![](/img/trans.png)
[英]Error running docker-compose command via Ansible playbook
[英]Issue with running ansible playbook on docker containers on MAC
我啟動了 3 個 ubuntu 容器來練習 ansible playbook。 就像在 docker for MAC 中一樣,我不能直接在容器 ip 上使用 ssh,必須通過端口轉發路由遵循這個問題
docker run -d -p 2024:22 dockerReg/ubuntu-ssh-enabled
docker run -d -p 2023:22 dockerReg/ubuntu-ssh-enabled
docker run -d -p 2022:22 dockerReg/ubuntu-ssh-enabled
我當前的庫存文件如下所示
MacBook-Pro:~$ cat inventory.txt
target1 ansible_host=172.17.0.2 ansible_ssh_pass=Passw0rd
target2 ansible_host=172.17.0.3 ansible_ssh_pass=Passw0rd
target3 ansible_host=172.17.0.4 ansible_ssh_pass=Passw0rd
我現在需要運行什么命令才能在我的清單文件中的所有目標上運行 ping 模塊。 當然這行不通: ansible target* -m ping -i inventory.txt
解決此問題的最佳方法是什么,或者是否有任何簡單的解決方法?
如果您正在啟動 docker 容器,為什么不使用docker
連接插件? 我從未使用過任何 machintosh,所以我可能會錯過一些東西,但我不明白為什么它不會按預期工作,只要您可以使用“正常”docker 命令與您的容器進行交互。
快速 POC 助您一臂之力。
inventories/docker-poc.yml
---
all:
children:
my_poc_hosts:
vars:
ansible_connection: docker
hosts:
target1:
target2:
target3:
如果你想保留 ini 格式,這是等效的:
[my_poc_hosts]
target1
target2
target3
[my_poc_hosts:vars]
ansible_connection=docker
我使用了 python:3.8 圖像(以確保安裝了 python,因為它是 ansible 必需的)和一個長時間運行的自定義命令。
for i in {1..3} ; do docker run -d --rm --name target$i python:3.8 sh -c "while true; do sleep 20000; done"; done
$ ansible -i inventories/docker-poc.yml my_poc_hosts -m ping
[WARNING]: Platform linux on host target1 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
target1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
[WARNING]: Platform linux on host target3 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
target3 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
[WARNING]: Platform linux on host target2 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
target2 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
for i in {1..3}; do docker rm -f target$i; done
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.