Ensure we load roles for linting

Did didn't have ansible-lint setup properly, as a results our roles
weren't actually linted properly.

Fix variable linting issues and ignore ANSIBLE0012.

Change-Id: I07aa940245e700c9f08df0f1920720f0ed9d3de0
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
Paul Belanger 2017-07-17 16:50:06 -04:00
parent 9258e5b6d8
commit 829297c37a
No known key found for this signature in database
GPG Key ID: 611A80832067AF38
10 changed files with 39 additions and 18 deletions

View File

@ -1,14 +1,20 @@
- hosts: all - hosts: all
pre_tasks: pre_tasks:
- shell: tox -l - name: Register tox environment list
command: tox -l
args: args:
chdir: "src/{{ zuul.project.canonical_name }}" chdir: "src/{{ zuul.project.canonical_name }}"
register: envlist register: envlist
- set_fact:
- name: Define tox_envlist fact for pep8
set_fact:
tox_envlist: 'pep8' tox_envlist: 'pep8'
when: envlist.stdout.find('pep8') != -1 when: envlist.stdout.find('pep8') != -1
- set_fact:
- name: Define tox_envlist fact for linters
set_fact:
tox_envlist: 'linters' tox_envlist: 'linters'
when: envlist.stdout.find('linters') != -1 when: envlist.stdout.find('linters') != -1
roles: roles:
- tox - tox

View File

@ -3,7 +3,8 @@
path: "{{ bindep_dir }}/bindep.txt" path: "{{ bindep_dir }}/bindep.txt"
register: bindep_file_stat register: bindep_file_stat
- set_fact: - name: Define bindep_file fact
set_fact:
bindep_file: "{{ bindep_file_stat.stat.path }}" bindep_file: "{{ bindep_file_stat.stat.path }}"
when: bindep_file_stat.stat.exists when: bindep_file_stat.stat.exists
@ -13,7 +14,8 @@
register: bindep_other_file_stat register: bindep_other_file_stat
when: not bindep_file_stat.stat.exists when: not bindep_file_stat.stat.exists
- set_fact: - name: Define bindep_file fact
set_fact:
bindep_file: "{{ bindep_other_file_stat.stat.path }}" bindep_file: "{{ bindep_other_file_stat.stat.path }}"
when: not bindep_other_file_stat|skipped and bindep_other_file_stat.stat.exists when: not bindep_other_file_stat|skipped and bindep_other_file_stat.stat.exists
@ -25,6 +27,7 @@
and not bindep_other_file_stat|skipped and not bindep_other_file_stat|skipped
and not bindep_other_file_stat.stat.exists and not bindep_other_file_stat.stat.exists
- set_fact: - name: Define bindep_file fact
set_fact:
bindep_file: "{{ bindep_fallback_file_stat.stat.path }}" bindep_file: "{{ bindep_fallback_file_stat.stat.path }}"
when: not bindep_fallback_file_stat|skipped and bindep_fallback_file_stat.stat.exists when: not bindep_fallback_file_stat|skipped and bindep_fallback_file_stat.stat.exists

View File

@ -11,5 +11,6 @@
name: bindep name: bindep
virtualenv: "{{ bindep_temp_dir }}/venv" virtualenv: "{{ bindep_temp_dir }}/venv"
- set_fact: - name: Define bindep_found_command
set_fact:
bindep_found_command: "{{ bindep_temp_dir }}/venv/bin/bindep" bindep_found_command: "{{ bindep_temp_dir }}/venv/bin/bindep"

View File

@ -8,12 +8,13 @@
- name: Check for system bindep - name: Check for system bindep
args: args:
executable: /bin/bash executable: /bin/bash
shell: type -p bindep command: type -p bindep
ignore_errors: yes ignore_errors: yes
register: bindep_command_type register: bindep_command_type
when: bindep_command is not defined or not bindep_command_stat.stat.exists when: bindep_command is not defined or not bindep_command_stat.stat.exists
- set_fact: - name: Define bindep_command fact
set_fact:
bindep_command: "{{ bindep_command_type.stdout }}" bindep_command: "{{ bindep_command_type.stdout }}"
when: bindep_command_type|succeeded and not bindep_command_type|skipped when: bindep_command_type|succeeded and not bindep_command_type|skipped
@ -23,7 +24,8 @@
- include: find.yaml - include: find.yaml
when: bindep_file is not defined when: bindep_file is not defined
- set_fact: - name: Define bindep_command fact
set_fact:
bindep_run: "{{ bindep_command }} -b -f {{ bindep_file }} {{ bindep_profile }}" bindep_run: "{{ bindep_command }} -b -f {{ bindep_file }} {{ bindep_profile }}"
- include: packages.yaml - include: packages.yaml

View File

@ -1,5 +1,5 @@
- name: Get list of packages to install from bindep - name: Get list of packages to install from bindep
shell: "{{ bindep_run }}" command: "{{ bindep_run }}"
register: bindep_output register: bindep_output
failed_when: false failed_when: false
@ -10,11 +10,12 @@
become: yes become: yes
- name: Check that packages are installed - name: Check that packages are installed
shell: "{{ bindep_run }}" command: "{{ bindep_run }}"
register: bindep_final_check register: bindep_final_check
# Ignore errors then fail later so that we can give a better error message # Ignore errors then fail later so that we can give a better error message
failed_when: false failed_when: false
- fail: - name: Fail if we cannot install all packages
fail:
msg: "bindep failed to install from {{ bindep_file}} - {{ bindep_final_check.stdout }}" msg: "bindep failed to install from {{ bindep_file}} - {{ bindep_final_check.stdout }}"
when: bindep_final_check|failed when: bindep_final_check|failed

View File

@ -5,4 +5,4 @@
state: absent state: absent
- name: Prove that general sudo access is actually revoked. - name: Prove that general sudo access is actually revoked.
shell: ! sudo -n true command: ! sudo -n true

View File

@ -4,7 +4,7 @@
register: p register: p
- name: Run tools/test-setup.sh - name: Run tools/test-setup.sh
shell: tools/test-setup.sh command: tools/test-setup.sh
args: args:
chdir: "{{ zuul_work_dir }}" chdir: "{{ zuul_work_dir }}"
when: when:

View File

@ -1,4 +1,5 @@
- set_fact: - name: Define zuul_info_dir fact
set_fact:
zuul_info_dir: "{{ zuul.executor.log_root }}/zuul-info" zuul_info_dir: "{{ zuul.executor.log_root }}/zuul-info"
- name: Ensure Zuul Ansible directory exists - name: Ensure Zuul Ansible directory exists

2
tests/ansible.cfg Normal file
View File

@ -0,0 +1,2 @@
[defaults]
roles_path = ../roles

View File

@ -21,11 +21,16 @@ commands = bindep test
commands = python setup.py build_sphinx commands = python setup.py build_sphinx
[testenv:pep8] [testenv:pep8]
setenv =
ANSIBLE_CONFIG = {toxinidir}/tests/ansible.cfg
whitelist_externals = bash whitelist_externals = bash
commands = commands =
flake8 {posargs} flake8 {posargs}
bash -c "cd roles; find . -type f -regex '.*.y[a]?ml' -print0 | xargs -t -n1 -0 \ # Ansible Lint Check
ansible-lint" # NOTE(pabelanger): Ignore the following checks:
# ANSIBlE0012: Commands should not change things if nothing needs doing
bash -c "cd playbooks; find . -type f -regex '.*.y[a]?ml' -print0 | xargs -t -n1 -0 \
ansible-lint -x ANSIBLE0012"
[testenv:venv] [testenv:venv]
commands = {posargs} commands = {posargs}