zuul-jobs/test-playbooks/ansible-lint-rules/run.yaml
Albin Vass 9ad8c11469 Check blocks recursively for loops
Also updates tests for the custom ansible-lint rules.

Adds a simple testsuite so test roles and playbooks that are known to be
faulty or valid can be put in a directory structure like:

<rule id>/valid/playbooks/valid_playbook.yaml
<rule id>/valid/roles/valid_role/tasks/main.yaml
<rule id>/valid/roles/valid_role/handlers/main.yaml

<rule id>/faulty/playbooks/faulty_playbook.yaml
<rule id>/faulty/roles/faulty_role/tasks/main.yaml
<rule id>/faulty/roles/faulty_role/handlers/main.yaml

So they will verify that the rules work as expected.

Change-Id: I29d0766c67e690e35490586f6befb95e4cd31b98
2020-05-05 22:56:46 +02:00

59 lines
1.9 KiB
YAML

- hosts: all
roles:
- ensure-pip
tasks:
- name: Create tempdir for ansible-lint venv
tempfile:
state: directory
register: ansible_lint_tempdir
- name: Install test-requirements.txt
pip:
requirements: "{{ansible_user_dir}}/{{ zuul.project.src_dir }}/test-requirements.txt"
virtualenv: "{{ ansible_lint_tempdir.path }}"
- name: Make sure ansible-lint is installed
command: "{{ ansible_lint_tempdir.path }}/bin/ansible-lint --version"
- name: Get faulty playbooks and roles
command: >-
find test-playbooks/ansible-lint-rules/
-mindepth 4
-maxdepth 4
-wholename '*ZUULJOBS*/faulty/*/*'
args:
chdir: "{{ ansible_user_dir}}/{{ zuul.project.src_dir }}"
register: faulty_ansible_items
- name: Get valid playbooks and roles
command: >-
find test-playbooks/ansible-lint-rules/
-mindepth 4
-maxdepth 4
-wholename '*ZUULJOBS*/valid/roles/*'
args:
chdir: "{{ ansible_user_dir}}/{{ zuul.project.src_dir }}"
register: valid_ansible_items
- name: Make sure faulty roles fail linting
command: >-
{{ ansible_lint_tempdir.path }}/bin/ansible-lint
-t {{ item | regex_replace('.*/(ZUULJOBS.*?)/.*', '\1') }}
{{ item }}
args:
chdir: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}"
register: ansible_lint
failed_when: ansible_lint.rc == 0
loop: "{{ faulty_ansible_items.stdout_lines }}"
- name: Make sure valid roles pass linting
command: >-
{{ ansible_lint_tempdir.path }}/bin/ansible-lint
-t {{ item | regex_replace('.*/(ZUULJOBS.*?)/.*', '\1') }}
{{ item }}
args:
chdir: "{{ansible_user_dir}}/{{ zuul.project.src_dir }}"
register: ansible_lint
failed_when: ansible_lint.rc != 0
loop: "{{ valid_ansible_items.stdout_lines }}"