问题
I need to install binary on remote servers. Following are the list of tasks that i am performing.
- Copy/scp binary to remote server
- Run the installer in silent mode
Step #1 is copying binaries to /tmp
, on remote hosts /tmp
has very less space and scp is failing once the /tmp
is full. I understood that by default ansible scripts/files will be copied to /tmp
directory, once the activity is done it will be removed. Since /tmp
is very low i need to use user directory to copy the binaries.
Below is ansible.cfg
:
remote_user = testaccount
host_key_checking = False
scp_if_ssh=True
remote_tmp = $HOME/.ansible/tmp
Below is the playbook:
- name: deploy binaries
hosts: test
strategy: free
become_method: 'sudo'
tasks:
- name: transfer
copy: src=./files/weblogic.jar dest=$HOME mode=0777
register: transfer
- debug: var=transfer.stdout
playbook execution:
ansible-playbook --inventory="hosts" --ask-pass --ask-become-pass --extra-vars="ansible_ssh_user=<unixaccount>" copybinaries.yml
Even with above config the binaries are not copied to user home, I have make sure to have $HOME/.ansible/tmp
directory and even hard coded like /home/testaccount/.ansbile/tmp
.
Any other configs needs to be overridden in ansible.cfg
?
回答1:
Although you still have not included a coherent MCVE, I guess:
either you are running the task with become-an-unprivileged-user option;
or your inventory file, configuration file, the execution call, and the playbook contain unnecessary and contradictory settings making Ansible run in a more or less nondeterministic way.
Ansible uses the system temp directory for tasks being run as a different user. This line determines this.
You can only specify /tmp
(default) or a subdirectory of /var/tmp
for such tasks (with remote_tmp
). See the comment in the Ansible code:
# When system is specified we have to create this in a directory where
# other users can read and access the temp directory. This is because
# we use system to create tmp dirs for unprivileged users who are
# sudo'ing to a second unprivileged user. The only dirctories where
# that is standard are the tmp dirs, /tmp and /var/tmp. So we only
# allow one of those two locations if system=True. However, users
# might want to have some say over which of /tmp or /var/tmp is used
# (because /tmp may be a tmpfs and want to conserve RAM or persist the
# tmp files beyond a reboot. So we check if the user set REMOTE_TMP
# to somewhere in or below /var/tmp and if so use /var/tmp. If
# anything else we use /tmp (because /tmp is specified by POSIX nad
# /var/tmp is not).
来源:https://stackoverflow.com/questions/42011478/remote-tmp-directory-not-set-for-ansible-script-execution