Ansible要求安装MySQL

编程入门 行业动态 更新时间:2024-10-26 18:29:53
本文介绍了Ansible要求安装MySQL-python,尽管已经安装了它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用在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 required

pip 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: present

when I run the playbook with:

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 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.yml

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

本文发布于:2023-11-06 06:15:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562906.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Ansible   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!