当用户主目录安装在 NFS 卷上时 Ansible 不起作用

Ansible doesn't work when user home directory mounted on NFS volume

情况是这样的。我有很多主机,我想通过 Ansible 维护它们。 logins/users/etc 等主机的基线配置由企业 IT 霸主控制,因此我只能更改与应用程序相关的内容,而不是一般主机设置。一些与应用程序相关的任务需要 运行ning 作为 'root' 或其他一些特权用户。

我在所有主机上都有无密码 sudo 访问权限,但是所有用户主目录都位于 NFS 挂载卷上。根据我的理解,ansible 是如何工作的,它首先以普通用户身份登录到目标主机并将一些文件放入 $HOME/.ansible 目录,然后它使用 sudo 切换到 root 用户并尝试 运行 来自那个的东西目录。

但问题来了。正如我上面提到的,主目录位于 NFS 卷上,因此在目标机器上的 ansible 进程成为根目录后,由于 NFS 限制,它无法再访问 $HOME/.ansible 目录。有没有办法告诉 ansible 将这些工作文件放在某些非 NFS 卷上的主目录之外。

Ansible 2.1 中引入的 ansible.cfg 配置文件有两个参数,允许指定目标和控制机器上临时目录的位置:

  • remote_tmp

    Ansible works by transferring modules to your remote machines, running them, and then cleaning up after itself. In some cases, you may not wish to use the default location and would like to change the path. You can do so by altering this setting:

    remote_tmp = ~/.ansible/tmp
    
  • local_tmp

    When Ansible gets ready to send a module to a remote machine it usually has to add a few things to the module: Some boilerplate code, the module’s parameters, and a few constants from the config file. This combination of things gets stored in a temporary file until ansible exits and cleans up after itself. 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:

    local_tmp = $HOME/.ansible/tmp