# 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
```