Lint all the generated playbook after standalone deployment.

This task default to false, and should be changed in the featureset.

It ansible-lint all generated playbook and enable detection of error
in any playbook, even those that are not used in the
deployment (upgrade, update, ffu tasks for instances)

The current version only fails on syntax error (wrong ansible module
name mainly) as currently the generated playbooks misses name in a lot
of tasks.

When this is fixed we can enable error of any lint error.

Change-Id: Ibe0bd47cc88063f71c405b408342426888fbf88d
This commit is contained in:
Sofer Athlan-Guyot 2018-09-13 20:12:47 +02:00 committed by Alex Schultz
parent 1cf80c39ac
commit 5f2da9cf2d
3 changed files with 37 additions and 1 deletions

View File

@ -24,6 +24,7 @@ Role Variables
- standalone_deploy_script: <'standalone.sh.j2'> -- The script name use to deploy the standalone server
- standalone_deploy_log: <'standalone_deploy.log'> -- The log of the deployment
- standalone_ansible_lint_log: <'standalone_ansible_lint.log'> -- The ansible lint output
- standalone_role: <'Standalone.yaml'> -- The TripleO Heat Template role definition of the deployment
@ -31,6 +32,8 @@ Role Variables
- standalone_selinux_mode: <'permissive'> -- The selinux mode to use.
- standalone_ansible_lint: <'false'> -- Perform ansible lint on the generated ansible playbooks
Dependencies
------------

View File

@ -13,10 +13,14 @@ standalone_container_prep_log: standalone_container_prep.log
# deploy script
standalone_deploy_script: standalone.sh.j2
standalone_deploy_log: standalone_deploy.log
standalone_ansible_lint_log: standalone_ansible_lint.log
# deployment role
standalone_role: Standalone.yaml
standalone_libvirt_type: kvm
# Extra action on the deployment
standalone_ansible_lint: false
standalone_selinux_mode: permissive
standalone_libvirt_type: kvm

View File

@ -30,3 +30,32 @@
set -o pipefail &&
{{ working_dir }}/standalone.sh 2>&1 {{ timestamper_cmd }} > {{ working_dir }}/{{ standalone_deploy_log }}
- when: standalone_ansible_lint|default(false)|bool
vars:
quickstart_venv: "{{ lookup('env','OPT_WORKDIR') }}"
block:
- name: Install ansible-lint
pip:
name: ansible-lint
state: latest
virtualenv: "{{ quickstart_venv }}"
- name: List playbooks
shell: "find $(ls -rtd {{ working_dir }}/undercloud-ansible-* | tail -1)/ -name '*playbook*.yaml'"
register: playbooks
# We ignore (for now) the lint (rc==2), only catch syntax error
# (rc==1).
- name: Lint playbooks
shell: >
source {{ quickstart_venv }}/bin/activate;
exec 1>>{{ working_dir }}/{{standalone_ansible_lint_log}};
exec 2>&1;
echo LINTING {{item}};
ansible-lint -v {{item}};
rc=$?;
echo DONE rc=$rc;
exit $rc
register: lint_result
with_items: "{{ playbooks.stdout_lines }}"
failed_when: lint_result.rc == 1