让 Ansible 与 Boot2Docker 一起工作的问题
Issues getting Ansible to work with Boot2Docker
我正在使用 Ansible 剧本来管理 Docker 容器的安装。我有以下安装 Cassandra 的剧本:
我想 运行 在本地安装此 playbook,并将其安装到 Boot2Docker。我可以使用 this answer 中的说明通过 SSH 进入 Boot2Docker:
$ ssh -i $HOME/.ssh/id_boot2docker -p 2022 docker@localhost
## .
## ## ## ==
## ## ## ## ===
/""""""""""""""""\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\______/
_ _ ____ _ _
| |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 1.4.1, build master : 86f7ec8 - Tue Dec 16 23:11:29 UTC 2014
Docker version 1.4.1, build 5bc2ff8
docker@boot2docker:~$
我用相同的 SSH 设置创建了一个清单文件:
[local]
localhost ansible_ssh_port=2022 ansible_ssh_user=docker ansible_ssh_private_key_file=~/.ssh/id_boot2docker
但是当我 运行 剧本时,它失败并显示错误“/bin/sh: /usr/bin/python: not found
”:
$ ansible-playbook db-setup.yml -i hosts.local
PLAY [local] ******************************************************************
GATHERING FACTS ***************************************************************
failed: [localhost] => {"failed": true, "parsed": false}
/bin/sh: /usr/bin/python: not found
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 102: Applying options for *
debug1: auto-mux: Trying existing master
debug1: mux_client_request_session: master session id: 2
Shared connection to localhost closed.
TASK: [Database] **************************************************************
FATAL: no hosts matched or all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/Users/bryan/db-setup.retry
localhost : ok=0 changed=0 unreachable=0 failed=1
即使 "gather facts" 关闭,我仍然会收到错误消息。如果我通过 SSH 进入 Boot2Docker,我可以看到 /usr/bin/python
存在:
$ ssh -i $HOME/.ssh/id_boot2docker -p 2022 docker@localhost
...
docker@boot2docker:~$ which python
解决方案很简单:Python 默认情况下未由 Boot2Docker 安装。
要安装,运行
$ boot2docker ssh "wget http://www.tinycorelinux.net/6.x/x86/tcz/python.tcz && tce-load -i python.tcz && rm -f python.tcz"
我创建了一个脚本来自动执行此操作,请参阅
https://gist.github.com/bcattle/90e64fbe808b3409ec2f
boot2docker ssh "tce-load -w -i python.tcz"
也可以解决问题(你需要互联网 ;-))对于 docker 和 ansible 你将需要 "docker-py"
- 设置pip,登录boot2docker
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
pip install docker-py
同时添加到您的库存文件中:
dockerhost ansible_connection=ssh ansible_ssh_host=192.168.59.103 ansible_ssh_user=docker ansible_ssh_private_key_file=~/.ssh/id_boot2docker ansible_python_interpreter=/usr/local/bin/python
我正在使用 Ansible 剧本来管理 Docker 容器的安装。我有以下安装 Cassandra 的剧本:
我想 运行 在本地安装此 playbook,并将其安装到 Boot2Docker。我可以使用 this answer 中的说明通过 SSH 进入 Boot2Docker:
$ ssh -i $HOME/.ssh/id_boot2docker -p 2022 docker@localhost
## .
## ## ## ==
## ## ## ## ===
/""""""""""""""""\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\______/
_ _ ____ _ _
| |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 1.4.1, build master : 86f7ec8 - Tue Dec 16 23:11:29 UTC 2014
Docker version 1.4.1, build 5bc2ff8
docker@boot2docker:~$
我用相同的 SSH 设置创建了一个清单文件:
[local]
localhost ansible_ssh_port=2022 ansible_ssh_user=docker ansible_ssh_private_key_file=~/.ssh/id_boot2docker
但是当我 运行 剧本时,它失败并显示错误“/bin/sh: /usr/bin/python: not found
”:
$ ansible-playbook db-setup.yml -i hosts.local
PLAY [local] ******************************************************************
GATHERING FACTS ***************************************************************
failed: [localhost] => {"failed": true, "parsed": false}
/bin/sh: /usr/bin/python: not found
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 102: Applying options for *
debug1: auto-mux: Trying existing master
debug1: mux_client_request_session: master session id: 2
Shared connection to localhost closed.
TASK: [Database] **************************************************************
FATAL: no hosts matched or all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/Users/bryan/db-setup.retry
localhost : ok=0 changed=0 unreachable=0 failed=1
即使 "gather facts" 关闭,我仍然会收到错误消息。如果我通过 SSH 进入 Boot2Docker,我可以看到 /usr/bin/python
存在:
$ ssh -i $HOME/.ssh/id_boot2docker -p 2022 docker@localhost
...
docker@boot2docker:~$ which python
解决方案很简单:Python 默认情况下未由 Boot2Docker 安装。
要安装,运行
$ boot2docker ssh "wget http://www.tinycorelinux.net/6.x/x86/tcz/python.tcz && tce-load -i python.tcz && rm -f python.tcz"
我创建了一个脚本来自动执行此操作,请参阅 https://gist.github.com/bcattle/90e64fbe808b3409ec2f
boot2docker ssh "tce-load -w -i python.tcz"
也可以解决问题(你需要互联网 ;-))对于 docker 和 ansible 你将需要 "docker-py"
- 设置pip,登录boot2docker
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
pip install docker-py
同时添加到您的库存文件中:
dockerhost ansible_connection=ssh ansible_ssh_host=192.168.59.103 ansible_ssh_user=docker ansible_ssh_private_key_file=~/.ssh/id_boot2docker ansible_python_interpreter=/usr/local/bin/python