Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/lookup_binary_file/tasks/main.yml

raw
1 ---
2 # Copyright (c) 2025, Felix Fontein <[email protected]>
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 - name: Read some files
7 ansible.builtin.set_fact:
8 file_1: >-
9 {{ query('community.general.binary_file', 'file_1') }}
10 empty: >-
11 {{ query('community.general.binary_file', 'does-not-exist', not_exist='empty') }}
12 empty_str: >-
13 {{ query('community.general.binary_file', 'does-not-exist', not_exist='empty_str') }}
14 multiple: >-
15 {{ query('community.general.binary_file', 'file_1', 'file_2') }}
16 multiple_empty: >-
17 {{ query('community.general.binary_file', 'file_1', 'does-not-exist', 'file_2', not_exist='empty') }}
18 multiple_empty_str: >-
19 {{ query('community.general.binary_file', 'file_1', 'does-not-exist', 'file_2', not_exist='empty_str') }}
20
21 - name: Check results
22 ansible.builtin.assert:
23 that:
24 - file_1 == ["file 1" | ansible.builtin.b64encode]
25 - empty == [""]
26 - empty_str == ["empty"]
27 - multiple == ["file 1" | ansible.builtin.b64encode, "file 2" | ansible.builtin.b64encode]
28 - multiple_empty == ["file 1" | ansible.builtin.b64encode, "", "file 2" | ansible.builtin.b64encode]
29 - multiple_empty_str == ["file 1" | ansible.builtin.b64encode, "empty", "file 2" | ansible.builtin.b64encode]
30
31 - name: Fail on non-existing file
32 ansible.builtin.debug:
33 msg: >-
34 {{ query('community.general.binary_file', 'does-not-exist') }}
35 ignore_errors: true
36 register: result
37
38 - name: Check results
39 ansible.builtin.assert:
40 that:
41 - result is failed
42 - >-
43 "Could not locate file in community.general.binary_file lookup: does-not-exist" in result.msg
44
45 - name: Fail on non-existing file after some existing ones
46 ansible.builtin.debug:
47 msg: >-
48 {{ query('community.general.binary_file', 'file_1', 'does-not-exist', 'file_2') }}
49 ignore_errors: true
50 register: result
51
52 - name: Check results
53 ansible.builtin.assert:
54 that:
55 - result is failed
56 - >-
57 "Could not locate file in community.general.binary_file lookup: does-not-exist" in result.msg