Ansible : "msg": "无法创建临时目录。在某些情况下.....致命:[本地主机]:无法访问!=>



我有一个简单的剧本,可以在Windows 10 WSL ubuntu中打印hello world 我调用:

ansible-playbook hello-world.yml -vvv

安西布尔.cfg:

[defaults]
remote_user = root
remote_tmp = /home/foo/projects/ansible_tmp

我收到错误:

foo@foo-LP:~/projects$ ansible-playbook hello-world.yml -vvv
ansible-playbook 2.9.9
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/foo/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/foo/.local/lib/python3.8/site-packages/ansible
executable location = /home/foo/.local/bin/ansible-playbook
python version = 3.8.2 (default, Apr 27 2020, 15:53:34) [GCC 9.3.0]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAYBOOK: hello-world.yml *******************************************************************************************************************************************************************************************************************
1 plays in hello-world.yml
PLAY [Echo] *********************************************************************************************************************************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************
task path: /home/foo/projects/hello-world.yml:1
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: foo
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/foo/projects/ansible_tmp `"&& mkdir /home/foo/projects/ansible_tmp/ansible-tmp-1592072036.299761-1251-15575474283021 && echo ansible-tmp-1592072036.299761-1251-15575474283021="` echo /home/foo/projects/ansible_tmp/ansible-tmp-1592072036.299761-1251-15575474283021 `" ) && sleep 0'
fatal: [localhost]: 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 /home/foo/projects/ansible_tmp `"&& mkdir /home/foo/projects/ansible_tmp/ansible-tmp-1592072036.299761-1251-15575474283021 && echo ansible-tmp-1592072036.299761-1251-15575474283021="` echo /home/foo/projects/ansible_tmp/ansible-tmp-1592072036.299761-1251-15575474283021 `" ), exited with result 1, stdout output: ansible-tmp-1592072036.299761-1251-15575474283021=/home/foo/projects/ansible_tmp/ansible-tmp-1592072036.299761-1251-15575474283021n",
"unreachable": true
}
PLAY RECAP **********************************************************************************************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0

这是ansible_tmp目录,您可以看到已创建文件:

foo@foo-LP:~/projects/ansible_tmp$ ls -l
total 0
drwx------ 1 foo foo 512 Jun 13 20:58 ansible-tmp-1592071117.4568608-1061-140750827389855
drwx------ 1 foo foo 512 Jun 13 21:04 ansible-tmp-1592071482.7000341-1178-197961143036553
drwx------ 1 foo foo 512 Jun 13 21:05 ansible-tmp-1592071559.571779-1200-194490972570368
drwx------ 1 foo foo 512 Jun 13 21:13 ansible-tmp-1592072036.299761-1251-15575474283021

你在 WSL1 和 Ubuntu 20.04 上吗?我也遇到了麻烦,摆弄了一整天。我只在本地主机上使用复制模块(在本地 a 复制到 b(时遇到这个问题。

这是GitHub的问题。 https://github.com/microsoft/WSL/issues/4898

它在快速构建 19603 中修复。贝塔频道是在 19042 年。稳定版(19041(的修复程序即将到来,但我们不知道日期。

那里有很多解决方法的想法包括一些补丁。我现在使用以下内容作为解决方法,因为它不会破坏睡眠。

mv /bin/sleep /bin/sleep~
ln -s /bin/busybox /bin/sleep

/存档:然后我偶然发现了这个: https://community.spiceworks.com/topic/2275812-ubuntu-wsl-ansible-permission-error-when-running-localhost-playbook

它接缝是因为 Glibc 和 WSL1 (https://discourse.ubuntu.com/t/ubuntu-20-04-and-wsl-1/15291( 存在问题。

您可以使用以下方法进行验证:

$ sleep 5
sleep: cannot read realtime clock: Invalid argument

"解决方法" ...

mv /usr/bin/sleep /usr/bin/sleep.dist
ln -s /bin/true /usr/bin/sleep

在第一个链接中说明对我有用。但这当然是次优的,因为睡眠对你来说基本上是无用的。

最新更新