Add binary_file lookup (#10616)

* Add binary_file lookup.

* Remove sentence on deprecation.
This commit is contained in:
Felix Fontein 2025-08-10 13:32:35 +02:00 committed by GitHub
commit 8960a57d53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 187 additions and 0 deletions

View file

@ -0,0 +1,5 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
azp/posix/2

View file

@ -0,0 +1 @@
file 1

View file

@ -0,0 +1,3 @@
Copyright (c) 2025, Felix Fontein <felix@fontein.de>
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
SPDX-License-Identifier: GPL-3.0-or-later

View file

@ -0,0 +1 @@
file 2

View file

@ -0,0 +1,3 @@
Copyright (c) 2025, Felix Fontein <felix@fontein.de>
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
SPDX-License-Identifier: GPL-3.0-or-later

View file

@ -0,0 +1,57 @@
---
# Copyright (c) 2025, Felix Fontein <felix@fontein.de>
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Read some files
ansible.builtin.set_fact:
file_1: >-
{{ query('community.general.binary_file', 'file_1') }}
empty: >-
{{ query('community.general.binary_file', 'does-not-exist', not_exist='empty') }}
empty_str: >-
{{ query('community.general.binary_file', 'does-not-exist', not_exist='empty_str') }}
multiple: >-
{{ query('community.general.binary_file', 'file_1', 'file_2') }}
multiple_empty: >-
{{ query('community.general.binary_file', 'file_1', 'does-not-exist', 'file_2', not_exist='empty') }}
multiple_empty_str: >-
{{ query('community.general.binary_file', 'file_1', 'does-not-exist', 'file_2', not_exist='empty_str') }}
- name: Check results
ansible.builtin.assert:
that:
- file_1 == ["file 1" | ansible.builtin.b64encode]
- empty == [""]
- empty_str == ["empty"]
- multiple == ["file 1" | ansible.builtin.b64encode, "file 2" | ansible.builtin.b64encode]
- multiple_empty == ["file 1" | ansible.builtin.b64encode, "", "file 2" | ansible.builtin.b64encode]
- multiple_empty_str == ["file 1" | ansible.builtin.b64encode, "empty", "file 2" | ansible.builtin.b64encode]
- name: Fail on non-existing file
ansible.builtin.debug:
msg: >-
{{ query('community.general.binary_file', 'does-not-exist') }}
ignore_errors: true
register: result
- name: Check results
ansible.builtin.assert:
that:
- result is failed
- >-
"Could not locate file in community.general.binary_file lookup: does-not-exist" in result.msg
- name: Fail on non-existing file after some existing ones
ansible.builtin.debug:
msg: >-
{{ query('community.general.binary_file', 'file_1', 'does-not-exist', 'file_2') }}
ignore_errors: true
register: result
- name: Check results
ansible.builtin.assert:
that:
- result is failed
- >-
"Could not locate file in community.general.binary_file lookup: does-not-exist" in result.msg