Answers: <p>I assume that you are referring to <a href="https://docs.ansible.com/ansible/latest/cli/ansible-playbook.html#cmdoption-ansible-playbook-v" rel="nofollow noreferrer">verbose output</a> similar like</p>
  <pre><code>TASK [Task] *****************************************************************************************************************
  task path: taskFile:&lt;lineNumber&gt;
  ...
  &lt;IP&gt; ESTABLISH ... CONNECTION FOR USER: {{ ansible_user }}
  &lt;IP&gt; EXEC /bin/sh -c 'echo ~{{ ansible_user }} &amp;&amp; sleep 0'
  &lt;IP&gt; EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p &quot;` echo /home/{{ ansible_user }}/.ansible/tmp `&quot;&amp;&amp; mkdir &quot;` echo /home/{{ ansible_user }}/.ansible/tmp/ansible-tmp-1234567890 `&quot; &amp;&amp; echo ansible-tmp-1234567890=&quot;` echo /home/{{ ansible_user }}/.ansible/tmp/ansible-tmp-1234567890 `&quot; ) &amp;&amp; sleep 0'
  Using module file /usr/lib/python2.7/site-packages/ansible/modules/files/find.py
  ...
  </code></pre>
  <blockquote>
  <p><em>Can I get Ansible to use another directory ...</em></p>
  </blockquote>
  <p>According an <a href="https://docs.ansible.com/ansible/2.3/intro_configuration.html#local-tmp" rel="nofollow noreferrer">older documentation (v2.3)</a>, it is possible to change that value. The configuration parameter <a href="https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-local-tmp" rel="nofollow noreferrer"><code>local_tmp</code></a> might still be available in latest version.</p>
  <blockquote>
  <p><em>When Ansible gets ready to send a module to a remote machine ... The default location is a subdirectory of the user’s home directory. If you’d like to change that, you can do so by altering this setting</em></p>
  </blockquote>
  <p>According</p>
  <p><strong>Further Q&amp;A</strong></p>
  <ul>
  <li><a href="https://devops.stackexchange.com/questions/10703/">Ansible temp dir change</a></li>
  </ul>
  <p>it should be the variable <a href="https://docs.ansible.com/ansible/latest/collections/ansible/builtin/sh_shell.html#parameters" rel="nofollow noreferrer"><code>remote_tmp</code></a>.</p>
  
Answers: CC BY-SA 4.0
Answers: 2022-03-25T10:26:28.487Z
Answers: samer error shows with /tmp changed. It appaers to be due to no $HOME, which is expected as there isn't one. I need to be able to state the directory on SSH connection in Ansible
Answers: eekfonky
Answers: CC BY-SA 4.0
Answers: 2022-03-25T10:32:30.010Z
Answers: @eekfonky, can you update your original question with your full `ansible.cfg`, as well the error message from verbose `-vvvv` output after re-running your playbook with `gather_facts: false`?
Answers: U880D
Answers: CC BY-SA 4.0
Answers: 2022-03-28T07:24:55.647Z
Answers: posted failure and .cfg
Answers: eekfonky
Answers: CC BY-SA 4.0
Answers: 2022-03-23T20:25:39.883Z
Answers: 2023-04-12T16:46:36.873Z
Answers: 2023-04-12T16:46:36.873Z
Answers: U880D
Body: <p>I have thousands of servers that, by default, for security and space do not create a <code>$HOME</code> when you <code>ssh</code> in.</p>
  <p>This seems to be posing a problem for Ansible as it keeps trying to <code>chdir to home</code> that does not exist. Can I get Ansible to use another directory in the <code>ansible.cfg</code> or just stop this behaviour completely?</p>
  <p><code>ansible.cfg</code></p>
  <pre><code>[defaults]
  
  inventory      = /home/welshch/.ansible/hosts
  remote_tmp     = /tmp
  local_tmp      = ~/.ansible/tmp
  interpreter_python = auto_silent
  roles_path    = /home/eekfonky/.ansible/roles
  host_key_checking = False
  </code></pre>
  <p>Here is the error with the server name changed for security reasons;</p>
  <pre><code>☁  .ansible  ansible-playbook get_fleet_info.yml -vvvv
  fatal: [ldap-corp-search-server.com]: FAILED! =&gt; {
      &quot;ansible_facts&quot;: {
          &quot;discovered_interpreter_python&quot;: &quot;/usr/bin/python&quot;
      },
      &quot;changed&quot;: false,
      &quot;module_stderr&quot;: &quot;OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017\r\ndebug1: Reading configuration data /home/eekfonky/.ssh/config\r\ndebug1: /home/eekfonky/.ssh/config line 2: Applying options for *\r\ndebug3: /home/eekfonky/.ssh/config line 9: Including file /home/eekfonky/.ssh/bastions-config depth 0\r\ndebug1: Reading configuration data /home/eekfonky/.ssh/bastions-config\r\ndebug1: /home/eekfonky/.ssh/bastions-config line 10: Applying options for *.corp.amazon.com\r\ndebug1: /home/ekfonky/.ssh/bastions-config line 35: Applying options for *.pdx*.server.com\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 58: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 27395\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\nShared connection to ldap-corp-search-server.com closed.\r\n&quot;,
      &quot;module_stdout&quot;: &quot;Could not chdir to home directory /home/eekfonky: No such file or directory\r\n&quot;,
      &quot;msg&quot;: &quot;MODULE FAILURE\nSee stdout/stderr for the exact error&quot;,
      &quot;rc&quot;: 1
  }
  </code></pre>
  
Comments: CC BY-SA 4.0
Comments: 2022-03-23T18:12:34.373Z
Comments: can you post an actual error message from Ansible? It's unclear from your question as stated where the problem may lie.
Comments: Bruce Becker
Tags: <ansible><ssh>
Title: Ansible no user $HOME by default - so how do I run commands
UserDisplayName: eekfonky
ThreadText: # Ansible no user $HOME by default - so how do I run commands
  
  (Asked by: username_0 on 2022-03-23)
  
  I have thousands of servers that, by default, for security and space do not create a `$HOME` when you `ssh` in.
  
  This seems to be posing a problem for Ansible as it keeps trying to `chdir to home` that does not exist. Can I get Ansible to use another directory in the `ansible.cfg` or just stop this behaviour completely?
  
  `ansible.cfg`
  
  ```
  [defaults]
  
  inventory      = /home/welshch/.ansible/hosts
  remote_tmp     = /tmp
  local_tmp      = ~/.ansible/tmp
  interpreter_python = auto_silent
  roles_path    = /home/username_0/.ansible/roles
  host_key_checking = False
  
  ```
  
  Here is the error with the server name changed for security reasons;
  
  ```
  ☁  .ansible  ansible-playbook get_fleet_info.yml -vvvv
  fatal: [ldap-corp-search-server.com]: FAILED! => {
      "ansible_facts": {
          "discovered_interpreter_python": "/usr/bin/python"
      },
      "changed": false,
      "module_stderr": "OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017\r\ndebug1: Reading configuration data /home/username_0/.ssh/config\r\ndebug1: /home/username_0/.ssh/config line 2: Applying options for *\r\ndebug3: /home/username_0/.ssh/config line 9: Including file /home/username_0/.ssh/bastions-config depth 0\r\ndebug1: Reading configuration data /home/username_0/.ssh/bastions-config\r\ndebug1: /home/username_0/.ssh/bastions-config line 10: Applying options for *.corp.amazon.com\r\ndebug1: /home/ekfonky/.ssh/bastions-config line 35: Applying options for *.pdx*.server.com\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 58: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 27395\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\nShared connection to ldap-corp-search-server.com closed.\r\n",
      "module_stdout": "Could not chdir to home directory /home/username_0: No such file or directory\r\n",
      "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
      "rc": 1
  }
  
  ```
  
  **Tags:** ansible, ssh
  
  > **Comments:**
  > **username_1**: can you post an actual error message from Ansible? It's unclear from your question as stated where the problem may lie.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2022-03-23. Score: 2
  
  I assume that you are referring to [verbose output](https://docs.ansible.com/ansible/latest/cli/ansible-playbook.html#cmdoption-ansible-playbook-v) similar like
  
  ```
  TASK [Task] *****************************************************************************************************************
  task path: taskFile:<lineNumber>
  ...
  <IP> ESTABLISH ... CONNECTION FOR USER: {{ ansible_user }}
  <IP> EXEC /bin/sh -c 'echo ~{{ ansible_user }} && sleep 0'
  <IP> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/{{ ansible_user }}/.ansible/tmp `"&& mkdir "` echo /home/{{ ansible_user }}/.ansible/tmp/ansible-tmp-1234567890 `" && echo ansible-tmp-1234567890="` echo /home/{{ ansible_user }}/.ansible/tmp/ansible-tmp-1234567890 `" ) && sleep 0'
  Using module file /usr/lib/python2.7/site-packages/ansible/modules/files/find.py
  ...
  
  ```
  
  > *Can I get Ansible to use another directory ...*
  
  According an [older documentation (v2.3)](https://docs.ansible.com/ansible/2.3/intro_configuration.html#local-tmp), it is possible to change that value. The configuration parameter [`local_tmp`](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-local-tmp) might still be available in latest version.
  
  > *When Ansible gets ready to send a module to a remote machine ... The default location is a subdirectory of the user’s home directory. If you’d like to change that, you can do so by altering this setting*
  
  According
  
  **Further Q&A**
  
  * [Ansible temp dir change](https://devops.stackexchange.com/questions/10703/)
  
  it should be the variable [`remote_tmp`](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/sh_shell.html#parameters).
  
  > **Comments:**
  > **username_0**: samer error shows with /tmp changed. It appaers to be due to no $HOME, which is expected as there isn't one. I need to be able to state the directory on SSH connection in Ansible  
  > **username_2**: @username_0, can you update your original question with your full `ansible.cfg`, as well the error message from verbose `-vvvv` output after re-running your playbook with `gather_facts: false`?  
  > **username_0**: posted failure and .cfg  
  
  ---
  
  