Can I modify Ansible 'remote_tmp' on a per task basis?

719 views
Skip to first unread message

BOB BOB

unread,
Jan 18, 2022, 9:30:13 AM1/18/22
to Ansible Project

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.

Thanks for any help!

BOB BOB

unread,
Jan 18, 2022, 9:30:14 AM1/18/22
to Ansible Project

Roberto Paz

unread,
Jan 18, 2022, 12:04:01 PM1/18/22
to Ansible Project
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.

Christopher McDaniel

unread,
Jan 18, 2022, 12:26:51 PM1/18/22
to Ansible Project
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!




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/4c5c6654-e726-43cb-90a2-35ff1edbd2d4n%40googlegroups.com
.

jbor...@gmail.com

unread,
Jan 19, 2022, 1:50:49 PM1/19/22
to Ansible Project
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.
Reply all
Reply to author
Forward
0 new messages