Can I modify Ansible 'remote_tmp' on a per task basis?
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.
As of 2.5, yes, changing remote_tmp
, which is an ansible_*
variable is something possible, by adding it to the vars
of the said task.
For example:
- tempfile:
state: file
suffix: temp
vars:
ansible_remote_tmp: /tmp/temp_file_1_task
Given a playbook with the two tasks:
- tempfile:
state: file
suffix: temp
vars:
ansible_remote_tmp: /tmp/temp_file_1_task
- tempfile:
state: file
suffix: temp
vars:
ansible_remote_tmp: /tmp/temp_file_2_task
A reduced version of the extra verbose log would yield:
<127.0.0.1> EXEC /bin/sh -c '/usr/local/bin/python /tmp/temp_file_1_task/ansible-tmp-1642453716.1902952-890-119314712082250/AnsiballZ_tempfile.py && sleep 0'
and
<127.0.0.1> EXEC /bin/sh -c '/usr/local/bin/python /tmp/temp_file_2_task/ansible-tmp-1642453716.6039782-905-172576654053914/AnsiballZ_tempfile.py && sleep 0'