From a013f42e3688d4cd325db8cae54bcdfea4a4e4e9 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Thu, 25 Mar 2021 12:56:06 +0000 Subject: [PATCH] Enable ansible-lint - enable run of ansible-lint, with a temporary set of excludes - fixes two problems reported by ansible-linter Change-Id: Ibbe23db8fd5ac1008109f50f514df96686b0fa19 Bug: #1921409 --- .gitignore | 3 +++ common/deploy-steps-playbooks-common.yaml | 20 +++++++++++++++---- .../haproxy/haproxy-container-puppet.yaml | 1 - test-requirements.txt | 1 + tox.ini | 1 + .../tests/test_tht_ansible_syntax.yml | 3 +-- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index b83fa1e4c0..844a62e926 100644 --- a/.gitignore +++ b/.gitignore @@ -179,3 +179,6 @@ tripleo_heat_templates/tests/tripleo-ansible # Files created by releasenotes build releasenotes/build +.cache +tripleo_heat_templates/tests/ansible-pacemaker +tripleo_heat_templates/tests/tripleo-ansible diff --git a/common/deploy-steps-playbooks-common.yaml b/common/deploy-steps-playbooks-common.yaml index 373dc60ba5..a3e718c988 100644 --- a/common/deploy-steps-playbooks-common.yaml +++ b/common/deploy-steps-playbooks-common.yaml @@ -5,6 +5,18 @@ # So we don't break the MaxFailPercentage feature since these plays can't use # Ansible strategies. +- hosts: localhost + name: Check if required variables are defined + tasks: + - fail: + msg: deploy_source_host variable is not defined + when: deploy_source_host is not defined + - fail: + msg: deploy_target_host variable is not defined + when: deploy_target_host is not defined + # Keep in mind that you will still need to use defaults in order to be + # able to pass Ansible own syntax check for blocks like 'hosts'. + - hosts: all name: Clear cached facts # We don't want to gather facts, just clear them @@ -14,7 +26,7 @@ tags: - facts -- hosts: "{{ deploy_source_host }}:{{ deploy_target_host }}" +- hosts: "{{ deploy_source_host | default([]) }}:{{ deploy_target_host | default([]) }}" name: Gather facts strategy: tripleo_free gather_facts: true @@ -35,12 +47,12 @@ any_errors_fatal: false ignore_unreachable: true tasks: - - include_vars: global_vars.yaml + - include_vars: global_vars.yaml # noqa: missing-import no_log: true tags: - always -- hosts: "{{ deploy_target_host }}" +- hosts: "{{ deploy_target_host | default([]) }}" name: Render all_nodes data as group_vars for overcloud gather_facts: "{{ gather_facts | default(false) }}" # we don't skip errors or ignore unreachable on this one because it's @@ -57,7 +69,7 @@ - facts - always -- hosts: "{{ deploy_target_host }}" +- hosts: "{{ deploy_target_host | default([]) }}" name: Set all_nodes data as group_vars for overcloud gather_facts: "{{ gather_facts | default(false) }}" any_errors_fatal: false diff --git a/deployment/haproxy/haproxy-container-puppet.yaml b/deployment/haproxy/haproxy-container-puppet.yaml index 8d83a48ab7..52bf8522bb 100644 --- a/deployment/haproxy/haproxy-container-puppet.yaml +++ b/deployment/haproxy/haproxy-container-puppet.yaml @@ -324,7 +324,6 @@ outputs: shell: | puppet apply {{ (puppet_debug|bool) | ternary('--debug --verbose', '') }} --detailed-exitcodes --summarize --color=false \ --modulepath '{{ puppet_modulepath }}' --tags '{{ puppet_tags }}' -e '{{ puppet_execute }}' - register: puppet_host_outputs changed_when: puppet_host_outputs.rc == 2 failed_when: false vars: diff --git a/test-requirements.txt b/test-requirements.txt index 36bb9c41fb..90fd4a9942 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -14,3 +14,4 @@ testtools>=2.2.0 # MIT oslotest>=3.2.0 # Apache-2.0 yaql>=1.1.3 # Apache 2.0 License ansible-runner>=1.4.2 # Apache +ansible-lint[core,yamllint]>=5.0.5 # MIT/GPL diff --git a/tox.ini b/tox.ini index e2daa4e168..837303998f 100644 --- a/tox.ini +++ b/tox.ini @@ -28,6 +28,7 @@ commands = bash -c ./tools/roles-data-validation.sh bash -c ./tools/check-up-to-date.sh flake8 + ansible-lint -v [flake8] # E125 is deliberately excluded. See diff --git a/tripleo_heat_templates/tests/test_tht_ansible_syntax.yml b/tripleo_heat_templates/tests/test_tht_ansible_syntax.yml index 96b349fecf..972c32d0d6 100644 --- a/tripleo_heat_templates/tests/test_tht_ansible_syntax.yml +++ b/tripleo_heat_templates/tests/test_tht_ansible_syntax.yml @@ -15,9 +15,8 @@ # under the License. -- name: Run check +- name: Render Ansible tasks for roles templates hosts: localhost - name: Render Ansible tasks for roles templates vars: # This variable is set to 9999, so we will not execute actually # any task. Still, the Ansible interpreter will check for syntax