我正在尝试使用ansible-playbook从docker容器到Ubuntu AWS EC2实例(主机名myubuntu)。我有ssh密钥,允许我以ubuntu用户的身份ssh到我的ubuntu上,像这样:
bash-5.1# ssh -i my-key-file.pem ubuntu@myubuntu
...
ubuntu@ip-XX-XX-XX-XX:~$ exit
但是当我尝试运行一个非常简单可见的剧本时,像这样:
bash-5.1# ansible-playbook -i inventories/dev-eu-central-1.yaml --private-key muy-key-file.pem
--become-user ubuntu playbooks/hello-world.yaml
我得到这样的输出:
PLAY [Hello World] ************************************************************************************************
TASK [Gathering Facts] ************************************************************************************************fatal: [ec2-XX-XX-XX-XX.eu-central-1.compute.amazonaws.com]: 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 Please login as the user "ubuntu" rather than the user "root"./.ansible/tmp `"&&
mkdir "` echo Please login as the user "ubuntu" rather than the user "root"./.ansible/tmp/ansible-tmp-1614280818.9033527-8950-254411587258517 `" &&
echo ansible-tmp-1614280818.9033527-8950-254411587258517="` echo Please login as the user "ubuntu" rather than the user "root"./.ansible/tmp/ansible-tmp-1614280818.9033527-8950-254411587258517 `" )
PLAY RECAP ************************************************************************************************
ec2-XX-XX-XX-XX.eu-central-1.compute.amazonaws.com : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
我做错了什么?我以为把--become-user ubuntu
指定到ansible-playbook就能解决这个问题了。ansible-playbook。我怀疑我不是唯一一个尝试过这样做的人,所以我希望so能帮助我。
--become-user
在 Ansible成功连接远程系统后生效。您需要更改Ansible在初始连接时使用的用户id。
您可以在命令行上使用-u
选项(ansible-playbook -u ubuntu ...
)设置它,或者为您的目录中的目标主机设置ansible_user
变量。