Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions plugins/lookup/binary_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ def run(self, terms, variables=None, **kwargs):
continue
raise AnsibleLookupError(f"Could not locate file in community.general.binary_file lookup: {term}")

try:
with open(path, "rb") as f:
result.append(base64.b64encode(f.read()).decode("utf-8"))
except Exception as exc:
raise AnsibleLookupError(f"Error while reading {path}: {exc}")
result.append(base64.b64encode(self._loader._get_file_contents(path)[0]).decode("utf-8"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bcoca @sivel is DataLoader._get_file_contents() safe to use in collections, or is it considered private?

If it is considered private, how should collections interact with Vault-encrypted files?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I gathered on Matrix, it doesn't look like there's a public API for this. The only API there is decrypts the file to another file on disk, which is something we really want to avoid.

Also DataLoader._get_file_contents() doesn't set the SourceWasEncrypted tag (and the functionality to set it is definitely private), so I guess there's no way to properly achieve this right now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created ansible/ansible#85852 for this.


return result