gpt4 book ai didi

macos - Ansible 要求安装 MySQL-python,尽管它已经安装

转载 作者:行者123 更新时间:2023-12-04 17:24:18 24 4
gpt4 key购买 nike

我正在尝试使用在 Mac OSX 上运行的 Ansible Controller 创建一个新的 MySQL 数据库。当我第一次得到 msg: the python mysqldb module is required错误消息,我添加了一个任务来安装 MySQL-pythonpip .它已正确安装,但我仍然收到 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显示包已正确安装。

我正在运行 Python 2.7.10 和 Ansible 1.9.4 都安装了 homebrew ,因此我不使用 sudo .

什么不见​​了?

  • 我对照 ubuntu/trusty64 检查了剧本流浪机器,它与 一起工作没问题 (OSX 是 Ansible Controller ,唯一的区别是在 sudo 模块中需要 pip)。
  • 我在第二台 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 运行时,结果中可见。选项。

    第一个任务成功了,因为默认 OSX 的 Python 调用 Homebrew 的 pip可执行并安装MySQL-python Homebrew 的 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到库存文件。

    同样的问题是 mentioned ,它包含其他可能解决方案的答案。

    关于macos - Ansible 要求安装 MySQL-python,尽管它已经安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33458889/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com