knowledge/technology/tools/Ansible/modules/ansible.builtin.tempfile.md

35 lines
1.9 KiB
Markdown
Raw Permalink Normal View History

2023-12-04 10:02:23 +00:00
# ansible.builtin.tempfile
2024-01-17 08:44:04 +00:00
The `tempfile` module creates temporary files and directories.
2023-12-04 10:02:23 +00:00
## Parameter
| Parameter | Type | Default | Description |
| ---------- | --------------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
2024-01-17 08:44:04 +00:00
| **path** | path | - | Location where temporary file or directory should be created. If path is not specified, the default system temporary directory will be used. |
2023-12-04 10:02:23 +00:00
| **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
```