我需要在远程服务器上安装二进制文件。以下是我正在执行的任务列表。
步骤#1将二进制文件复制到/tmp
,远程主机/tmp
上的空间非常少,而/tmp
填满后scp失败。据我所知,默认情况下,ansible脚本/文件将被复制到/tmp
目录,一旦活动完成,它将被删除。由于/tmp
非常低,我需要使用用户目录来复制二进制文件。
以下是ansible.cfg
:
remote_user = testaccount
host_key_checking = False
scp_if_ssh=True
remote_tmp = $HOME/.ansible/tmp
以下是剧本:
- 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
剧本执行:
ansible-playbook --inventory="hosts" --ask-pass --ask-become-pass --extra-vars="ansible_ssh_user=<unixaccount>" copybinaries.yml
即使使用上面的配置,二进制文件也不会复制到用户主页,我确保拥有$HOME/.ansible/tmp
目录,甚至硬编码为/home/testaccount/.ansbile/tmp
。
需要在ansible.cfg
?
答案 0 :(得分:0)
虽然你还没有包含一个连贯的MCVE,但我想:
您正在使用“成为非特权用户”选项运行任务;
或您的库存文件,配置文件,执行调用和剧本包含不必要且相互矛盾的设置,使Ansible以或多或少的不确定性方式运行。
Ansible使用系统临时目录来执行作为其他用户运行的任务。 This line确定了这一点。
您只能为此类任务指定/tmp
(默认)或/var/tmp
的子目录(使用remote_tmp
)。请参阅Ansible代码中的the comment:
# 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).