[英]create an aws ec2 instance on centos 7 through ansible playbook
[英]How can I run ansible-playbook on docker container to execute commands on an AWS EC2 Ubuntu instance?
我正在嘗試使用從 docker 容器到 Ubuntu AWS EC2 實例(主機名 myubuntu)的 ansible-playbook。 我有 ssh 密鑰,允許我以 ubuntu 用戶的身份將 ssh 安裝到 myubuntu 上,如下所示:
bash-5.1# ssh -i my-key-file.pem ubuntu@myubuntu
...
ubuntu@ip-XX-XX-XX-XX:~$ exit
但是當我嘗試像這樣運行一個非常簡單的 anisble 劇本時:
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
我得到這個 output:
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成功連接遠程系統后生效。 您需要更改用於初始連接的用戶 ID Ansible。
您可以使用-u
選項( ansible-playbook -u ubuntu...
)在命令行上進行設置,或者為清單中的目標主機設置ansible_user
變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.