From 9f1906cd74c2a5555d3924dc2d5e80f8c8484775 Mon Sep 17 00:00:00 2001 From: Michele Costa Date: Mon, 25 Mar 2024 10:17:42 +0000 Subject: [PATCH] Fix linting issues --- deploy_cluster.yml | 9 ++-- deploy_day2_workers.yml | 21 +++++--- deploy_prerequisites.yml | 27 ++++++---- playbooks/deploy_registry.yml | 6 +-- playbooks/populate_registry.yml | 8 ++- roles/display_deployment_plan/tasks/main.yml | 6 +-- roles/validate_inventory/tasks/ai.yml | 1 - roles/validate_inventory/tasks/day2.yml | 2 +- roles/validate_inventory/tasks/dns.yml | 6 +-- roles/validate_inventory/tasks/main.yml | 52 ++++++++++++------- roles/validate_inventory/tasks/network.yml | 12 ++--- roles/validate_inventory/tasks/ntp.yml | 2 +- roles/validate_inventory/tasks/partitions.yml | 4 +- roles/validate_inventory/tasks/prereqs.yml | 6 ++- roles/validate_inventory/tasks/proxy.yml | 4 +- .../tasks/required_vars.yml | 10 ++-- roles/validate_inventory/tasks/secrets.yml | 4 +- .../validate_inventory/tasks/validate_pxe.yml | 14 ++--- roles/validate_inventory/tasks/vendor.yml | 2 +- roles/validate_inventory/tasks/vms.yml | 16 +++--- site.yml | 18 ++++--- tests/run_tests.yml | 3 +- .../roles/run_suite/tasks/main.yml | 14 ++--- .../roles/run_suite/tasks/run_test.yml | 17 +++--- tests/validate_inventory/tests.yml | 4 +- 25 files changed, 157 insertions(+), 111 deletions(-) diff --git a/deploy_cluster.yml b/deploy_cluster.yml index 7d140666..d82cc48f 100644 --- a/deploy_cluster.yml +++ b/deploy_cluster.yml @@ -1,8 +1,11 @@ --- -- import_playbook: playbooks/validate_inventory.yml +- name: Validate Inventory + ansible.builtin.import_playbook: playbooks/validate_inventory.yml -- import_playbook: playbooks/deploy_cluster_agent_based_installer.yml +- name: Deploy cluster using agent based installer + ansible.builtin.import_playbook: playbooks/deploy_cluster_agent_based_installer.yml when: (use_agent_based_installer | default(true)) | bool -- import_playbook: playbooks/deploy_cluster_assisted_installer.yml +- name: Deploy cluster using agent based installer + ansible.builtin.import_playbook: playbooks/deploy_cluster_assisted_installer.yml when: not ((use_agent_based_installer | default(true)) | bool) diff --git a/deploy_day2_workers.yml b/deploy_day2_workers.yml index c68e7849..38d42ee3 100644 --- a/deploy_day2_workers.yml +++ b/deploy_day2_workers.yml @@ -1,7 +1,9 @@ --- -- import_playbook: playbooks/validate_inventory.yml +- name: Validate inventory + ansible.builtin.import_playbook: playbooks/validate_inventory.yml -- import_playbook: playbooks/create_vms.yml +- name: Create VMs + import_playbook: playbooks/create_vms.yml when: groups['day2_workers'] | default([]) | length > 0 vars: nodes_to_process: "{{ groups['day2_workers'] | default([]) }}" @@ -11,21 +13,26 @@ # are trying to join DELETE_VM_BRIDGE: false -- import_playbook: playbooks/create_day2_cluster.yml +- name: Create Day 2 cluster instance + ansible.builtin.import_playbook: playbooks/create_day2_cluster.yml -- import_playbook: playbooks/generate_discovery_iso.yml +- name: Generate Day 2 discovery iso + ansible.builtin.import_playbook: playbooks/generate_discovery_iso.yml when: groups['day2_workers'] | default([]) | length > 0 vars: discovery_iso_name: "{{ day2_discovery_iso_name }}" iso_cluster_id: "{{ add_host_cluster_id }}" -- import_playbook: playbooks/boot_iso.yml +- name: Boot Day 2 ISO + import_playbook: playbooks/boot_iso.yml when: groups['day2_workers'] | default([]) | length > 0 vars: discovery_iso_name: "{{ day2_discovery_iso_name }}" boot_iso_url: "{{ discovery_iso_server }}/{{ day2_discovery_iso_name }}" boot_iso_hosts: day2_workers -- import_playbook: playbooks/add_day2_nodes.yml +- name: Add day 2 nodes to cluster + ansible.builtin.import_playbook: playbooks/add_day2_nodes.yml -- import_playbook: playbooks/approve_csrs.yml +- name: Approve node CSRs + ansible.builtin.import_playbook: playbooks/approve_csrs.yml diff --git a/deploy_prerequisites.yml b/deploy_prerequisites.yml index 55d27936..ad9d5129 100644 --- a/deploy_prerequisites.yml +++ b/deploy_prerequisites.yml @@ -1,26 +1,35 @@ --- -- import_playbook: prereq_facts_check.yml +- name: Prereq fact checks + ansible.builtin.import_playbook: prereq_facts_check.yml - name: Play to populate image_hashes for relevant images hosts: localhost roles: - redhatci.ocp.get_image_hash -- import_playbook: playbooks/deploy_ntp.yml +- name: Deploy NTP + ansible.builtin.import_playbook: playbooks/deploy_ntp.yml -- import_playbook: playbooks/deploy_http_store.yml +- name: Deploy HTTP Store + ansible.builtin.import_playbook: playbooks/deploy_http_store.yml -- import_playbook: playbooks/create_vms.yml +- name: Create VMs + ansible.builtin.import_playbook: playbooks/create_vms.yml vars: nodes_to_process: "{{ groups['masters'] + groups['workers'] | default([]) }}" -- import_playbook: playbooks/deploy_tftp.yml +- name: Deploy TFTP + ansible.builtin.import_playbook: playbooks/deploy_tftp.yml -- import_playbook: playbooks/deploy_dns.yml +- name: Deploy DNS + ansible.builtin.import_playbook: playbooks/deploy_dns.yml -- import_playbook: playbooks/deploy_registry.yml +- name: Deploy Registry + ansible.builtin.import_playbook: playbooks/deploy_registry.yml -- import_playbook: playbooks/deploy_assisted_installer_onprem.yml +- name: Deploy assisted installer on prem + ansible.builtin.import_playbook: playbooks/deploy_assisted_installer_onprem.yml when: not ((use_agent_based_installer | default(true)) | bool) -- import_playbook: playbooks/deploy_sushy_tools.yml +- name: Deploy Sushy Tools + ansible.builtin.import_playbook: playbooks/deploy_sushy_tools.yml diff --git a/playbooks/deploy_registry.yml b/playbooks/deploy_registry.yml index f564ca2f..96f88ce5 100644 --- a/playbooks/deploy_registry.yml +++ b/playbooks/deploy_registry.yml @@ -13,16 +13,16 @@ - name: Setup facts ansible.builtin.setup: when: SETUP_REGISTRY_SERVICE | bool - - name: pre-compute need to get hashes + - name: Pre-compute need to get hashes ansible.builtin.set_fact: - run_get_hash: "{{ image_hashes | default({}) | length == 0 }}" + run_get_hash: "{{ image_hashes | default({}) | length == 0 }}" roles: - role: redhatci.ocp.get_image_hash when: run_get_hash - name: Play to install and setup mirror registry hosts: registry_host - gather_facts: False + gather_facts: false vars: downloads_path: /tmp/wip config_file_path: /tmp/wip/config diff --git a/playbooks/populate_registry.yml b/playbooks/populate_registry.yml index 40b1758f..70ffe61e 100644 --- a/playbooks/populate_registry.yml +++ b/playbooks/populate_registry.yml @@ -4,7 +4,7 @@ - name: Play to populate image_hashes for relevant images hosts: localhost - gather_facts: (setup_registry_service | default(true)) | bool + gather_facts: false vars: destination_hosts: - registry_host @@ -19,10 +19,14 @@ - name: Play populate mirror registry hosts: registry_host - gather_facts: "{{ (setup_registry_service | default(true)) | bool }}" + gather_facts: false vars: config_file_path: /tmp/wip/config SETUP_REGISTRY_SERVICE: "{{ setup_registry_service | default(true)}}" + pre_tasks: + - name: Setup facts + ansible.builtin.setup: + when: SETUP_REGISTRY_SERVICE | bool roles: - role: redhatci.ocp.populate_mirror_registry when: SETUP_REGISTRY_SERVICE | bool diff --git a/roles/display_deployment_plan/tasks/main.yml b/roles/display_deployment_plan/tasks/main.yml index 682166d4..a6f49a4c 100644 --- a/roles/display_deployment_plan/tasks/main.yml +++ b/roles/display_deployment_plan/tasks/main.yml @@ -1,6 +1,6 @@ --- - name: Get all PXE Nodes - set_fact: + ansible.builtin.set_fact: pxe_node_names: "{{ pxe_node_names + [item] }}" when: hostvars[item]['vendor'] | lower == 'pxe' loop: "{{ groups['nodes'] }}" @@ -9,7 +9,7 @@ when: not ((skip_interactive_prompts | default(false)) | bool) block: - name: Display inventory details and ask for user confirmation - pause: + ansible.builtin.pause: prompt: "{{ lookup('template', 'plan.j2').strip('\n') }}" vars: # Every row consists of two columns. To ensure all items in the right column are aligned, @@ -65,7 +65,7 @@ register: display_deployment_plan__confirmation - name: Assert the deployment plan is confirmed - assert: + ansible.builtin.assert: that: - (display_deployment_plan__confirmation.user_input | lower | trim) in ['y', 'yes'] fail_msg: "The deployment plan must be confirmed by the user" diff --git a/roles/validate_inventory/tasks/ai.yml b/roles/validate_inventory/tasks/ai.yml index 7a971dbb..22cdf32f 100644 --- a/roles/validate_inventory/tasks/ai.yml +++ b/roles/validate_inventory/tasks/ai.yml @@ -93,7 +93,6 @@ ver_query: "[?version=='{{ openshift_full_version }}']" block: - name: Assert os_images exists - vars: ansible.builtin.assert: that: - os_images is defined diff --git a/roles/validate_inventory/tasks/day2.yml b/roles/validate_inventory/tasks/day2.yml index db9960c6..cde8e3eb 100644 --- a/roles/validate_inventory/tasks/day2.yml +++ b/roles/validate_inventory/tasks/day2.yml @@ -1,5 +1,5 @@ - name: Check for day2_discovery_iso_name if required - assert: + ansible.builtin.assert: that: - day2_discovery_iso_name is defined when: (groups['day2_workers'] | default([])) | length > 0 diff --git a/roles/validate_inventory/tasks/dns.yml b/roles/validate_inventory/tasks/dns.yml index 1c91c17a..e367e19f 100644 --- a/roles/validate_inventory/tasks/dns.yml +++ b/roles/validate_inventory/tasks/dns.yml @@ -1,6 +1,6 @@ --- - name: Assert 'dhcp_range_first' and 'dhcp_range_last' are defined if needed - assert: + ansible.builtin.assert: that: - hostvars['dns_host'][item] is defined - hostvars['dns_host'][item] | ansible.utils.ipaddr('bool') == True @@ -10,8 +10,8 @@ - dhcp_range_first - dhcp_range_last -- name: if DNS DHCP setup is enabled, ntp_server MUST be an IP for DNS config - assert: +- name: If DNS DHCP setup is enabled, ntp_server MUST be an IP for DNS config + ansible.builtin.assert: that: - hostvars['dns_host']['ntp_server'] is defined - hostvars['dns_host']['ntp_server'] | ansible.utils.ipaddr('bool') == True diff --git a/roles/validate_inventory/tasks/main.yml b/roles/validate_inventory/tasks/main.yml index efe1b6b3..21edbf92 100644 --- a/roles/validate_inventory/tasks/main.yml +++ b/roles/validate_inventory/tasks/main.yml @@ -1,80 +1,95 @@ --- - name: Validate Inventory + when: not (inventory_validated | default(False) | bool) + delegate_to: "{{ validation_host | default('bastion') }}" block: - - include_tasks: + - name: Check required vars + ansible.builtin.include_tasks: file: required_vars.yml apply: tags: validate_required_vars tags: validate_required_vars - - include_tasks: + - name: Check cluster values + ansible.builtin.include_tasks: file: cluster.yml apply: tags: validate_cluster tags: validate_cluster - - include_tasks: + - name: Check vendor vars + ansible.builtin.include_tasks: file: vendor.yml apply: tags: validate_vendor tags: validate_vendor - - include_tasks: + - name: Check ntp vars + ansible.builtin.include_tasks: file: ntp.yml apply: tags: validate_ntp tags: validate_ntp - - include_tasks: + - name: Check VM vars + ansible.builtin.include_tasks: file: vms.yml apply: tags: validate_vms tags: validate_vms - - include_tasks: + - name: Check secrets + ansible.builtin.include_tasks: file: secrets.yml apply: tags: validate_secrets tags: validate_secrets - - include_tasks: + - name: Check prereqs + ansible.builtin.include_tasks: file: prereqs.yml apply: tags: validate_prereqs tags: validate_prereqs - - include_tasks: + - name: Check proxy vars + ansible.builtin.include_tasks: file: proxy.yml apply: tags: validate_proxy_config tags: validate_proxy_config - - include_tasks: + - name: Check network vars + ansible.builtin.include_tasks: file: network.yml apply: tags: validate_network tags: validate_network - - include_tasks: + - name: Check day2 vars + ansible.builtin.include_tasks: file: day2.yml apply: tags: validate_day2 tags: validate_day2 - - include_tasks: + - name: Check partitions vars + ansible.builtin.include_tasks: file: partitions.yml apply: tags: validate_partitions tags: validate_partitions - - include_tasks: + - name: Check pxe vars + ansible.builtin.include_tasks: file: validate_pxe.yml apply: tags: validate_pxe tags: validate_pxe when: (setup_pxe_service | default(false)) | bool - - include_tasks: + - name: Check installer feature gates + ansible.builtin.include_tasks: file: agent_based_installer_feature_gates.yml apply: tags: validate_agent_based_installer @@ -83,7 +98,8 @@ - not ((ignore_agent_based_installer_feature_gates | default(false)) | bool) tags: validate_agent_based_installer - - include_tasks: + - name: Check agent based installer requirements + ansible.builtin.include_tasks: file: agent_based_installer_requirements.yml apply: tags: validate_agent_based_installer @@ -91,12 +107,10 @@ - (use_agent_based_installer | default(true) | bool) tags: validate_agent_based_installer - when: not (inventory_validated | default(False) | bool) - delegate_to: "{{ validation_host | default('bastion') }}" - name: Record successful validation on all hosts - set_fact: - inventory_validated: True + ansible.builtin.set_fact: + inventory_validated: true delegate_to: "{{ item }}" - delegate_facts: True + delegate_facts: true loop: "{{ groups['all'] + ['localhost'] }}" diff --git a/roles/validate_inventory/tasks/network.yml b/roles/validate_inventory/tasks/network.yml index 6bace421..dd27c3a5 100644 --- a/roles/validate_inventory/tasks/network.yml +++ b/roles/validate_inventory/tasks/network.yml @@ -2,20 +2,20 @@ # Node `ansible_host`s are not pinged. They are not required to be running at this stage. # KVM node BMCs are not checked, the vm_host will be pinged later. - name: Ensure baremetal node BMCs are reachable - shell: # noqa 305 + ansible.builtin.shell: # noqa command-instead-of-shell cmd: "ping -c 1 -W 2 {{ hostvars[item]['bmc_ip'] | default(hostvars[item]['bmc_address']) }}" - changed_when: False + changed_when: false when: hostvars[item]['vendor'] | lower != 'kvm' loop: "{{ groups['nodes'] }}" - name: Ensure service hosts are reachable - shell: # noqa 305 + ansible.builtin.shell: # noqa command-instead-of-shell cmd: "ping -c 1 -W 2 {{ hostvars[item]['ansible_host'] }}" - changed_when: False + changed_when: false loop: "{{ groups['services'] }}" - name: Ensure NTP server is available if not being set up - shell: # noqa 305 + ansible.builtin.shell: # noqa command-instead-of-shell cmd: "ping -c 1 -W 2 {{ ntp_server }}" - changed_when: False + changed_when: false when: (setup_ntp_service | default(True)) != True diff --git a/roles/validate_inventory/tasks/ntp.yml b/roles/validate_inventory/tasks/ntp.yml index e1e84e6c..b22f7607 100644 --- a/roles/validate_inventory/tasks/ntp.yml +++ b/roles/validate_inventory/tasks/ntp.yml @@ -1,5 +1,5 @@ - name: Check ntp_server is valid - assert: + ansible.builtin.assert: that: - hostvars['ntp_host']['ntp_server'] is defined - hostvars['ntp_host']['ntp_server'] | ansible.utils.ipaddr('bool') == True diff --git a/roles/validate_inventory/tasks/partitions.yml b/roles/validate_inventory/tasks/partitions.yml index ad08be63..1de02c54 100644 --- a/roles/validate_inventory/tasks/partitions.yml +++ b/roles/validate_inventory/tasks/partitions.yml @@ -1,7 +1,7 @@ - name: Assert that partitions can be create on supported Openshift version - assert: + ansible.builtin.assert: that: - - openshift_full_version is version('4.8', '>=') + - openshift_full_version is version('4.8', '>=') fail_msg: "openshift_full_version must be >= 4.8." when: hostvars[item]['disks'] is defined loop: "{{ groups['nodes'] | default([]) }}" diff --git a/roles/validate_inventory/tasks/prereqs.yml b/roles/validate_inventory/tasks/prereqs.yml index 4f9c1b60..95063f17 100644 --- a/roles/validate_inventory/tasks/prereqs.yml +++ b/roles/validate_inventory/tasks/prereqs.yml @@ -1,4 +1,6 @@ --- -- import_tasks: ai.yml +- name: Check installer vars + ansible.builtin.import_tasks: ai.yml -- import_tasks: dns.yml +- name: Check DNS vars + ansible.builtin.import_tasks: dns.yml diff --git a/roles/validate_inventory/tasks/proxy.yml b/roles/validate_inventory/tasks/proxy.yml index 87bc0eec..08a9e9a3 100644 --- a/roles/validate_inventory/tasks/proxy.yml +++ b/roles/validate_inventory/tasks/proxy.yml @@ -1,5 +1,5 @@ - name: Check for repeated values in proxy config - assert: + ansible.builtin.assert: that: - - "{{ (no_proxy.split(',') | unique | list | length) == (no_proxy.split(',') | list | length) }}" + - "{{ (no_proxy.split(',') | unique | list | length) == (no_proxy.split(',') | list | length) }}" when: no_proxy is defined and no_proxy != "" diff --git a/roles/validate_inventory/tasks/required_vars.yml b/roles/validate_inventory/tasks/required_vars.yml index c469da8d..ee6e0a9d 100644 --- a/roles/validate_inventory/tasks/required_vars.yml +++ b/roles/validate_inventory/tasks/required_vars.yml @@ -1,14 +1,14 @@ - name: Check repo_root_path is defined - assert: + ansible.builtin.assert: that: - repo_root_path is defined fail_msg: repo_root_path is required for all playbooks to function correctly - changed_when: False + changed_when: false - name: Check kubeadmin_vault_password_file_path is defined and the file exists - assert: + ansible.builtin.assert: that: - kubeadmin_vault_password_file_path is file fail_msg: "Kubeadmin Vault password must be stored in the location specified by the required variable 'kubeadmin_vault_password_file_path'." - changed_when: False - when: kubeadmin_vault_password_file_path is defined + changed_when: false + when: kubeadmin_vault_password_file_path is defined diff --git a/roles/validate_inventory/tasks/secrets.yml b/roles/validate_inventory/tasks/secrets.yml index 514f1600..91990413 100644 --- a/roles/validate_inventory/tasks/secrets.yml +++ b/roles/validate_inventory/tasks/secrets.yml @@ -1,6 +1,6 @@ --- - name: Assert that all credentials for the disconnected registry are set - assert: + ansible.builtin.assert: that: - hostvars['registry_host'][secret_var_name] is defined - hostvars['registry_host'][secret_var_name] is string @@ -20,7 +20,7 @@ when: "use_local_mirror_registry | default(setup_registry_service | default(true))" - name: Assert that all nodes have BMC credentials set - assert: + ansible.builtin.assert: that: - hostvars[item.0][item.1] is defined - hostvars[item.0][item.1] is string diff --git a/roles/validate_inventory/tasks/validate_pxe.yml b/roles/validate_inventory/tasks/validate_pxe.yml index b5bd9b84..b63182eb 100644 --- a/roles/validate_inventory/tasks/validate_pxe.yml +++ b/roles/validate_inventory/tasks/validate_pxe.yml @@ -1,6 +1,6 @@ --- - name: Assert 'dns host' and 'tftp host' is have IPs and that is the same - assert: + ansible.builtin.assert: that: - hostvars['dns_host']['ansible_host'] is defined - hostvars['tftp_host']['ansible_host'] is defined @@ -15,11 +15,11 @@ ansible.builtin.shell: cmd: "ipmitool -V" register: ipmitool_check - ignore_errors: True - changed_when: False + ignore_errors: true + changed_when: false - name: Record failures - fail: + ansible.builtin.fail: msg: "ipmitool must be installed for pxe installation" when: ipmitool_check.rc != 0 @@ -27,10 +27,10 @@ ansible.builtin.shell: cmd: "pip3 show pyghmi" register: pyghmi_check - ignore_errors: True - changed_when: False + ignore_errors: true + changed_when: false - name: Record failures - fail: + ansible.builtin.fail: msg: "pyghmi must be installed for pxe installation" when: pyghmi_check.rc != 0 diff --git a/roles/validate_inventory/tasks/vendor.yml b/roles/validate_inventory/tasks/vendor.yml index d3f26f6e..589e52ad 100644 --- a/roles/validate_inventory/tasks/vendor.yml +++ b/roles/validate_inventory/tasks/vendor.yml @@ -1,4 +1,4 @@ - +--- - name: Assert that all values of 'vendor' are supported ansible.builtin.assert: that: diff --git a/roles/validate_inventory/tasks/vms.yml b/roles/validate_inventory/tasks/vms.yml index 64200885..3fe670a7 100644 --- a/roles/validate_inventory/tasks/vms.yml +++ b/roles/validate_inventory/tasks/vms.yml @@ -1,13 +1,13 @@ - name: Get all KVM Nodes vars: kvm_node_names: [] - set_fact: + ansible.builtin.set_fact: kvm_node_names: "{{ kvm_node_names + [item] }}" when: hostvars[item]['vendor'] | lower == 'kvm' loop: "{{ groups['nodes'] }}" - name: Check there is no vm_host in services - assert: + ansible.builtin.assert: that: - ('vm_host' not in groups['services']) fail_msg: > @@ -17,7 +17,7 @@ to the host of the vm. - name: Check that a host is defined in the 'vm_hosts' group if needed - assert: + ansible.builtin.assert: that: - groups['vm_hosts'] is defined - groups['vm_hosts'] | length > 0 @@ -25,7 +25,7 @@ when: (kvm_node_names is defined) and (kvm_node_names | length > 0) - name: Check that each node will be on a valid host - assert: + ansible.builtin.assert: that: - hostvars[item]['vm_host'] in groups['vm_hosts'] quiet: true @@ -38,7 +38,7 @@ - name: Get KVM BMC username password combinations vars: kvm_user_password_combinations: {} # Structure will be {'{{vm_host}}.{{bmc_user}}': [{{bmc_password}}, ...]} - set_fact: + ansible.builtin.set_fact: kvm_user_password_combinations: "{{ kvm_user_password_combinations | combine({ (hostvars[item]['vm_host'] + '.' + hostvars[item]['bmc_user']): ( @@ -54,7 +54,7 @@ no_log: true - name: Check there are not mutliple bmc passwords for the same bmc user and vm host. - assert: + ansible.builtin.assert: that: - (item.value | length) == 1 fail_msg: | @@ -69,14 +69,14 @@ kvm_node_uuids: [] block: - name: Get node UUIDs - set_fact: + ansible.builtin.set_fact: kvm_node_uuids: "{{ kvm_node_uuids + [hostvars[item]['uuid']] }}" when: "'uuid' in hostvars[item]" loop: "{{ kvm_node_names }}" no_log: true - name: Check values are unique - assert: + ansible.builtin.assert: that: - (kvm_node_uuids | length) == (kvm_node_uuids | unique | length) fail_msg: "KVM node UUIDs must be unique otherwise they won't build or will collide during discovery" diff --git a/site.yml b/site.yml index 9e3dc679..a94e139a 100644 --- a/site.yml +++ b/site.yml @@ -1,13 +1,19 @@ --- -- import_playbook: playbooks/validate_inventory.yml +- name: Validate Inventory + ansible.builtin.import_playbook: playbooks/validate_inventory.yml -- import_playbook: playbooks/display_deployment_plan.yml +- name: Display deployment plan + ansible.builtin.import_playbook: playbooks/display_deployment_plan.yml -- import_playbook: deploy_prerequisites.yml +- name: Deploy prerequisites + ansible.builtin.import_playbook: deploy_prerequisites.yml -- import_playbook: deploy_cluster.yml +- name: Deploy cluster + ansible.builtin.import_playbook: deploy_cluster.yml -- import_playbook: post_install.yml +- name: Post install + ansible.builtin.import_playbook: post_install.yml -- import_playbook: deploy_day2_workers.yml +- name: Deploy day2 workers + ansible.builtin.import_playbook: deploy_day2_workers.yml when: not ((use_agent_based_installer | default(true)) | bool) diff --git a/tests/run_tests.yml b/tests/run_tests.yml index a013ab16..4be64c43 100644 --- a/tests/run_tests.yml +++ b/tests/run_tests.yml @@ -1,2 +1,3 @@ --- -- import_playbook: validate_inventory/tests.yml +- name: Test validate inventory + ansible.builtin.import_playbook: validate_inventory/tests.yml diff --git a/tests/validate_inventory/roles/run_suite/tasks/main.yml b/tests/validate_inventory/roles/run_suite/tasks/main.yml index a3491e5e..ef002192 100644 --- a/tests/validate_inventory/roles/run_suite/tasks/main.yml +++ b/tests/validate_inventory/roles/run_suite/tasks/main.yml @@ -1,11 +1,11 @@ --- - name: "Load suite {{ test_suite_file }}" - include_vars: + ansible.builtin.include_vars: file: "suites/{{ test_suite_file }}" name: suite_data - name: Create temporary directory for rendered templates - tempfile: + ansible.builtin.tempfile: state: directory register: temp_dir @@ -13,21 +13,21 @@ block: - name: "Render test inventories for {{ test_suite_file }}" - template: + ansible.builtin.template: src: "{{ item.from_template | default(suite_data.template_file) }}" dest: "{{ temp_dir.path }}/{{ item.test_name }}.yml" - mode: 0644 + mode: "0644" trim_blocks: true lstrip_blocks: true loop: "{{ suite_data.tests }}" - name: "Run Inventory Validation tests from {{ test_suite_file }}" - include_tasks: run_test.yml + ansible.builtin.include_tasks: run_test.yml loop: "{{ suite_data.tests }}" rescue: - name: Persist the tested inventory files on failure - copy: + ansible.builtin.copy: src: "{{ temp_dir.path }}" dest: "{{ playbook_dir }}/failed/" mode: preserve @@ -36,7 +36,7 @@ always: - name: Remove the temporary directory - file: + ansible.builtin.file: path: "{{ temp_dir.path }}" state: absent when: temp_dir.path is defined diff --git a/tests/validate_inventory/roles/run_suite/tasks/run_test.yml b/tests/validate_inventory/roles/run_suite/tasks/run_test.yml index 77f31480..5a8cdd33 100644 --- a/tests/validate_inventory/roles/run_suite/tasks/run_test.yml +++ b/tests/validate_inventory/roles/run_suite/tasks/run_test.yml @@ -1,16 +1,17 @@ --- -- block: - - name: "Run Testcase {{ item.test_name }}" - shell: - chdir: "{{ playbook_dir }}/../.." - cmd: "ansible-playbook playbooks/validate_inventory.yml -i {{ temp_dir.path }}/{{ item.test_name }}.yml -t {{ suite_data.tags }}" +- name: Run Test case + block: + - name: "Run Testcase {{ item.test_name }}" + ansible.builtin.shell: + chdir: "{{ playbook_dir }}/../.." + cmd: "ansible-playbook playbooks/validate_inventory.yml -i {{ temp_dir.path }}/{{ item.test_name }}.yml -t {{ suite_data.tags }}" environment: "{{ suite_data.env | default({}) }}" register: res failed_when: res.rc != item.expected changed_when: false # Keep simple success/failure state for tests - + rescue: - - name: "Record failure of testcase {{ item.test_name }}" - set_fact: + - name: "Record failure of testcase {{ item.test_name }}" + ansible.builtin.set_fact: test_failures: "{{ test_failures | default([]) + [item.test_name] }}" failed_when: true # Keep non-zero exit code diff --git a/tests/validate_inventory/tests.yml b/tests/validate_inventory/tests.yml index af52694f..e15131e6 100644 --- a/tests/validate_inventory/tests.yml +++ b/tests/validate_inventory/tests.yml @@ -14,7 +14,7 @@ - proxy.yml tasks: - name: Run Inventory Validation test suites - include_role: + ansible.builtin.include_role: name: run_suite ignore_errors: true loop: "{{ test_suites | list }}" @@ -22,7 +22,7 @@ loop_var: test_suite_file - name: Record failures - fail: + ansible.builtin.fail: msg: "Test failed!: {{ item }}" when: (test_failures | default([])) | length > 0 loop: "{{ test_failures }}"