zuul-jobs/test-playbooks/ansible-lint-rules/run.yaml
Albin Vass aeca4e34e3 Fix ansible-lint rules tests
ansible-lint does not work when given an empty (/dev/null) config file.

Traceback (most recent call last):
  File "/tmp/ansible.td6htcac/bin/ansible-lint", line 8, in <module>
    sys.exit(main())
  File "/tmp/ansible.td6htcac/lib/python3.6/site-packages/ansiblelint/__main__.py", line 42, in main
    options = cli.get_config(sys.argv[1:])
  File "/tmp/ansible.td6htcac/lib/python3.6/site-packages/ansiblelint/cli.py", line 208, in get_config
    config = load_config(options.config_file)
  File "/tmp/ansible.td6htcac/lib/python3.6/site-packages/ansiblelint/cli.py", line 77, in load_config
    expand_to_normalized_paths(config, config_dir)
  File "/tmp/ansible.td6htcac/lib/python3.6/site-packages/ansiblelint/cli.py", line 40, in expand_to_normalized_paths
    if paths_var not in config:
TypeError: argument of type 'NoneType' is not iterable

Change-Id: Id2a883676c9fbb3a2c704c8cbd8f3cbc28cdc5fb
2020-06-18 00:12:55 +02:00

62 lines
2.1 KiB
YAML

- hosts: all
roles:
- ensure-pip
- ensure-virtualenv
tasks:
- name: Create tempdir for ansible-lint venv
tempfile:
state: directory
register: ansible_lint_tempdir
- name: Install linters-requirements.txt
pip:
requirements: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/linters-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
-c test-playbooks/ansible-lint-rules/ansible-lint.yaml
-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
-c test-playbooks/ansible-lint-rules/ansible-lint.yaml
-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 }}"