Merge "Check blocks recursively for loops"
This commit is contained in:
commit
8478544a62
@ -20,6 +20,25 @@ https://zuul-ci.org/docs/zuul-jobs/policy.html\
|
|||||||
if file.get('type') not in ('tasks', 'handlers'):
|
if file.get('type') not in ('tasks', 'handlers'):
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
results.extend(self.handle_play(task))
|
||||||
|
return results
|
||||||
|
|
||||||
|
def handle_play(self, task):
|
||||||
|
results = []
|
||||||
|
if 'block' in task:
|
||||||
|
results.extend(self.handle_playlist(task['block']))
|
||||||
|
else:
|
||||||
|
results.extend(self.handle_task(task))
|
||||||
|
return results
|
||||||
|
|
||||||
|
def handle_playlist(self, playlist):
|
||||||
|
results = []
|
||||||
|
for play in playlist:
|
||||||
|
results.extend(self.handle_play(play))
|
||||||
|
return results
|
||||||
|
|
||||||
|
def handle_task(self, task):
|
||||||
|
results = []
|
||||||
has_loop = 'loop' in task
|
has_loop = 'loop' in task
|
||||||
for key in task.keys():
|
for key in task.keys():
|
||||||
if key.startswith('with_'):
|
if key.startswith('with_'):
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
- block:
|
||||||
|
- debug:
|
||||||
|
var: item
|
||||||
|
loop:
|
||||||
|
- 1
|
||||||
|
- 2
|
@ -0,0 +1,6 @@
|
|||||||
|
- block:
|
||||||
|
- debug:
|
||||||
|
var: item
|
||||||
|
with_items:
|
||||||
|
- 1
|
||||||
|
- 2
|
@ -0,0 +1,7 @@
|
|||||||
|
- block:
|
||||||
|
- block:
|
||||||
|
- debug:
|
||||||
|
var: item
|
||||||
|
loop:
|
||||||
|
- 1
|
||||||
|
- 2
|
@ -0,0 +1,8 @@
|
|||||||
|
- block:
|
||||||
|
- debug:
|
||||||
|
msg: zj_item
|
||||||
|
loop:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
loop_control:
|
||||||
|
loop_var: zj_item
|
@ -0,0 +1,8 @@
|
|||||||
|
- block:
|
||||||
|
- debug:
|
||||||
|
msg: zj_item
|
||||||
|
with_items:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
loop_control:
|
||||||
|
loop_var: zj_item
|
@ -0,0 +1,5 @@
|
|||||||
|
- debug: # noqa ZUULJOBS0001
|
||||||
|
var: item
|
||||||
|
loop:
|
||||||
|
- 1
|
||||||
|
- 2
|
@ -15,28 +15,44 @@
|
|||||||
- name: Make sure ansible-lint is installed
|
- name: Make sure ansible-lint is installed
|
||||||
command: "{{ ansible_lint_tempdir.path }}/bin/ansible-lint --version"
|
command: "{{ ansible_lint_tempdir.path }}/bin/ansible-lint --version"
|
||||||
|
|
||||||
- name: Make sure missing loopvars fail linting
|
- name: Get faulty playbooks and roles
|
||||||
command: "{{ ansible_lint_tempdir.path }}/bin/ansible-lint test-playbooks/ansible-lint-rules/roles/{{ item }}"
|
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:
|
args:
|
||||||
chdir: "{{ansible_user_dir}}/{{ zuul.project.src_dir }}"
|
chdir: "{{ansible_user_dir}}/{{ zuul.project.src_dir }}"
|
||||||
register: ansible_lint
|
register: ansible_lint
|
||||||
failed_when: ansible_lint.rc == 0
|
failed_when: ansible_lint.rc != 0
|
||||||
loop:
|
loop: "{{ valid_ansible_items.stdout_lines }}"
|
||||||
- tasks-missing-loopvar-with
|
|
||||||
- tasks-missing-loopvar-loop
|
|
||||||
- tasks-include-missing-loopvar-with
|
|
||||||
- tasks-include-missing-loopvar-loop
|
|
||||||
- handlers-missing-loopvar-with
|
|
||||||
- handlers-missing-loopvar-loop
|
|
||||||
|
|
||||||
- name: Make sure valid configuration passes linting
|
|
||||||
command: "{{ ansible_lint_tempdir.path }}/bin/ansible-lint test-playbooks/ansible-lint-rules/roles/{{ item }}"
|
|
||||||
args:
|
|
||||||
chdir: "{{ansible_user_dir}}/{{ zuul.project.src_dir }}"
|
|
||||||
loop:
|
|
||||||
- tasks-loopvar-with
|
|
||||||
- tasks-loopvar-loop
|
|
||||||
- tasks-include-loopvar-with
|
|
||||||
- tasks-include-loopvar-loop
|
|
||||||
- handlers-loopvar-with
|
|
||||||
- handlers-loopvar-loop
|
|
||||||
|
Loading…
Reference in New Issue
Block a user