首页 文章

远程tmp目录未设置为ansible脚本执行

提问于
浏览
0

我需要在远程服务器上安装二进制文件 . 以下是我正在执行的任务列表 .

  • 将/二进制文件复制到远程服务器

  • 以静默方式运行安装程序

步骤#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 中需要覆盖任何其他配置?

1 回答

  • 0

    虽然你还没有包含一个连贯的MCVE,我猜:

    • 您正在使用become-an-unprivileged-user选项运行任务;

    • 或您的库存文件,配置文件,执行调用和剧本包含不必要和矛盾的设置,使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).
    

相关问题