Add ansible-lint script

This patch adds tools/ansible-lint.sh script to lint validations playbooks.
Moreover, it adds `changed_when: False` to commands that should not change
things if nothing needs doing [ANSIBLE0012].

Change-Id: I4fb432bfbd2b73740c29011d08a09058b6c45348
Signed-off-by: Gael Chamoulaud <gchamoul@redhat.com>
This commit is contained in:
Gael Chamoulaud 2017-10-10 14:57:41 +02:00
parent e00ed6d609
commit 6406ef8bd8
13 changed files with 44 additions and 6 deletions

19
tools/ansible-lint.sh Normal file
View File

@ -0,0 +1,19 @@
#!/bin/bash
# ANSIBLE0006: Using command rather than module
# we have a few use cases where we need to use curl and rsync
# ANSIBLE0016: Tasks that run when changed should likely be handlers
# this requires refactoring roles, skipping for now
SKIPLIST="ANSIBLE0006,ANSIBLE0016"
pushd validations
for playbook in `find . -type f -regex '.*\.y[a]?ml'`; do
ansible-lint -vvv -x $SKIPLIST $playbook || lint_error=1
done
popd
# exit with 1 if we had a least an error or warning.
if [[ -n "$lint_error" ]]; then
exit 1;
fi

View File

@ -5,11 +5,12 @@ skipsdist = True
[testenv]
usedevelop = True
install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages} "ansible>=2"
install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages} "ansible>=2" "ansible-lint"
setenv =
VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/test-requirements.txt
commands = python setup.py test --slowest --testr-args='{posargs}'
whitelist_externals = bash
[testenv:releasenotes]
whitelist_externals = bash
@ -17,6 +18,7 @@ commands = bash -c tools/releasenotes_tox.sh
[testenv:pep8]
commands =
{[testenv:ansible-lint]commands}
flake8 {posargs}
python ./tools/validate-files.py .
@ -32,6 +34,11 @@ commands = python setup.py build_sphinx
[testenv:debug]
commands = oslo_debug_helper {posargs}
[testenv:ansible-lint]
basepython = python2
commands =
bash tools/ansible-lint.sh
[flake8]
# E123, E125 skipped as they are invalid PEP-8.

View File

@ -12,7 +12,8 @@
tasks:
- name: List the available drives
register: drive_list
shell: "ls /sys/class/block/"
command: "ls /sys/class/block/"
changed_when: False
- name: Detect whether the drive uses Advanced Format
advanced_format: drive={{ item }}
when: item|match("^sd.$")

View File

@ -9,11 +9,12 @@
- pre-deployment
tasks:
- name: Check if ceph-ansible is installed
shell: yum list installed ceph-ansible
command: yum list installed ceph-ansible
args:
warn: no
ignore_errors: true
register: ceph_ansible_installed
changed_when: False
- name: Warn about missing ceph-ansible
warn:
msg: If planning to use Ceph, it is necessary to install the ceph-ansible on the undercloud

View File

@ -15,6 +15,7 @@
shell: hiera -c /etc/puppet/hiera.yaml enabled_services | egrep -sq ceph_mon
ignore_errors: true
register: ceph_mon_enabled
changed_when: False
- name: Get ceph health
become: true
shell: ceph health | awk '{print $1}'

View File

@ -13,6 +13,7 @@
- name: Find repository URLs
shell: 'yum repolist -v | grep Repo-baseurl | sed "s/Repo-baseurl.*\(http[^ ]*\).*/\1/g"'
register: repository_urls
changed_when: False
- name: Check if there is at least one repository baseurl
fail:
msg: No repository found in yum repolist

View File

@ -10,8 +10,9 @@
- pre-deployment
tasks:
- name: Fetch available images
shell: openstack image list --format value --column Name
command: openstack image list --format value --column Name
register: shell_result
changed_when: False
- name: Check for required images
fail: msg="The image {{ item }} is missing."

View File

@ -14,3 +14,4 @@
- name: Run ntpstat
# ntpstat returns 0 if synchronised and non-zero otherwise:
command: ntpstat
changed_when: False

View File

@ -17,7 +17,8 @@
uri: url={{ overcloud_horizon_url }}
when: overcloud_horizon_url|default('')
- fail: msg="The `HorizonPublic` endpoint is not defined in the `EndpointMap` of the deployed stack. This means Horizon may not have been deployed correctly."
- name: Fail if the HorizonPublic endpoint is not defined
fail: msg="The `HorizonPublic` endpoint is not defined in the `EndpointMap` of the deployed stack. This means Horizon may not have been deployed correctly."
when: overcloud_horizon_url|default('') == ''
# Check that we can obtain an auth token from horizon
@ -36,7 +37,8 @@
register: auth_token
when: overcloud_keystone_url|default('')
- fail: msg="The `KeystoneURL` output is not available in the deployed stack."
- name: Fail if KeystoneURL output is not available
fail: msg="The `KeystoneURL` output is not available in the deployed stack."
when: overcloud_keystone_url|default('') == ''
# TODO(shadower): other endpoints

View File

@ -16,5 +16,6 @@
become: true
command: pcs status xml
register: pcs_status
changed_when: False
- name: Check pacemaker status
pacemaker: status="{{ pcs_status.stdout }}"

View File

@ -16,6 +16,7 @@
command: pgrep -f -c {{ item }}
ignore_errors: yes
register: "process_count"
changed_when: False
with_items:
- heat-engine
- mistral

View File

@ -14,6 +14,7 @@
become: true
with_items: "{{ undercloud_service_list }}"
register: "check_services"
changed_when: False
ignore_errors: true
- name: Fail if services were not running
fail: msg="One of the undercloud services was not active. Please check {{ item.item }} first and then confirm the status of undercloud services in general before attempting to update or upgrade the environment."

View File

@ -15,6 +15,7 @@
become: true
shell: 'crontab -l -u keystone | grep -v "^#"'
register: cron_result
changed_when: False
-
name: Check keystone crontab
fail: msg="keystone token_flush does not appear to be enabled via cron. You should add '<desired interval > {{ cron_check }}' to the keystone users crontab."