Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/callback/tasks/main.yml

raw
1 ---
2 ####################################################################
3 # WARNING: These are designed specifically for Ansible tests #
4 # and should not be used as examples of how to write Ansible roles #
5 ####################################################################
6
7 # Copyright (c) Ansible Project
8 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
9 # SPDX-License-Identifier: GPL-3.0-or-later
10
11 - block:
12 - name: Create temporary playbook files
13 tempfile:
14 state: file
15 suffix: temp
16 loop: "{{ tests }}"
17 loop_control:
18 loop_var: test
19 label: "{{ test.name }}"
20 register: temporary_playbook_files
21
22 - name: Set temporary playbook file content
23 copy:
24 content: "{{ test.playbook }}"
25 dest: "{{ temporary_playbook_files.results[test_idx].path }}"
26 loop: "{{ tests }}"
27 loop_control:
28 loop_var: test
29 index_var: test_idx
30 label: "{{ test.name }}"
31
32 - name: Collect outputs
33 command: "ansible-playbook -i {{ inventory }} {{ playbook }} {{ test.extra_cli_arguments | default('') }}"
34 environment: "{{ test.environment }}"
35 loop: "{{ tests }}"
36 loop_control:
37 loop_var: test
38 label: "{{ test.name }}"
39 register: outputs
40 changed_when: false
41 vars:
42 inventory: "{{ role_path }}/inventory.yml"
43 playbook: "
44 {%- for result in temporary_playbook_files.results -%}
45 {%- if result.test.name == test.name -%}
46 {{- result.path -}}
47 {%- endif -%}
48 {%- endfor -%}"
49
50 - name: Assert test output equals expected output
51 assert:
52 that: result.output.differences | length == 0
53 loop: "{{ outputs.results | callback_results_extractor }}"
54 loop_control:
55 loop_var: result
56 label: "{{ result.name }}"
57 register: assertions
58
59 always:
60 - name: Remove temporary playbooks
61 file:
62 path: "{{ temporary_file.path }}"
63 state: absent
64 loop: "{{ temporary_playbook_files.results }}"
65 loop_control:
66 loop_var: temporary_file
67 label: "{{ temporary_file.test.name }}: {{ temporary_file.path }}"