Ansible 要求安装 MySQL-python 尽管它已经安装 [英] Ansible demands installing MySQL-python despite it was already installed
问题描述
我正在尝试使用在 Mac OSX 上运行的 Ansible 控制器创建一个新的 MySQL 数据库.当我第一次收到 msg: the python mysqldb module is required
错误消息时,我添加了一个任务来安装 MySQL-python
和 pip
.它已正确安装,但我仍然收到 Ansible 要求安装的错误消息.
I am trying to create a new MySQL database with Ansible controller running on Mac OSX. When I first got msg: the python mysqldb module is required
error message, I added a task to install the MySQL-python
with pip
. It got installed correctly, however still I am still getting an error from Ansible demanding its installation.
我的最小剧本是:
- hosts: all
tasks:
- name: Ensure MySQL-python module is installed
pip:
name: MySQL-python
executalbe: /usr/local/Cellar/python/2.7.10_2/bin/pip
- name: Create test_db MySQL database
mysql_db:
name: test_db
state: present
当我运行剧本时:
ansible-playbook -i "localhost," -c local mysql-test.yml
我得到以下结果(第一次运行时第一个任务已更改
):
I get the following result (with changed
for the first task upon first run):
TASK: [Ensure MySQL-python module is installed] **************************************
ok: [localhost]
TASK: [Create test_db MySQL database] *********************************************
failed: [localhost] => {"failed": true}
msg: the python mysqldb module is required
pip show MySQL-python
显示安装正确.
我运行的 Python 2.7.10 和 Ansible 1.9.4 都安装了 homebrew
,因此我不使用 sudo
.
I am running Python 2.7.10 and Ansible 1.9.4 both installed with homebrew
, thus I don't use sudo
.
缺少什么?
我针对
ubuntu/trusty64
Vagrant 机器检查了剧本,它没问题(OSX 是 Ansible 控制器,唯一的区别是要求对于pip
模块中的sudo
).
I checked the playbook against
ubuntu/trusty64
Vagrant machine and it worked with no problem (with OSX being the Ansible controller, the only difference was a requirement forsudo
inpip
module).
我使用 -c local
在本地和通过 SSH 远程检查了第二台 Mac 上的剧本,并得到了与原始问题相同的错误(对于 pip
要通过 SSH 正常工作我必须添加 executalbe=/usr/local/Cellar/python/2.7.10_2/bin/pip
否则它报告 msg: Failed找到所需的可执行文件 pip
)
I checked the playbook on a second Mac both locally with -c local
and remotely via SSH and got the same error as in original question (for pip
to work correctly through SSH I had to add executalbe=/usr/local/Cellar/python/2.7.10_2/bin/pip
otherwise it reported msg: Failed to find required executable pip
)
使用-c local -vvvv
运行时任务的结果:
The results of the task when run with -c local -vvvv
:
<localhost> REMOTE_MODULE mysql_db name=test_db state=present
<localhost> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1446497958.1-90296161052037 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1446497958.1-90296161052037 && echo $HOME/.ansible/tmp/ansible-tmp-1446497958.1-90296161052037']
<localhost> PUT /var/folders/nw/2vnhg_gj77v_cyfv0p1vdfj80000gn/T/tmpK3DT_j TO /Users/techraf/.ansible/tmp/ansible-tmp-1446497958.1-90296161052037/mysql_db
<localhost> EXEC ['/bin/sh', '-c', u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /Users/techraf/.ansible/tmp/ansible-tmp-1446497958.1-90296161052037/mysql_db; rm -rf /Users/techraf/.ansible/tmp/ansible-tmp-1446497958.1-90296161052037/ >/dev/null 2>&1']
failed: [localhost] => {"failed": true}
msg: the python mysqldb module is required
推荐答案
问题的原因是 Ansible 使用了默认的 OSX 的 Python (/usr/bin/python
),它在使用 -vvvv
选项运行时的结果.
The reason for the problem was that Ansible used the default OSX's Python (/usr/bin/python
) which is visible in the results when run with -vvvv
option.
第一个任务成功了,因为默认 OSX 的 Python 称为 Homebrew 的 pip
可执行文件,并为 Homebrew 的 Python 安装了 MySQL-python
模块.
First task succeeded because default OSX's Python called Homebrew's pip
executable and installed the MySQL-python
module for the Homebrew's Python.
第二个任务失败,因为它再次运行默认的 OSX 的 Python,这需要 MySQL-python
,但该版本没有安装该模块.
The second task failed because it run default OSX's Python again which required MySQL-python
, but the module was not installed for this version.
解决方案是使用选项来指定 Ansible 使用的 Python 解释器的路径:
The solution was to use the option to specify the path to the Python interpreter to be used by Ansible:
ansible-playbook -i "localhost," -c local --extra-vars "ansible_python_interpreter=/usr/local/bin/python" mysql-test.yml
或将 ansible_python_interpreter=/usr/local/bin/python
添加到清单文件中.
or to add ansible_python_interpreter=/usr/local/bin/python
to the inventory file.
同样的问题被提到,它包含其他可能解决方案的答案.
The same problem was mentioned, it contains answers with other possible solutions.
这篇关于Ansible 要求安装 MySQL-python 尽管它已经安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!