Ansible 在 Windows 服务器上的 Playbook 失败

37次阅读
没有评论

问题描述

在运行 Ansible Playbook 时遇到了错误。他的 Playbook 是用于测试的基本 Playbook,目标主机是 Windows 服务器。以下是错误信息:

fatal: [WindowsServer1]: UNREACHABLE! => {"changed": false, "msg": "Failed to create temporary directory.In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \"/tmp\", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p \"` echo c\\temp `\"&& mkdir \"` echo c\\temp/ansible-tmp-1661983610.31-13-149784338894642 `\" && echo ansible-tmp-1661983610.31-13-149784338894642=\"` echo c\\temp/ansible-tmp-1661983610.31-13-149784338894642 `\" ), exited with result 1", "unreachable": true}

用户想知道为什么 Ansible 在 Windows 服务器上使用 Linux 命令。

解决方案

请注意以下操作注意版本差异及修改前做好备份。

方案1

根据用户的问题描述,Ansible 在 Windows 服务器上使用 Linux 命令的原因可能是由于 Ansible 的配置文件中的 remote_tmp 参数设置不正确。为了解决这个问题,可以尝试在主机文件中添加以下内容:

[windows:vars]
remote_tmp = C:\Users\ans_user\Tmp
become_method = runas
ansible_shell_type = powershell
shell_type = powershell

以上配置将指定 Ansible 在 Windows 服务器上使用 PowerShell 作为默认的 shell,并将 remote_tmp 参数设置为正确的 Windows 路径。

方案2

如果方案1无法解决问题,可以尝试修改 Ansible 的配置文件 ansible.cfg。在该文件中,可以将 remote_tmp 参数设置为以 "/tmp" 为根目录的路径,这样可以避免使用 Linux 命令。具体操作如下:
1. 打开 ansible.cfg 文件。
2. 找到 remote_tmp 参数,并将其值修改为以 "/tmp" 为根目录的路径,例如 "/tmp/ansible"
3. 保存并关闭文件。

请注意,修改配置文件可能会影响其他 Ansible 的行为,因此在修改之前请确保做好备份,并仔细阅读 Ansible 的官方文档以了解更多信息。

以上是解决 Ansible 在 Windows 服务器上使用 Linux 命令的两种方案。根据具体情况选择适合的方案进行尝试。

希望以上解决方案能帮助到你解决问题。如果还有其他疑问,请随时提问。

正文完