|
4 | 4 | file: complex.yaml |
5 | 5 |
|
6 | 6 | - name: Test keep_keys |
7 | | - vars: |
8 | | - result: "{{ l1 | ansible.utils.keep_keys(target=['p1', 'p2']) }}" |
9 | | - target: |
10 | | - - { p1: a, p2: a } |
11 | | - - { p1: b, p2: b } |
12 | | - - { p1: c, p2: c } |
13 | 7 | tags: keep_keys |
14 | 8 | block: |
| 9 | + - name: Setup data as facts for complex keep_keys integration test l1 |
| 10 | + ansible.builtin.set_fact: |
| 11 | + l1: |
| 12 | + - { p1: a, p2: a, p3: a } |
| 13 | + - { p1: b, p2: b, p3: b } |
| 14 | + - { p1: c, p2: c, p3: c } |
| 15 | + |
15 | 16 | - name: Test keep_keys debug |
16 | 17 | ansible.builtin.debug: |
17 | | - var: result|to_yaml |
18 | | - when: debug_test|d(false)|bool |
| 18 | + msg: "{{ l1 | ansible.utils.keep_keys(target=['p1', 'p2']) }}" |
| 19 | + register: result |
| 20 | + |
19 | 21 | - name: Test keep_keys assert |
20 | 22 | ansible.builtin.assert: |
21 | | - that: result == target |
| 23 | + that: result['msg'] == keep['l1'] |
22 | 24 |
|
23 | | -- name: Test map keep_keys |
24 | | - vars: |
25 | | - result: "{{ l2 | map('ansible.utils.keep_keys', target=['p1', 'p2']) | list }}" |
26 | | - target: |
27 | | - - - { p1: a, p2: a } |
28 | | - - { p1: b, p2: b } |
29 | | - - { p1: c, p2: c } |
30 | | - - - { p1: a, p2: a } |
31 | | - - { p1: b, p2: b } |
32 | | - - { p1: c, p2: c } |
33 | | - - - { p1: a, p2: a } |
34 | | - - { p1: b, p2: b } |
35 | | - - { p1: c, p2: c } |
36 | | - tags: map_keep_keys |
37 | | - block: |
38 | | - - name: Test map keep_keys debug |
| 25 | + - name: Debug l1 for starts_with 'p' |
39 | 26 | ansible.builtin.debug: |
40 | | - var: result|to_yaml |
41 | | - when: debug_test|d(false)|bool |
42 | | - - name: Test map keep_keys assert |
43 | | - ansible.builtin.assert: |
44 | | - that: result == target |
| 27 | + msg: "{{ l1 | ansible.utils.keep_keys(target=['p1', 'p2'], matching_parameter='starts_with') }}" |
| 28 | + register: result_l1_starts_with_p |
45 | 29 |
|
46 | | -- name: Test keep_keys starts_with |
47 | | - vars: |
48 | | - result: "{{ l1 | ansible.utils.keep_keys(target=['p1', 'p2'], matching_parameter='starts_with') }}" |
49 | | - target: |
50 | | - - { p1: a, p2: a } |
51 | | - - { p1: b, p2: b } |
52 | | - - { p1: c, p2: c } |
53 | | - tags: keep_keys_starts_with_2 |
54 | | - block: |
55 | | - - name: Test keep_keys starts_with debug |
56 | | - ansible.builtin.debug: |
57 | | - var: result|to_yaml |
58 | | - when: debug_test|d(false)|bool |
59 | | - - name: Test keep_keys starts_with assert |
| 30 | + - name: Assert result dicts l1 for starts_with 'p' |
60 | 31 | ansible.builtin.assert: |
61 | | - that: result == target |
| 32 | + that: |
| 33 | + - result_l1_starts_with_p['msg'] == keep['l1_starts_with_p'] |
62 | 34 |
|
63 | | -- name: Test keep_keys starts_with 'p' |
64 | | - vars: |
65 | | - result: "{{ l1 | ansible.utils.keep_keys(target=['p'], matching_parameter='starts_with') }}" |
66 | | - target: |
67 | | - - { p1: a, p2: a, p3: a } |
68 | | - - { p1: b, p2: b, p3: b } |
69 | | - - { p1: c, p2: c, p3: c } |
70 | | - tags: keep_keys_starts_with_1 |
71 | | - block: |
72 | | - - name: Test keep_keys starts_with 'p' debug |
| 35 | + - name: Debug l1 for ends_with |
73 | 36 | ansible.builtin.debug: |
74 | | - var: result|to_yaml |
75 | | - when: debug_test|d(false)|bool |
76 | | - - name: Test keep_keys starts_with 'p' assert |
| 37 | + msg: "{{ l1 | ansible.utils.keep_keys(target=['p1', 'p2'], matching_parameter='ends_with') }}" |
| 38 | + register: result_l1_ends_with |
| 39 | + |
| 40 | + - name: Assert result dicts l1 for ends_with |
77 | 41 | ansible.builtin.assert: |
78 | | - that: result == target |
| 42 | + that: |
| 43 | + - result_l1_ends_with['msg'] == keep['l1_ends_with'] |
79 | 44 |
|
80 | | -- name: Test keep_keys ends_with |
81 | | - vars: |
82 | | - result: "{{ l1 | ansible.utils.keep_keys(target=['p1', 'p2'], matching_parameter='ends_with') }}" |
83 | | - target: |
84 | | - - { p1: a, p2: a } |
85 | | - - { p1: b, p2: b } |
86 | | - - { p1: c, p2: c } |
87 | | - tags: keep_keys_ends_with_2 |
88 | | - block: |
89 | | - - name: Test keep_keys end_with debug |
| 45 | + - name: Debug l1 for ends_with '2' |
90 | 46 | ansible.builtin.debug: |
91 | | - var: result|to_yaml |
92 | | - when: debug_test|d(false)|bool |
93 | | - - name: Test keep_keys end_with assert |
| 47 | + msg: "{{ l1 | ansible.utils.keep_keys(target=['2'], matching_parameter='ends_with') }}" |
| 48 | + register: result_l1_ends_with_2 |
| 49 | + |
| 50 | + - name: Assert result dicts l1 for ends_with '2' |
94 | 51 | ansible.builtin.assert: |
95 | | - that: result == target |
| 52 | + that: |
| 53 | + - result_l1_ends_with_2['msg'] == keep['l1_ends_with_2'] |
96 | 54 |
|
97 | | -- name: Test keep_keys ends_with '2' |
98 | | - vars: |
99 | | - result: "{{ l1 | ansible.utils.keep_keys(target=['2'], matching_parameter='ends_with') }}" |
100 | | - target: |
101 | | - - { p2: a } |
102 | | - - { p2: b } |
103 | | - - { p2: c } |
104 | | - tags: keep_keys_ends_with_1 |
105 | | - block: |
106 | | - - name: Test keep_keys end_with '2' debug |
| 55 | + - name: Test keep_keys regex |
107 | 56 | ansible.builtin.debug: |
108 | | - var: result|to_yaml |
109 | | - when: debug_test|d(false)|bool |
110 | | - - name: Test keep_keys end_with '2' assert |
| 57 | + msg: "{{ l1 | ansible.utils.keep_keys(target=['p1', 'p2'], matching_parameter='regex') }}" |
| 58 | + register: result_l1_regex |
| 59 | + |
| 60 | + - name: Assert result dicts l1 for regex |
111 | 61 | ansible.builtin.assert: |
112 | | - that: result == target |
| 62 | + that: |
| 63 | + - result_l1_regex['msg'] == keep['l1_regex'] |
113 | 64 |
|
114 | | -- name: Test keep_keys regex |
115 | | - vars: |
116 | | - result: "{{ l1 | ansible.utils.keep_keys(target=['p1', 'p2'], matching_parameter='regex') }}" |
117 | | - target: |
118 | | - - { p1: a, p2: a } |
119 | | - - { p1: b, p2: b } |
120 | | - - { p1: c, p2: c } |
121 | | - tags: keep_keys_regex |
| 65 | +- name: Test map keep_keys |
| 66 | + tags: map_keep_keys |
122 | 67 | block: |
123 | | - - name: Test keep_keys regex debug |
| 68 | + - name: Setup data as facts for complex keep integration test l2 |
| 69 | + ansible.builtin.set_fact: |
| 70 | + l2: |
| 71 | + - - { p1: a, p2: a, p3: a } |
| 72 | + - { p1: b, p2: b, p3: b } |
| 73 | + - { p1: c, p2: c, p3: c } |
| 74 | + - - { p1: a, p2: a, p3: a } |
| 75 | + - { p1: b, p2: b, p3: b } |
| 76 | + - { p1: c, p2: c, p3: c } |
| 77 | + - - { p1: a, p2: a, p3: a } |
| 78 | + - { p1: b, p2: b, p3: b } |
| 79 | + - { p1: c, p2: c, p3: c } |
| 80 | + |
| 81 | + - name: Test map keep_keys debug |
124 | 82 | ansible.builtin.debug: |
125 | | - var: result|to_yaml |
126 | | - when: debug_test|d(false)|bool |
127 | | - - name: Test keep_keys regex assert |
| 83 | + msg: "{{ l2 | map('ansible.utils.keep_keys', target=['p1', 'p2']) | list }}" |
| 84 | + register: result |
| 85 | + |
| 86 | + - name: Test map keep_keys assert |
128 | 87 | ansible.builtin.assert: |
129 | | - that: result == target |
| 88 | + that: result['msg'] == keep['l2'] |
0 commit comments