| 1 |
--- |
| 2 |
# Copyright (c) Ansible Project |
| 3 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
|
| 6 |
- when: sops_installed |
| 7 |
block: |
| 8 |
- name: Test load_vars with missing option |
| 9 |
community.sops.load_vars: |
| 10 |
register: load_vars_missing_option |
| 11 |
failed_when: load_vars_missing_option is not failed |
| 12 |
|
| 13 |
- assert: |
| 14 |
that: |
| 15 |
- '"missing required arguments: file" in load_vars_missing_option.msg' |
| 16 |
|
| 17 |
- name: Test load_vars with wrong choice value |
| 18 |
community.sops.load_vars: |
| 19 |
file: a |
| 20 |
expressions: invalid value |
| 21 |
register: load_vars_invalid_value |
| 22 |
failed_when: load_vars_invalid_value is not failed |
| 23 |
|
| 24 |
- assert: |
| 25 |
that: |
| 26 |
- '"value of expressions must be one of: ignore, evaluate-on-load, lazy-evaluation, got: invalid value" in load_vars_invalid_value.msg' |
| 27 |
|
| 28 |
- name: Test load_vars with missing file |
| 29 |
community.sops.load_vars: |
| 30 |
file: non-existent.sops.yaml |
| 31 |
register: load_vars_missing_file |
| 32 |
failed_when: load_vars_missing_file is not failed |
| 33 |
|
| 34 |
- assert: |
| 35 |
that: |
| 36 |
- | |
| 37 |
"Could not find or access 'non-existent.sops.yaml'\n" in load_vars_missing_file.msg |
| 38 |
|
| 39 |
- name: Test load_vars with non-sops file |
| 40 |
community.sops.load_vars: |
| 41 |
file: wrong.yaml |
| 42 |
register: load_vars_wrong_file |
| 43 |
failed_when: load_vars_wrong_file is not failed |
| 44 |
|
| 45 |
- assert: |
| 46 |
that: |
| 47 |
- "'sops metadata not found' in load_vars_wrong_file.msg" |
| 48 |
|
| 49 |
- name: Test load_vars with simple file into variable (1/3) |
| 50 |
community.sops.load_vars: |
| 51 |
file: simple.sops.yaml |
| 52 |
name: dest_variable |
| 53 |
register: load_vars_simple |
| 54 |
|
| 55 |
- assert: |
| 56 |
that: |
| 57 |
- load_vars_simple is success |
| 58 |
- >- |
| 59 |
ansible_version.full is version('2.21', '>=') or |
| 60 |
load_vars_simple.ansible_facts == {'dest_variable': {'foo': 'bar'}} |
| 61 |
- >- |
| 62 |
ansible_version.full is version('2.21', '<') or |
| 63 |
'ansible_facts' not in load_vars_simple |
| 64 |
- dest_variable.foo == 'bar' |
| 65 |
- foo is undefined |
| 66 |
|
| 67 |
- name: Test load_vars with simple file into variable (2/3) |
| 68 |
community.sops.load_vars: |
| 69 |
file: simple.sops.yaml |
| 70 |
name: dest_variable_2 |
| 71 |
return_method: facts-only |
| 72 |
register: load_vars_simple_2 |
| 73 |
|
| 74 |
- assert: |
| 75 |
that: |
| 76 |
- load_vars_simple_2 is success |
| 77 |
- >- |
| 78 |
load_vars_simple_2.ansible_facts == {'dest_variable_2': {'foo': 'bar'}} |
| 79 |
- ansible_facts.dest_variable_2.foo == 'bar' |
| 80 |
- >- |
| 81 |
ansible_version.full is version('2.24', '>=') or |
| 82 |
dest_variable_2.foo == 'bar' |
| 83 |
register: load_vars_simple_2_assert |
| 84 |
|
| 85 |
- name: Show deprecations |
| 86 |
debug: |
| 87 |
msg: "{{ load_vars_simple_2_assert.deprecations | default([]) }}" |
| 88 |
|
| 89 |
- when: ansible_version.full is version('2.20', '>=') and ansible_version.full is version('2.24', '<') |
| 90 |
assert: |
| 91 |
that: |
| 92 |
- load_vars_simple_2_assert.deprecations | length > 0 |
| 93 |
- load_vars_simple_2_assert.deprecations | map(attribute='msg') | select('ansible.builtin.regex', 'INJECT_FACTS_AS_VARS') | length > 0 |
| 94 |
|
| 95 |
- name: Test load_vars with simple file into variable (3/3) |
| 96 |
community.sops.load_vars: |
| 97 |
file: simple.sops.yaml |
| 98 |
name: dest_variable_3 |
| 99 |
return_method: vars-only |
| 100 |
register: load_vars_simple_3 |
| 101 |
ignore_errors: true |
| 102 |
|
| 103 |
- when: ansible_version.full is version('2.21', '>=') |
| 104 |
assert: |
| 105 |
that: |
| 106 |
- load_vars_simple_3 is success |
| 107 |
- >- |
| 108 |
"ansible_facts" not in load_vars_simple_3 |
| 109 |
- dest_variable_3.foo == 'bar' |
| 110 |
|
| 111 |
- when: ansible_version.full is version('2.21', '<') |
| 112 |
assert: |
| 113 |
that: |
| 114 |
- load_vars_simple_3 is failed |
| 115 |
- load_vars_simple_3.msg == "return_method=vars-only requires ansible-core 2.21+" |
| 116 |
|
| 117 |
- name: Test load_vars with empty file |
| 118 |
community.sops.load_vars: |
| 119 |
file: empty.sops.json |
| 120 |
register: load_vars_empty |
| 121 |
|
| 122 |
- assert: |
| 123 |
that: |
| 124 |
- load_vars_empty is success |
| 125 |
- >- |
| 126 |
ansible_version.full is version('2.21', '>=') or |
| 127 |
(load_vars_empty.ansible_facts | length == 0) |
| 128 |
|
| 129 |
- name: Test load_vars with simple file into global namespace |
| 130 |
community.sops.load_vars: |
| 131 |
file: simple.sops.yaml |
| 132 |
register: load_vars_simple_global |
| 133 |
|
| 134 |
- assert: |
| 135 |
that: |
| 136 |
- load_vars_simple_global is success |
| 137 |
- >- |
| 138 |
ansible_version.full is version('2.21', '>=') or |
| 139 |
load_vars_simple_global.ansible_facts == {'foo': 'bar'} |
| 140 |
- foo == 'bar' |
| 141 |
|
| 142 |
- name: Test load_vars with expressions ignored |
| 143 |
community.sops.load_vars: |
| 144 |
file: proper-vars.sops.yaml |
| 145 |
expressions: ignore |
| 146 |
register: load_vars_expr_ignore |
| 147 |
|
| 148 |
- assert: |
| 149 |
that: |
| 150 |
- load_vars_expr_ignore is success |
| 151 |
- test1 == '{' ~ '{ bar }' ~ '}' |
| 152 |
- test2 == '{' ~ '{ this_will_not_get_evaluated }' ~ '}' |
| 153 |
- bar == 'baz' |
| 154 |
|
| 155 |
- set_fact: |
| 156 |
to_be_defined_earlier: something_defined_before |
| 157 |
bar_2: baz |
| 158 |
|
| 159 |
- name: Test load_vars with expressions evaluated now |
| 160 |
community.sops.load_vars: |
| 161 |
file: proper-vars-2.sops.yaml |
| 162 |
expressions: evaluate-on-load |
| 163 |
register: load_vars_expr_evaluated_now |
| 164 |
|
| 165 |
- set_fact: |
| 166 |
to_be_defined_earlier: something_else |
| 167 |
|
| 168 |
- assert: |
| 169 |
that: |
| 170 |
- load_vars_expr_evaluated_now is success |
| 171 |
- test1_2 == 'baz' |
| 172 |
- test2_2 == 'something_defined_before' |
| 173 |
- test3_2[0] == 'baz' |
| 174 |
- test4_2.test_4_2_1 == 'bazbaz' |
| 175 |
|
| 176 |
- name: Test load_vars with expressions evaluated now (again) |
| 177 |
community.sops.load_vars: |
| 178 |
file: proper-vars-2.sops.yaml |
| 179 |
expressions: evaluate-on-load |
| 180 |
register: load_vars_expr_evaluated_now_2 |
| 181 |
|
| 182 |
- assert: |
| 183 |
that: |
| 184 |
- load_vars_expr_evaluated_now_2 is success |
| 185 |
- test2_2 == 'something_else' |
| 186 |
|
| 187 |
- when: ansible_version.full is version('2.19', '>=') |
| 188 |
block: |
| 189 |
- set_fact: |
| 190 |
to_be_defined_earlier: something_defined_before |
| 191 |
bar_2: baz |
| 192 |
|
| 193 |
- name: Test load_vars with expressions evaluated lazily |
| 194 |
community.sops.load_vars: |
| 195 |
file: proper-vars-2.sops.yaml |
| 196 |
expressions: lazy-evaluation |
| 197 |
register: load_vars_expr_lazy_evaluated |
| 198 |
|
| 199 |
- assert: |
| 200 |
that: |
| 201 |
- load_vars_expr_lazy_evaluated is success |
| 202 |
- test1_2 == 'baz' |
| 203 |
- test2_2 == 'something_defined_before' |
| 204 |
- test3_2[0] == 'baz' |
| 205 |
- test4_2.test_4_2_1 == 'bazbaz' |
| 206 |
|
| 207 |
- set_fact: |
| 208 |
to_be_defined_earlier: something_else |
| 209 |
bar_2: buzz |
| 210 |
|
| 211 |
- assert: |
| 212 |
that: |
| 213 |
- load_vars_expr_lazy_evaluated is success |
| 214 |
- test1_2 == 'buzz' |
| 215 |
- test2_2 == 'something_else' |
| 216 |
- test3_2[0] == 'buzz' |
| 217 |
- test4_2.test_4_2_1 == 'buzzbuzz' |