Answers: <p>I understood with the help of the documentation above how to replace environment variables.</p>
  
  <p>For example:</p>
  
  <pre><code>- hosts: hostnames
    remote_user: root
    gather_facts: no
    vars:
      ansible_remote_tmp: /tmp
    tasks:
    ...
  </code></pre>
  
  <p>Also, it's possible to replace in the separate tasks.</p>
  
  <p><a href="https://docs.ansible.com/ansible/latest/user_guide/playbooks_environment.html" rel="nofollow noreferrer">Ansible documentation about playbook environment</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2020-05-26T17:41:23.373Z
Answers: 2020-05-26T17:41:23.373Z
Answers: Kirill Vakhrushev
Answers: <p>Q: <em><strong>&quot;Is it possible to change ansible temp dir for one playbook only? I have VMs with r/o root.&quot;</strong></em></p>
  <p>A: Yes. It's possible. Configure the variable <a href="https://docs.ansible.com/ansible/latest/plugins/shell/sh.html" rel="nofollow noreferrer">ansible_remote_tmp</a>.</p>
  <p>In some cases, a better solution to this problem is <a href="https://docs.ansible.com/ansible/latest/reference_appendices/config.html#ansible-pipelining" rel="nofollow noreferrer">ANSIBLE_PIPELINING</a>. Quoting from <a href="https://docs.ansible.com/ansible/latest/user_guide/become.html#risks-and-limitations-of-become" rel="nofollow noreferrer">Risks and limitations of become</a>:</p>
  <blockquote>
  <p>Use pipelining. When pipelining is enabled, Ansible does not save the module to a temporary file on the client. Instead, it pipes the module to the remote python interpreter’s stdin. Pipelining does not work for python modules involving file transfer (for example: copy, fetch, template), or for non-python modules.</p>
  </blockquote>
  <hr>
  Notes:
  <ul>
  <li>Quoting from <a href="https://github.com/ansible/ansible/blob/stable-2.5/changelogs/CHANGELOG-v2.5.rst#minor-changes-4" rel="nofollow noreferrer">Release notes</a>:</li>
  </ul>
  <blockquote>
  <p>The ANSIBLE_REMOTE_TMP environment variable has been added to supplement (and override) ANSIBLE_REMOTE_TEMP. This matches the spelling of the config value. ANSIBLE_REMOTE_TEMP will be deprecated in the future.</p>
  </blockquote>
  <ul>
  <li><p><code>remote_tmp</code> is not among configuration options in <a href="https://docs.ansible.com/ansible/latest/reference_appendices/config.html#ansible-configuration-settings" rel="nofollow noreferrer">Ansible Configuration Settings</a></p>
  </li>
  <li><p>See <a href="https://docs.ansible.com/ansible/latest/plugins/shell/sh.html#parameter-remote_tmp" rel="nofollow noreferrer"><code>remote_tmp</code></a> parameter of the <a href="https://docs.ansible.com/ansible/latest/plugins/shell/sh.html#sh-posix-shell-bin-sh" rel="nofollow noreferrer">sh</a> plugin.</p>
  </li>
  <li><p>See open <a href="https://github.com/ansible/ansible/issues?utf8=%E2%9C%93&amp;q=ANSIBLE_REMOTE_TMP+is%3Aopen" rel="nofollow noreferrer">bugs</a></p>
  </li>
  </ul>
  
Answers: CC BY-SA 4.0
Answers: 2020-02-04T15:52:55.497Z
Answers: 2023-07-12T15:43:31.610Z
Answers: 2023-07-12T15:43:31.610Z
Answers: Vladimir Botka
Body: <p>Ansible version 2.9.2</p>
  
  <p>Is it possible to change ansible temp dir for one playbook only?
  I have VMs with r/o root. So, the playbook fails.
  Even if I run my playbook under root user on target VM it can't create ansible temp files that it creates in current user's home dir on target VM.
  I know that I can change it in ansible.cfg file, but I need it only for one VM type.</p>
  
  <p>I need to make changes to other not r/o drives.</p>
  
Tags: <ansible>
Title: Ansible temp dir change
UserDisplayName: Kirill Vakhrushev
ThreadText: # Ansible temp dir change
  
  (Asked by: username_0 on 2020-02-04)
  
  Ansible version 2.9.2
  
  Is it possible to change ansible temp dir for one playbook only?
  I have VMs with r/o root. So, the playbook fails.
  Even if I run my playbook under root user on target VM it can't create ansible temp files that it creates in current user's home dir on target VM.
  I know that I can change it in ansible.cfg file, but I need it only for one VM type.
  
  I need to make changes to other not r/o drives.
  
  **Tags:** ansible
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2020-02-04. Score: 8 | Accepted answer
  
  Q: ***"Is it possible to change ansible temp dir for one playbook only? I have VMs with r/o root."***
  
  A: Yes. It's possible. Configure the variable [ansible\_remote\_tmp](https://docs.ansible.com/ansible/latest/plugins/shell/sh.html).
  
  In some cases, a better solution to this problem is [ANSIBLE\_PIPELINING](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#ansible-pipelining). Quoting from [Risks and limitations of become](https://docs.ansible.com/ansible/latest/user_guide/become.html#risks-and-limitations-of-become):
  
  > Use pipelining. When pipelining is enabled, Ansible does not save the module to a temporary file on the client. Instead, it pipes the module to the remote python interpreter’s stdin. Pipelining does not work for python modules involving file transfer (for example: copy, fetch, template), or for non-python modules.
  
  ---
  
  Notes:
  
  * Quoting from [Release notes](https://github.com/ansible/ansible/blob/stable-2.5/changelogs/CHANGELOG-v2.5.rst#minor-changes-4):
  
  > The ANSIBLE\_REMOTE\_TMP environment variable has been added to supplement (and override) ANSIBLE\_REMOTE\_TEMP. This matches the spelling of the config value. ANSIBLE\_REMOTE\_TEMP will be deprecated in the future.
  
  * `remote_tmp` is not among configuration options in [Ansible Configuration Settings](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#ansible-configuration-settings)
  * See [`remote_tmp`](https://docs.ansible.com/ansible/latest/plugins/shell/sh.html#parameter-remote_tmp) parameter of the [sh](https://docs.ansible.com/ansible/latest/plugins/shell/sh.html#sh-posix-shell-bin-sh) plugin.
  * See open [bugs](https://github.com/ansible/ansible/issues?utf8=%E2%9C%93&q=ANSIBLE_REMOTE_TMP+is%3Aopen)
  
  
  ---
  
  ### Answer by username_0 on 2020-05-26. Score: 3
  
  I understood with the help of the documentation above how to replace environment variables.
  
  For example:
  
  ```
  - hosts: hostnames
    remote_user: root
    gather_facts: no
    vars:
      ansible_remote_tmp: /tmp
    tasks:
    ...
  
  ```
  
  Also, it's possible to replace in the separate tasks.
  
  [Ansible documentation about playbook environment](https://docs.ansible.com/ansible/latest/user_guide/playbooks_environment.html)
  
  
  ---
  
  