我正在尝试使用在Mac OSX上运行的Ansible控制器创建一个新的MySQL数据库.当我第一次收到msg: the python mysqldb module is required错误消息时,我添加了一个任务,该任务将MySQL-python与pip一起安装.它已正确安装,但是仍然无法从Ansible中获取错误,要求其安装.
我最小的剧本是:
- 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我得到以下结果(对于第一次运行的第一个任务,使用changed表示):
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 requiredpip show MySQL-python显示软件包已正确安装.
我正在运行都安装了homebrew的Python 2.7.10和Ansible 1.9.4,因此我不使用sudo.
缺少什么?
-
我在ubuntu/trusty64 Vagrant机器上检查了剧本,并且没问题正常工作(OSX是Ansible控制器,唯一的区别是
模块). -
我在第二台Mac上都使用-c local在本地检查了该剧本,并通过SSH对其进行了远程检查,并得到与原始问题相同的错误(为了使pip通过SSH正常工作我必须添加executalbe=/usr/local/Cellar/python/2.7.10_2/bin/pip,否则报告为msg: Failed to find required executable pip)
使用-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选项运行时,结果中可见. /p>
第一个任务成功是因为默认的OSX的Python调用了Homebrew的pip可执行文件,并为Homebrew的Python安装了MySQL-python模块.
第二个任务失败,因为它再次运行默认的OSX的Python,这需要MySQL-python,但未为此版本安装该模块.
解决方案是使用该选项指定Ansible使用的Python解释器的路径:
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添加到清单文件.
提到了相同的问题,其中包含其他可能的解决方案的答案.
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.
My minimal playbook is:
- 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: presentwhen I run the playbook with:
ansible-playbook -i "localhost," -c local mysql-test.ymlI 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 requiredpip show MySQL-python shows the package got installed correctly.
I am running Python 2.7.10 and Ansible 1.9.4 both installed with homebrew, thus I don't use sudo.
What is missing?
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 for sudo in pip module).
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)
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解决方案
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.
First task succeeded because default OSX's Python called Homebrew's pip executable and installed the MySQL-python module for the Homebrew's 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.
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.ymlor 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
发布评论