Debian Codegraph @

ansible_collections/amazon/aws/tests/integration/targets/lookup_secretsmanager_secret/tasks/nested.yaml

raw
1 ---
2 - vars:
3 json_secret_name: "ansible-test-{{ tiny_prefix }}-secret-json"
4 json_secret_value: "{{ json_secret | to_json }}"
5 block:
6 - name: Create secret "{{ json_secret_name }}"
7 community.aws.secretsmanager_secret:
8 name: "{{ json_secret_name }}"
9 secret: "{{ json_secret_value }}"
10 state: present
11
12 - name: Validate nested secret value
13 ansible.builtin.assert:
14 that:
15 - lookup('amazon.aws.secretsmanager_secret', json_secret_name + '.resource_prefix', nested=True, **connection_args) == resource_prefix
16
17 - name: Read missing secret variable using 'on_missing==error'
18 ansible.builtin.set_fact:
19 missing_err_secret: "{{ lookup('amazon.aws.secretsmanager_secret', json_secret_name + '.missing_err_secret', nested=True, on_missing='error', **connection_args)
20 }}"
21 register: on_missing_error
22 ignore_errors: true
23
24 - name: Ensure the lookup raised an error
25 ansible.builtin.assert:
26 that:
27 - on_missing_error is failed
28 - '"Successfully retrieved secret but there exists no key missing_err_secret in the secret" in on_missing_error.msg'
29 - missing_err_secret is undefined
30
31 - name: Read missing secret variable using 'on_missing==error'
32 ansible.builtin.set_fact:
33 resource_prefix_child: "{{ lookup('amazon.aws.secretsmanager_secret', json_secret_name + '.resource_prefix.child', nested=True, on_missing='error', **connection_args)
34 }}"
35 register: nested_child
36 ignore_errors: true
37
38 - name: Ensure the lookup raised an error
39 ansible.builtin.assert:
40 that:
41 - nested_child is failed
42 - '"Successfully retrieved secret but there exists no key resource_prefix.child in the secret" in nested_child.msg'
43 - resource_prefix_child is undefined
44
45 - name: Read missing secret variable using 'on_missing==warn'
46 ansible.builtin.set_fact:
47 missing_wrn_secret: "{{ lookup('amazon.aws.secretsmanager_secret', json_secret_name + '.missing_wrn_secret', nested=True, on_missing='warn', **connection_args)
48 }}"
49
50 - name: Ensure that the variable has not been defined
51 ansible.builtin.assert:
52 that:
53 - missing_wrn_secret == []
54
55 always:
56 # delete secret created
57 - name: Delete secret '{{ json_secret_name }}'
58 community.aws.secretsmanager_secret:
59 name: "{{ json_secret_name }}"
60 state: absent
61 recovery_window: 0
62 ignore_errors: true