gpt4 book ai didi

python - Ansible + Ubuntu 18.04 + MySQL = "The PyMySQL (Python 2.7 and Python 3.X) or MySQL-python (Python 2.X) module is required."

转载 作者:行者123 更新时间:2023-12-04 19:26:06 27 4
gpt4 key购买 nike

我在 Ubuntu 18.04 上使用 Ansible 2.8 的多个剧本上看到了上述消息。为简单起见,我使用此基本剧本为单节点 Drupal 服务器复制了它。 https://github.com/geerlingguy/ansible-for-devops/tree/master/drupal ;该剧本在 ubuntu 的早期版本上运行良好,但不适用于 18.04,我了解默认情况下包含 python3。

我已经使用 vagrant 创建了基础机器,它显示了以下内容:

$ which python
/usr/bin/python
$ which python2
/usr/bin/python2
$ which python3
/usr/bin/python3
$ python --version
Python 2.7.15rc1
$ python2 --version
Python 2.7.15rc1
$ python3 --version
Python 3.6.7

这似乎是在告诉我 python 2 和 python 3 都已安装,但 2.7 是默认值,因为这是对 $ python --version 的响应。

我已经尝试了本文中描述的所有建议: https://www.rollnorocks.com/2018/12/ansible-python-and-mysql-untangling-the-mess/
包括指定
ansible_python_interpreter=/usr/bin/python3

但没有任何影响消息。剧本运行的编辑 -vvv 输出如下。有没有人对问题或解决方案有更多的想法。
TASK [Remove the MySQL test database.] ****************************************************************************************************************************
task path: /vagrant/provisioning/playbook.yml:96
<10.1.1.11> ESTABLISH SSH CONNECTION FOR USER: mt-ansible-user
<10.1.1.11> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o
.
.
.
Using module file /usr/local/lib/python2.7/dist-packages/ansible/modules/database/mysql/mysql_db.py
<10.1.1.11> PUT /home/mt-tools-user/.ansible/tmp/ansible-local-21287bh5dK5/tmp7pOKOH TO /home/mt-ansible-user/.ansible/tmp/ansible-tmp-1558868136.49-16683638151793
1/AnsiballZ_mysql_db.py
<10.1.1.11> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/home/mt-tools-user/.ssh/mt_ansible_rsa"' -o KbdInteractiveAuthent
ication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="mt-ansible-user"' -o ConnectTimeout=
10 -o ControlPath=/home/mt-tools-user/.ansible/cp/af4de51057 '[10.1.1.11]'
<10.1.1.11> (0, 'sftp> put /home/mt-tools-user/.ansible/tmp/ansible-local-21287bh5dK5/tmp7pOKOH /home/mt-ansible-user/.ansible/tmp/ansible-tmp-1558868136.49-166836
381517931/AnsiballZ_mysql_db.py\n', '')
<10.1.1.11> ESTABLISH SSH CONNECTION FOR USER: mt-ansible-user
<10.1.1.11> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/home/mt-tools-user/.ssh/mt_ansible_rsa"' -o KbdInteractiveAuthenticatio
n=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="mt-ansible-user"' -o ConnectTimeout=10 -o
ControlPath=/home/mt-tools-user/.ansible/cp/af4de51057 10.1.1.11 '/bin/sh -c '"'"'chmod u+x /home/mt-ansible-user/.ansible/tmp/ansible-tmp-1558868136.49-1668363815
17931/ /home/mt-ansible-user/.ansible/tmp/ansible-tmp-1558868136.49-166836381517931/AnsiballZ_mysql_db.py && sleep 0'"'"''
<10.1.1.11> (0, '', '')
<10.1.1.11> ESTABLISH SSH CONNECTION FOR USER: mt-ansible-user
<10.1.1.11> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/home/mt-tools-user/.ssh/mt_ansible_rsa"' -o KbdInteractiveAuthenticatio
n=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="mt-ansible-user"' -o ConnectTimeout=10 -o
ControlPath=/home/mt-tools-user/.ansible/cp/af4de51057 -tt 10.1.1.11 '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-qwjewg
qckuyapsxnkbqoegainrkyiinc ; /usr/bin/python3 /home/mt-ansible-user/.ansible/tmp/ansible-tmp-1558868136.49-166836381517931/AnsiballZ_mysql_db.py'"'"'"'"'"'"'"'"' &
& sleep 0'"'"''
<10.1.1.11> (1, 'BECOME-SUCCESS-qwjewgqckuyapsxnkbqoegainrkyiinc\r\n\r\n{"msg": "The PyMySQL (Python 2.7 and Python 3.X) or MySQL-python (Python 2.X) module is req
uired.", "failed": true, "invocation": {"module_args": {"db": "test", "state": "absent", "name": "test", "login_host": "localhost", "login_port": 3306, "encoding":
"", "collation": "", "connect_timeout": 30, "config_file": "/root/.my.cnf", "single_transaction": false, "quick": true, "ignore_tables": [], "login_user": null, "
login_password": null, "login_unix_socket": null, "target": null, "client_cert": null, "client_key": null, "ca_cert": null}}}\r\n', 'Shared connection to 10.1.1.11
closed.\r\n')
<10.1.1.11> Failed to connect to the host via ssh: Shared connection to 10.1.1.11 closed.
<10.1.1.11> ESTABLISH SSH CONNECTION FOR USER: mt-ansible-user
<10.1.1.11> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/home/mt-tools-user/.ssh/mt_ansible_rsa"' -o KbdInteractiveAuthenticatio
n=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="mt-ansible-user"' -o ConnectTimeout=10 -o
ControlPath=/home/mt-tools-user/.ansible/cp/af4de51057 10.1.1.11 '/bin/sh -c '"'"'rm -f -r /home/mt-ansible-user/.ansible/tmp/ansible-tmp-1558868136.49-16683638151
7931/ > /dev/null 2>&1 && sleep 0'"'"''
<10.1.1.11> (0, '', '')

最佳答案

您的远程主机告诉您:

The PyMySQL (Python 2.7 and Python 3.X) or MySQL-python (Python 2.X) module is required.



您是否遵循了建议并安装了所需的 pymysql远程主机上的 python 包?

为了快速测试,在您的远程主机上:
  • 如果使用 python 2.7:sudo pip install pymysql
  • 如果使用 python 3.x:sudo pip3 install pymysql

  • 测试后,为确保此依赖项始终存在,请在启动任何 mysql 任务之前在您的剧本中添加一个任务:
    - name: Make sure pymysql is present
    become: true # needed if the other tasks are not played as root
    pip:
    name: pymysql
    state: present

    您不必指定 executable在这种情况下的选项(请参阅 doc ),因为它将默认为您的 ansible_python_interpreter

    关于python - Ansible + Ubuntu 18.04 + MySQL = "The PyMySQL (Python 2.7 and Python 3.X) or MySQL-python (Python 2.X) module is required.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56313083/

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