diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
commit | 8a754e0858d922e955e71b253c139e071ecec432 (patch) | |
tree | 527d16e74bfd1840c85efd675fdecad056c54107 /test/integration/targets/lookup_dict | |
parent | Initial commit. (diff) | |
download | ansible-core-8a754e0858d922e955e71b253c139e071ecec432.tar.xz ansible-core-8a754e0858d922e955e71b253c139e071ecec432.zip |
Adding upstream version 2.14.3.upstream/2.14.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/targets/lookup_dict')
-rw-r--r-- | test/integration/targets/lookup_dict/aliases | 1 | ||||
-rw-r--r-- | test/integration/targets/lookup_dict/tasks/main.yml | 56 |
2 files changed, 57 insertions, 0 deletions
diff --git a/test/integration/targets/lookup_dict/aliases b/test/integration/targets/lookup_dict/aliases new file mode 100644 index 0000000..b598321 --- /dev/null +++ b/test/integration/targets/lookup_dict/aliases @@ -0,0 +1 @@ +shippable/posix/group3 diff --git a/test/integration/targets/lookup_dict/tasks/main.yml b/test/integration/targets/lookup_dict/tasks/main.yml new file mode 100644 index 0000000..b132413 --- /dev/null +++ b/test/integration/targets/lookup_dict/tasks/main.yml @@ -0,0 +1,56 @@ +- name: Define users dict + set_fact: + users: + alice: + name: Alice + age: 21 + bob: + name: Bob + age: 22 + +- name: Convert users dict to list + set_fact: + user_list: "{{ lookup('dict', users) | sort(attribute='key') }}" + +- name: Verify results + assert: + that: + - user_list | length == 2 + - user_list[0].key == 'alice' + - user_list[0].value | length == 2 + - user_list[0].value.name == 'Alice' + - user_list[0].value.age == 21 + - user_list[1].key == 'bob' + - user_list[1].value | length == 2 + - user_list[1].value.name == 'Bob' + - user_list[1].value.age == 22 + +- name: Convert a non-dict (failure expected) + set_fact: + bad_fact: "{{ bbbbad }}" + vars: + bbbbad: "{{ lookup('dict', 1) }}" + register: result + ignore_errors: yes + +- name: Verify conversion failed + assert: + that: + - result is failed + +- name: Define simple dict + set_fact: + simple: + hello: World + +- name: Convert using with_dict to cause terms to not be a list + set_fact: + hello: "{{ item }}" + with_dict: "{{ simple }}" + +- name: Verify conversion + assert: + that: + - hello | length == 2 + - hello.key == 'hello' + - hello.value == 'World' |