# Can I modify Ansible 'remote\_tmp' on a per task basis?

**URL:** <https://forum.ansible.com/t/can-i-modify-ansible-remote-tmp-on-a-per-task-basis/36217>\
**Category:** Ansible Project\
**Created:** [January 18, 2022, 12:06pm UTC](https://forum.ansible.com/t/can-i-modify-ansible-remote-tmp-on-a-per-task-basis/36217 "2022-01-18T12:06:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BOB\_BOB](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@BOB\_BOB](https://forum.ansible.com/u/BOB_BOB)\
**Post date:** [January 18, 2022, 12:06pm UTC](https://forum.ansible.com/t/can-i-modify-ansible-remote-tmp-on-a-per-task-basis/36217/1 "2022-01-18T12:06:10Z")

</div>

I am running some tasks with delegate\_to. When those tasks run, they use the same remote\_tmp directory setup from the _ansible.cfg_. However, due to permissions and directory size issues, I need to change the remote\_tmp directory for tasks that I am using delegate\_to for.

Example:

- name: Create Temp Dir

delegate\_to: localhost

file:

path: “{{ my\_temp\_dir }}”

state: directory

I am using Ansible 2.3.2.

---

<div class="post-metadata">

**Author:** ![Roberto\_J\_R\_Paz](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@Roberto\_J\_R\_Paz](https://forum.ansible.com/u/Roberto_J_R_Paz)\
**Post date:** [January 18, 2022, 5:04pm UTC](https://forum.ansible.com/t/can-i-modify-ansible-remote-tmp-on-a-per-task-basis/36217/2 "2022-01-18T17:04:01Z")

</div>

If you are using a variable like “my\_temp\_dir”, then you can overwrite it before each task using something like:

- set\_fact:  
my\_temp\_dir: “new\_value”

as a separated task.

However, if the variable is provided at runtime as an extra var, some additional considerations should be done regarding value precedence.

---

<div class="post-metadata">

**Author:** ![BOB\_BOB](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@BOB\_BOB](https://forum.ansible.com/u/BOB_BOB)\
**Post date:** [January 18, 2022, 5:21pm UTC](https://forum.ansible.com/t/can-i-modify-ansible-remote-tmp-on-a-per-task-basis/36217/3 "2022-01-18T17:21:52Z")

</div>

Roberto,

Sorry, I think worded this question wrong.  
Ansible’s ‘remote\_tmp’ directory that can be modified in the ‘ansible.cfg’  
is what I need to be able to modify on a per task basis…preferable within the task file.

I know it can be set per host in the host file with Ansible versions \>=2.4.  
Right now, I have to work with Ansible 2.3.2. I can’t find a variable or an environment variable  
to modify the ‘remote\_tmp’ dir at a task level.

So I would want something like this - which I haven’t found a way in 2.3.2 yet:

- name: Create Temp Dir

delegate\_to: localhost

file:

path: “{{ my\_temp\_dir }}”

state: directory  
vars:  
remote\_tmp: “{{ new\_remote\_tmp\_dir }}”

Thanks again!

If you are using a variable like “my\_temp\_dir”, then you can overwrite it before each task using something like:

- set\_fact:  
my\_temp\_dir: “new\_value”

as a separated task.

However, if the variable is provided at runtime as an extra var, some additional considerations should be done regarding value precedence.

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [January 19, 2022, 6:50pm UTC](https://forum.ansible.com/t/can-i-modify-ansible-remote-tmp-on-a-per-task-basis/36217/4 "2022-01-19T18:50:49Z")

</div>

You can, just need to set the var to ansible\_remote\_tmp, see the var entry for it [https://docs.ansible.com/ansible/latest/collections/ansible/builtin/sh\_shell.html#parameter-remote\_tmp](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/sh_shell.html#parameter-remote_tmp).
