Ansible no user $HOME by default - so how do I run commands
-
I have thousands of servers that, by default, for security and space do not create a
$HOME
when youssh
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 theansible.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/eekfonky/.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/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", "module_stdout": "Could not chdir to home directory /home/eekfonky: No such file or directory\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1 }
-
I assume that you are referring to https://docs.ansible.com/ansible/latest/cli/ansible-playbook.html#cmdoption-ansible-playbook-v similar like
TASK [Task] ***************************************************************************************************************** task path: taskFile: ... ESTABLISH ... CONNECTION FOR USER: {{ ansible_user }} EXEC /bin/sh -c 'echo ~{{ ansible_user }} && sleep 0' 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 https://docs.ansible.com/ansible/2.3/intro_configuration.html#local-tmp , it is possible to change that value. The configuration parameter 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
- https://devops.stackexchange.com/questions/10703/
it should be the variable https://docs.ansible.com/ansible/latest/collections/ansible/builtin/sh_shell.html#parameters .