使用Ubuntu 18.04, Ansible 2.9, Python 3.6.9, 已安装python3-apt
在基本的 ansible 命令上ansible -b all -m apt -a "name=apache2 state=latest"
获取错误:
FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"msg": "Could not import python modules: apt, apt_pkg. Please install python3-apt package."
}
Run Code Online (Sandbox Code Playgroud)
$ sudo apt-get install python3-apt
$ ansible --version
ansible 2.9.12
python version = 3.6.9
$ python --version
Python 3.7.6
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用在Mac OSX上运行的Ansible控制器创建一个新的MySQL数据库.当我第一次收到msg: the python mysqldb module is required错误消息时,我添加了一个安装MySQL-pythonwith 的任务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
Run Code Online (Sandbox Code Playgroud)
当我运行剧本时:
ansible-playbook -i "localhost," -c local mysql-test.yml
Run Code Online (Sandbox Code Playgroud)
我得到以下结果(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 …Run Code Online (Sandbox Code Playgroud)