knowledge/technology/tools/Ansible/modules/ansible.builtin.tempfile.md
2023-12-04 11:02:23 +01:00

35 lines
No EOL
1.9 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ansible.builtin.tempfile
The `tempfile` module creates temporary files and directories.
## Parameter
| Parameter | Type | Default | Description |
| ---------- | --------------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| **path** | path | - | Location where temporary file or directory should be created.  If path is not specified, the default system temporary directory will be used. |
| **prefix** | string | "ansible." | Prefix of file/directory name created by module. |
| **state** | "directory"<br>"file" | "file" | Whether to create file or directory. |
| **suffix** | string | "" | Suffix of file/directory name created by module. |
## Return Values
| Value | Type | When | Description |
| -------- | ------ | ------- | ---------------------------------- |
| **path** | string | success | Path to created file or directory. |
## Examples
```yaml
- name: Create temporary build directory
ansible.builtin.tempfile:
state: directory
suffix: build
- name: Create temporary file
ansible.builtin.tempfile:
state: file
suffix: temp
register: tempfile_1
- name: Use the registered var and the file module to remove the temporary file
ansible.builtin.file:
path: "{{ tempfile_1.path }}"
state: absent
when: tempfile_1.path is defined
```