| 1 |
--- |
| 2 |
- ansible.builtin.set_fact: |
| 3 |
# As a lookup plugin we don't have access to module_defaults |
| 4 |
connection_args: |
| 5 |
region: "{{ aws_region }}" |
| 6 |
access_key: "{{ aws_access_key }}" |
| 7 |
secret_key: "{{ aws_secret_key }}" |
| 8 |
session_token: "{{ security_token | default(omit) }}" |
| 9 |
no_log: true |
| 10 |
|
| 11 |
- name: Aws_ssm lookup plugin integration tests |
| 12 |
module_defaults: |
| 13 |
group/aws: |
| 14 |
access_key: "{{ aws_access_key }}" |
| 15 |
secret_key: "{{ aws_secret_key }}" |
| 16 |
session_token: "{{ security_token | default(omit) }}" |
| 17 |
region: "{{ aws_region }}" |
| 18 |
vars: |
| 19 |
skip: skip |
| 20 |
warn: warn |
| 21 |
simple_name: /{{ ssm_key_prefix }}/Simple |
| 22 |
simple_description: This is a simple example |
| 23 |
simple_value: A simple VALue |
| 24 |
updated_value: A simple (updated) VALue |
| 25 |
path_name: /{{ ssm_key_prefix }}/path |
| 26 |
path_name_a: "{{ path_name }}/key_one" |
| 27 |
path_shortname_a: key_one |
| 28 |
path_droppath_name_a: /key_one |
| 29 |
path_name_b: "{{ path_name }}/keyTwo" |
| 30 |
path_shortname_b: keyTwo |
| 31 |
path_droppath_name_b: /keyTwo |
| 32 |
path_name_c: "{{ path_name }}/Nested/Key" |
| 33 |
path_shortname_c: Key |
| 34 |
path_droppath_name_c: /Nested/Key |
| 35 |
path_name_d: "{{ path_name }}/AnotherNested/Key" |
| 36 |
path_shortname_d: Key |
| 37 |
path_droppath_name_d: /AnotherNested/Key |
| 38 |
path_description: This is somewhere to store a set of keys |
| 39 |
path_value_a: value_one |
| 40 |
path_value_b: valueTwo |
| 41 |
path_value_c: Value Three |
| 42 |
path_value_d: value-fou |
| 43 |
missing_name: "{{ path_name }}/IDoNotExist" |
| 44 |
block: |
| 45 |
# ============================================================ |
| 46 |
# Simple key/value |
| 47 |
- name: Lookup a missing key (error) |
| 48 |
ansible.builtin.set_fact: |
| 49 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name, **connection_args) }}" |
| 50 |
ignore_errors: true |
| 51 |
register: lookup_missing |
| 52 |
- ansible.builtin.assert: |
| 53 |
that: |
| 54 |
- lookup_missing is failed |
| 55 |
|
| 56 |
- name: Lookup a missing key (warn) |
| 57 |
ansible.builtin.set_fact: |
| 58 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name, on_missing=warn, **connection_args) }}" |
| 59 |
register: lookup_missing |
| 60 |
- ansible.builtin.assert: |
| 61 |
that: |
| 62 |
- lookup_value is none |
| 63 |
|
| 64 |
- name: Lookup a single missing key (skip) |
| 65 |
ansible.builtin.set_fact: |
| 66 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name, on_missing=skip, **connection_args) }}" |
| 67 |
register: lookup_missing |
| 68 |
- ansible.builtin.assert: |
| 69 |
that: |
| 70 |
- lookup_value is none |
| 71 |
|
| 72 |
- name: Create key/value pair in aws parameter store |
| 73 |
community.aws.ssm_parameter: |
| 74 |
name: "{{ simple_name }}" |
| 75 |
description: "{{ simple_description }}" |
| 76 |
value: "{{ simple_value }}" |
| 77 |
|
| 78 |
- name: Lookup a single key |
| 79 |
ansible.builtin.set_fact: |
| 80 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name, **connection_args) }}" |
| 81 |
- ansible.builtin.assert: |
| 82 |
that: |
| 83 |
- lookup_value == simple_value |
| 84 |
|
| 85 |
- name: Create key/value pair in aws parameter store |
| 86 |
community.aws.ssm_parameter: |
| 87 |
name: "{{ simple_name }}" |
| 88 |
description: "{{ simple_description }}" |
| 89 |
value: "{{ simple_value }}" |
| 90 |
|
| 91 |
- name: Lookup a single key |
| 92 |
ansible.builtin.set_fact: |
| 93 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name, **connection_args) }}" |
| 94 |
- ansible.builtin.assert: |
| 95 |
that: |
| 96 |
- lookup_value == simple_value |
| 97 |
|
| 98 |
- name: Update key/value pair in aws parameter store |
| 99 |
community.aws.ssm_parameter: |
| 100 |
name: "{{ simple_name }}" |
| 101 |
description: "{{ simple_description }}" |
| 102 |
value: "{{ updated_value }}" |
| 103 |
|
| 104 |
- name: Lookup updated single key |
| 105 |
ansible.builtin.set_fact: |
| 106 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name, **connection_args) }}" |
| 107 |
- ansible.builtin.assert: |
| 108 |
that: |
| 109 |
- lookup_value == updated_value |
| 110 |
|
| 111 |
- name: Lookup original value from single key |
| 112 |
ansible.builtin.set_fact: |
| 113 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name + ':1', **connection_args) }}" |
| 114 |
- ansible.builtin.assert: |
| 115 |
that: |
| 116 |
- lookup_value == simple_value |
| 117 |
|
| 118 |
# ============================================================ |
| 119 |
|
| 120 |
- name: Create nested key/value pair in aws parameter store (1) |
| 121 |
community.aws.ssm_parameter: |
| 122 |
name: "{{ path_name_a }}" |
| 123 |
description: "{{ path_description }}" |
| 124 |
value: "{{ path_value_a }}" |
| 125 |
|
| 126 |
- name: Create nested key/value pair in aws parameter store (2) |
| 127 |
community.aws.ssm_parameter: |
| 128 |
name: "{{ path_name_b }}" |
| 129 |
description: "{{ path_description }}" |
| 130 |
value: "{{ path_value_b }}" |
| 131 |
|
| 132 |
- name: Create nested key/value pair in aws parameter store (3) |
| 133 |
community.aws.ssm_parameter: |
| 134 |
name: "{{ path_name_c }}" |
| 135 |
description: "{{ path_description }}" |
| 136 |
value: "{{ path_value_c }}" |
| 137 |
|
| 138 |
- name: Create nested key/value pair in aws parameter store (4) |
| 139 |
community.aws.ssm_parameter: |
| 140 |
name: "{{ path_name_d }}" |
| 141 |
description: "{{ path_description }}" |
| 142 |
value: "{{ path_value_d }}" |
| 143 |
|
| 144 |
# ============================================================ |
| 145 |
|
| 146 |
- name: Lookup a keys using bypath |
| 147 |
ansible.builtin.set_fact: |
| 148 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', path_name, bypath=True, wantlist=True, **connection_args) | first }}" |
| 149 |
- ansible.builtin.assert: |
| 150 |
that: |
| 151 |
- path_name_a in lookup_value |
| 152 |
- lookup_value[path_name_a] == path_value_a |
| 153 |
- path_name_b in lookup_value |
| 154 |
- lookup_value[path_name_b] == path_value_b |
| 155 |
- lookup_value | length == 2 |
| 156 |
|
| 157 |
- name: Lookup a keys using bypath and recursive |
| 158 |
ansible.builtin.set_fact: |
| 159 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', path_name, bypath=True, recursive=True, wantlist=True, **connection_args) | first }}" |
| 160 |
- ansible.builtin.assert: |
| 161 |
that: |
| 162 |
- path_name_a in lookup_value |
| 163 |
- lookup_value[path_name_a] == path_value_a |
| 164 |
- path_name_b in lookup_value |
| 165 |
- lookup_value[path_name_b] == path_value_b |
| 166 |
- path_name_c in lookup_value |
| 167 |
- lookup_value[path_name_c] == path_value_c |
| 168 |
- path_name_d in lookup_value |
| 169 |
- lookup_value[path_name_d] == path_value_d |
| 170 |
- lookup_value | length == 4 |
| 171 |
|
| 172 |
- name: Lookup a keys using bypath and shortname |
| 173 |
ansible.builtin.set_fact: |
| 174 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', path_name, bypath=True, shortnames=True, wantlist=True, **connection_args) | first }}" |
| 175 |
- ansible.builtin.assert: |
| 176 |
that: |
| 177 |
- path_shortname_a in lookup_value |
| 178 |
- lookup_value[path_shortname_a] == path_value_a |
| 179 |
- path_shortname_b in lookup_value |
| 180 |
- lookup_value[path_shortname_b] == path_value_b |
| 181 |
- lookup_value | length == 2 |
| 182 |
|
| 183 |
- name: Lookup a keys using bypath and recursive and shortname |
| 184 |
ansible.builtin.set_fact: |
| 185 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', path_name, bypath=True, recursive=True, shortnames=True, wantlist=True, **connection_args) | first }}" |
| 186 |
- ansible.builtin.assert: |
| 187 |
that: |
| 188 |
- path_shortname_a in lookup_value |
| 189 |
- lookup_value[path_shortname_a] == path_value_a |
| 190 |
- path_shortname_b in lookup_value |
| 191 |
- lookup_value[path_shortname_b] == path_value_b |
| 192 |
- path_shortname_c in lookup_value |
| 193 |
- lookup_value[path_shortname_c] == path_value_c |
| 194 |
- lookup_value | length == 3 |
| 195 |
|
| 196 |
- name: Lookup a keys using bypath and recursive and droppath |
| 197 |
ansible.builtin.set_fact: |
| 198 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', path_name, bypath=True, recursive=True, droppath=True, wantlist=True, **connection_args) | first }}" |
| 199 |
- ansible.builtin.assert: |
| 200 |
that: |
| 201 |
- path_droppath_name_a in lookup_value |
| 202 |
- lookup_value[path_droppath_name_a] == path_value_a |
| 203 |
- path_droppath_name_b in lookup_value |
| 204 |
- lookup_value[path_droppath_name_b] == path_value_b |
| 205 |
- path_droppath_name_c in lookup_value |
| 206 |
- lookup_value[path_droppath_name_c] == path_value_c |
| 207 |
- path_droppath_name_d in lookup_value |
| 208 |
- lookup_value[path_droppath_name_d] == path_value_d |
| 209 |
- lookup_value | length == 4 |
| 210 |
|
| 211 |
# ============================================================ |
| 212 |
|
| 213 |
- name: Explicitly lookup two keys |
| 214 |
ansible.builtin.set_fact: |
| 215 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name, path_name_a, wantlist=True, **connection_args) }}" |
| 216 |
- ansible.builtin.assert: |
| 217 |
that: |
| 218 |
- lookup_value | list | length == 2 |
| 219 |
- lookup_value[0] == updated_value |
| 220 |
- lookup_value[1] == path_value_a |
| 221 |
|
| 222 |
### |
| 223 |
|
| 224 |
- name: Explicitly lookup two keys - one missing |
| 225 |
ansible.builtin.set_fact: |
| 226 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name, missing_name, wantlist=True, **connection_args) }}" |
| 227 |
ignore_errors: true |
| 228 |
register: lookup_missing |
| 229 |
- ansible.builtin.assert: |
| 230 |
that: |
| 231 |
- lookup_missing is failed |
| 232 |
|
| 233 |
- name: Explicitly lookup two keys - one missing (skip) |
| 234 |
ansible.builtin.set_fact: |
| 235 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name, missing_name, on_missing=skip, wantlist=True, **connection_args) }}" |
| 236 |
- ansible.builtin.assert: |
| 237 |
that: |
| 238 |
- lookup_value | list | length == 2 |
| 239 |
- lookup_value[0] == updated_value |
| 240 |
- lookup_value[1] is none |
| 241 |
|
| 242 |
### |
| 243 |
|
| 244 |
- name: Explicitly lookup two paths - one missing |
| 245 |
ansible.builtin.set_fact: |
| 246 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', path_name, missing_name, bypath=True, wantlist=True, **connection_args) }}" |
| 247 |
ignore_errors: true |
| 248 |
register: lookup_missing |
| 249 |
- ansible.builtin.assert: |
| 250 |
that: |
| 251 |
- lookup_missing is failed |
| 252 |
|
| 253 |
- name: Explicitly lookup two paths - one missing (skip) |
| 254 |
ansible.builtin.set_fact: |
| 255 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', path_name, missing_name, on_missing=skip, bypath=True, wantlist=True, **connection_args) }}" |
| 256 |
- ansible.builtin.assert: |
| 257 |
that: |
| 258 |
- lookup_value | list | length == 2 |
| 259 |
- lookup_value[1] == {} |
| 260 |
- path_name_a in lookup_value[0] |
| 261 |
- lookup_value[0][path_name_a] == path_value_a |
| 262 |
- path_name_b in lookup_value[0] |
| 263 |
- lookup_value[0][path_name_b] == path_value_b |
| 264 |
- lookup_value[0] | length == 2 |
| 265 |
|
| 266 |
### |
| 267 |
|
| 268 |
- name: Explicitly lookup two paths with recurse - one missing |
| 269 |
ansible.builtin.set_fact: |
| 270 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', path_name, missing_name, bypath=True, recursive=True, wantlist=True, **connection_args) }}" |
| 271 |
ignore_errors: true |
| 272 |
register: lookup_missing |
| 273 |
- ansible.builtin.assert: |
| 274 |
that: |
| 275 |
- lookup_missing is failed |
| 276 |
|
| 277 |
- name: Explicitly lookup two paths with recurse - one missing (skip) |
| 278 |
ansible.builtin.set_fact: |
| 279 |
lookup_value: "{{ lookup('amazon.aws.aws_ssm', path_name, missing_name, on_missing=skip, bypath=True, recursive=True, wantlist=True, **connection_args) }}" |
| 280 |
- ansible.builtin.assert: |
| 281 |
that: |
| 282 |
- lookup_value | list | length == 2 |
| 283 |
- lookup_value[1] == {} |
| 284 |
- path_name_a in lookup_value[0] |
| 285 |
- lookup_value[0][path_name_a] == path_value_a |
| 286 |
- path_name_b in lookup_value[0] |
| 287 |
- lookup_value[0][path_name_b] == path_value_b |
| 288 |
- path_name_c in lookup_value[0] |
| 289 |
- lookup_value[0][path_name_c] == path_value_c |
| 290 |
- path_name_d in lookup_value[0] |
| 291 |
- lookup_value[0][path_name_d] == path_value_d |
| 292 |
- lookup_value[0] | length == 4 |
| 293 |
|
| 294 |
always: |
| 295 |
# ============================================================ |
| 296 |
- name: Delete remaining key/value pairs in aws parameter store |
| 297 |
community.aws.ssm_parameter: |
| 298 |
name: "{{ item }}" |
| 299 |
state: absent |
| 300 |
ignore_errors: true |
| 301 |
with_items: |
| 302 |
- "{{ path_name_c }}" |
| 303 |
- "{{ path_name_b }}" |
| 304 |
- "{{ path_name_c }}" |
| 305 |
- "{{ path_name }}" |
| 306 |
- "{{ simple_name }}" |