From a472345db1f58b4d0b6a4a8d3c5c8be85b614c33 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Mon, 15 Oct 2018 13:51:58 +0100 Subject: [PATCH] Repair ansible when calls with jinja2 - adopts official syntax for 'when:' commands - assures we use current linter which spots when errors - reverts temporary linter rule disablement - use parsable output (pep8 like) for ansible-lint Change-Id: I6eb5719841c2f264e1efed4bf38726f71c840e36 Closes-Bug: #1797838 --- ci-scripts/ansible-lint.sh | 7 +++---- playbooks/to-build-or-not-to-build.yml | 2 +- roles/build-images/tasks/main.yml | 2 +- roles/gate-quickstart/tasks/checkout.yml | 4 ++-- roles/gate-quickstart/tasks/main.yml | 4 +++- roles/overcloud-scale/tasks/delete-original-node.yml | 5 +++-- roles/overcloud-scale/tasks/scale-nodes.yml | 8 +++++--- test-requirements.txt | 2 +- 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/ci-scripts/ansible-lint.sh b/ci-scripts/ansible-lint.sh index 06ee75d2c..eccf581d3 100755 --- a/ci-scripts/ansible-lint.sh +++ b/ci-scripts/ansible-lint.sh @@ -10,13 +10,12 @@ # ANSIBLE0013: Use Shell only when shell functionality is required # ANSIBLE0016: Tasks that run when changed should likely be handlers # this requires refactoring roles, skipping for now -# ANSIBLE0019: This is task ID 102 with '"when" lines should not include Jinja2 variables' -SKIPLIST="ANSIBLE0006,ANSIBLE0007,ANSIBLE0010,ANSIBLE0012,ANSIBLE0013,ANSIBLE0016,ANSIBLE0019" +SKIPLIST="ANSIBLE0006,ANSIBLE0007,ANSIBLE0010,ANSIBLE0012,ANSIBLE0013,ANSIBLE0016" # lint the playbooks separately to avoid linting the roles multiple times pushd playbooks for playbook in `find . -type f -regex '.*\.y[a]?ml'`; do - ansible-lint -vvv -x $SKIPLIST -R -r ../ci-scripts/ansible_rules $playbook || lint_error=1 + ansible-lint -vvv -p -x $SKIPLIST -R -r ../ci-scripts/ansible_rules $playbook || lint_error=1 done popd @@ -24,7 +23,7 @@ popd # Due to https://github.com/willthames/ansible-lint/issues/210, the roles # directories need to contain a trailing slash at the end of the path. for rolesdir in `find ./roles -maxdepth 1 -type d`; do - ansible-lint -vvv -x $SKIPLIST -R -r ./ci-scripts/ansible_rules $rolesdir/ || lint_error=1 + ansible-lint -vvv -p -x $SKIPLIST -R -r ./ci-scripts/ansible_rules $rolesdir/ || lint_error=1 done ## exit with 1 if we had a least an error or warning. diff --git a/playbooks/to-build-or-not-to-build.yml b/playbooks/to-build-or-not-to-build.yml index e38152f86..1001c7fa4 100644 --- a/playbooks/to-build-or-not-to-build.yml +++ b/playbooks/to-build-or-not-to-build.yml @@ -48,4 +48,4 @@ set_fact: to_build: true cacheable: true - when: "{{ lookup('env', 'PERIODIC')|default('0')|int == 1 }}" + when: lookup('env', 'PERIODIC')|default('0')|int == 1 diff --git a/roles/build-images/tasks/main.yml b/roles/build-images/tasks/main.yml index 282d68261..dcf736775 100644 --- a/roles/build-images/tasks/main.yml +++ b/roles/build-images/tasks/main.yml @@ -4,7 +4,7 @@ path: "{{ images_working_dir }}" state: absent become: true - when: "{{ images_destroy_working_dir }}|bool" + when: images_destroy_working_dir | bool - name: Create the working directory file: diff --git a/roles/gate-quickstart/tasks/checkout.yml b/roles/gate-quickstart/tasks/checkout.yml index 8207082c3..3b68d3af1 100644 --- a/roles/gate-quickstart/tasks/checkout.yml +++ b/roles/gate-quickstart/tasks/checkout.yml @@ -15,7 +15,7 @@ path: '{{ lookup("env", "WORKSPACE") }}/{{ gated_project_name }}' state: absent # do not remove the repo if it was cloned by the jenkins job - when: gated_change.project != "{{ lookup('env', 'GERRIT_PROJECT') }}" + when: gated_change.project != lookup('env', 'GERRIT_PROJECT') - name: Check out the gated change git: @@ -24,7 +24,7 @@ refspec: '{{ gated_change.refspec }}' version: 'FETCH_HEAD' # do not check out the gated change if it was already cloned by the jenkins job - when: gated_change.project != "{{ lookup('env', 'GERRIT_PROJECT') }}" + when: gated_change.project != lookup('env', 'GERRIT_PROJECT') # do this only for the roles - when: gated_change.project != "openstack/tripleo-quickstart" diff --git a/roles/gate-quickstart/tasks/main.yml b/roles/gate-quickstart/tasks/main.yml index 1e2070bc2..d8fafb80c 100644 --- a/roles/gate-quickstart/tasks/main.yml +++ b/roles/gate-quickstart/tasks/main.yml @@ -7,7 +7,9 @@ change_id: "{{ lookup('env', 'GERRIT_CHANGE_ID') }}" branch: "{{ lookup('env', 'GERRIT_BRANCH') }}" patchset_rev: "{{ lookup('env', 'GERRIT_PATCHSET_REVISION') }}" - when: artg_change_list is not defined and "{{ lookup('env', 'GERRIT_HOST') }}" != "" + when: + - artg_change_list is not defined + - lookup('env', 'GERRIT_HOST') != "" - name: Check out the specific changes include: checkout.yml gated_change={{ item }} diff --git a/roles/overcloud-scale/tasks/delete-original-node.yml b/roles/overcloud-scale/tasks/delete-original-node.yml index 28f1debe0..f22d11ce3 100644 --- a/roles/overcloud-scale/tasks/delete-original-node.yml +++ b/roles/overcloud-scale/tasks/delete-original-node.yml @@ -61,5 +61,6 @@ delegate_to: localhost - name: Check that post delete node count is correct - fail: msg="Overcloud nova list does not show expected number of {{ node_to_scale }} services" - when: post_scale_node_count.stdout|int != {{ initial_scale_value | int }} + fail: + msg: "Overcloud nova list does not show expected number of {{ node_to_scale }} services" + when: post_scale_node_count.stdout|int != (initial_scale_value | int) diff --git a/roles/overcloud-scale/tasks/scale-nodes.yml b/roles/overcloud-scale/tasks/scale-nodes.yml index a957fa5f0..e471a41b5 100644 --- a/roles/overcloud-scale/tasks/scale-nodes.yml +++ b/roles/overcloud-scale/tasks/scale-nodes.yml @@ -24,7 +24,8 @@ register: post_scale_nova_list - name: Display post-scale nova list - debug: msg={{ post_scale_nova_list.stdout_lines }} + debug: + msg: "{{ post_scale_nova_list.stdout_lines }}" when: post_scale_nova_list is defined # Verify the scale @@ -35,5 +36,6 @@ register: post_scale_node_count - name: Check that post scale node count is correct - fail: msg="Overcloud nova list does not show expected number of {{ node_to_scale }} services" - when: post_scale_node_count.stdout|int != {{ final_scale_value|int }} + fail: + msg: "Overcloud nova list does not show expected number of {{ node_to_scale }} services" + when: post_scale_node_count.stdout|int != (final_scale_value|int) diff --git a/test-requirements.txt b/test-requirements.txt index f19a4f557..698abc9fb 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,7 +2,7 @@ openstackdocstheme>=1.11.0 # Apache-2.0 hacking<0.11,>=0.10 bashate>=0.2 # Apache-2.0 -ansible-lint +ansible-lint>=3.5.0 sphinx>=1.6.2 # BSD reno>=1.8.0 # Apache-2.0 jinja2