Skip to main content

Modules modules

Downloads the binary file content stored on a CoreFileObject schema node. Identifies the node by UUID (node_id) or HFID (hfid). Optionally saves the file to a local destination path. Returns base64-encoded binary content and metadata regardless of I(dest).

Parameters

ParameterTypeRequiredDefaultDescription
api_endpointstrNoEndpoint of the Infrahub API, optional env=INFRAHUB_ADDRESS
tokenstrNoThe API token created through Infrahub, optional env=INFRAHUB_API_TOKEN
timeoutintNo10Timeout for Infrahub requests in seconds
validate_certsboolNoTrueWhether or not to validate SSL of the Infrahub instance
branchstrNomainBranch in which the request is made
kindstrYesSchema kind that inherits from CoreFileObject (e.g. C(NetworkCircuitContract))
node_idstrNoUUID of the CoreFileObject node to fetch. One of I(node_id) or I(hfid) is required.
hfidlistNoHuman-friendly ID component values for the CoreFileObject node. One of I(node_id) or I(hfid) is required.
deststrNoNoneLocal path to save the file content. When a directory path is given (trailing slash or existing directory), the file is saved as {dest}/{node.file_name}. When a file path is given, the file is saved exactly at that path. When omitted, file content is returned as variables only.

Examples

---
- name: Fetch contract PDF by node UUID
opsmill.infrahub.object_file_fetch:
kind: NetworkCircuitContract
node_id: "abc123-uuid"
register: fetch_result

- name: Write fetched file to disk
ansible.builtin.copy:
content: "{{ fetch_result.binary | b64decode }}"
dest: /tmp/contract.pdf

- name: Fetch and save to directory by HFID
opsmill.infrahub.object_file_fetch:
kind: NetworkCircuitContract
hfid:
- "contract.pdf"
dest: /tmp/contracts/
register: fetch_result
# File saved to /tmp/contracts/contract.pdf
# fetch_result.dest == "/tmp/contracts/contract.pdf"

- name: Fetch and save to explicit file path
opsmill.infrahub.object_file_fetch:
kind: NetworkCircuitContract
node_id: "abc123-uuid"
dest: /tmp/my-contract.pdf
register: fetch_result
# File saved to exactly /tmp/my-contract.pdf

Return values

KeyTypeDescription
binarystrBase64-encoded file content downloaded from the CoreFileObject node.
textstrUTF-8 decoded file content for text MIME types (text/plain, application/json, etc.). null for binary MIME types.
file_namestrOriginal filename as stored in Infrahub.
file_typestrMIME type of the file as detected by Infrahub.
file_sizeintSize of the file in bytes.
checksumstrSHA-1 hex digest of the file content as stored in Infrahub.
node_idstrUUID of the fetched CoreFileObject node.
deststrResolved local path where the file was saved. null if I(dest) was not provided.
msgstrStatus message.