Ansible complains about "The MySQL-python module is required"

时间:2018-07-25 04:39:00

标签: ansible ansible-2.x

I have Ansible 2.6.1 installed in my local machine (WSL; Ubuntu):

ansible 2.6.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/user/.ansible/plugins/modules', u'/usr/share/ansile/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.12 (default, Dec  4 2017, 14:50:18) [GCC 5.4.0 20160609]

My target machine is running Ubuntu 16.04-LTS.

I'm using this task to install python3-mysqldb:

 - name: "Debian | Install Mysql Client package"
   apt:
     name: "{{ item }}"
     state: present
   with_items:
     - mysql-client
     - python3-dev
     - libmysqlclient-dev
     - python3-mysqldb
   when:
     - zabbix_server_database == 'mysql'
   tags:
     - zabbix-server
     - init
     - database

It fails in this task:

- name: "MySQL | Create database and import file >= 3.0"
  mysql_db:
    name: "{{ zabbix_server_dbname }}"
    encoding: "{{ zabbix_server_dbencoding }}"
    collation: "{{ zabbix_server_dbcollation }}"
    state: import
    target: "{{ ls_output_create.stdout }}"
  when:
    - zabbix_version is version_compare('3.0', '>=')
    - zabbix_database_sqlload
    - not done_file.stat.exists
  delegate_to: "{{ delegated_dbhost }}"
  tags:
    - zabbix-server
    - database

Here's the fail message:

fatal: [target_host -> target_host-db]: FAILED! => {"changed": false, "msg": "The MySQL-python module is required."}

I can confirm python3-mysqldb was indeed installed:

/.                                                                             
/usr                                                                           
/usr/share                                                                     
/usr/share/doc                                                                 
/usr/share/doc/python3-mysqldb                                                 
/usr/share/doc/python3-mysqldb/changelog.Debian.gz                             
/usr/share/doc/python3-mysqldb/copyright                                       
/usr/lib                                                                       
/usr/lib/python3                                                               
/usr/lib/python3/dist-packages                                                 
/usr/lib/python3/dist-packages/mysqlclient-1.3.7.egg-info                      
/usr/lib/python3/dist-packages/mysqlclient-1.3.7.egg-info/top_level.txt        
/usr/lib/python3/dist-packages/mysqlclient-1.3.7.egg-info/PKG-INFO             
/usr/lib/python3/dist-packages/mysqlclient-1.3.7.egg-info/dependency_links.txt 
/usr/lib/python3/dist-packages/_mysql_exceptions.py                            
/usr/lib/python3/dist-packages/_mysql.cpython-35m-x86_64-linux-gnu.so          
/usr/lib/python3/dist-packages/MySQLdb                                         
/usr/lib/python3/dist-packages/MySQLdb/connections.py                          
/usr/lib/python3/dist-packages/MySQLdb/release.py                              
/usr/lib/python3/dist-packages/MySQLdb/cursors.py                              
/usr/lib/python3/dist-packages/MySQLdb/constants                               
/usr/lib/python3/dist-packages/MySQLdb/constants/ER.py                         
/usr/lib/python3/dist-packages/MySQLdb/constants/CLIENT.py                     
/usr/lib/python3/dist-packages/MySQLdb/constants/REFRESH.py                    
/usr/lib/python3/dist-packages/MySQLdb/constants/FIELD_TYPE.py                 
/usr/lib/python3/dist-packages/MySQLdb/constants/FLAG.py                       
/usr/lib/python3/dist-packages/MySQLdb/constants/__init__.py                   
/usr/lib/python3/dist-packages/MySQLdb/constants/CR.py                         
/usr/lib/python3/dist-packages/MySQLdb/converters.py                           
/usr/lib/python3/dist-packages/MySQLdb/compat.py                               
/usr/lib/python3/dist-packages/MySQLdb/__init__.py                             
/usr/lib/python3/dist-packages/MySQLdb/times.py    

I also tried installing the python package MySQL-python using pip but I also got the same error message.

I'm stumped. I don't know what to do anymore.

EDIT: I also tried installing Python 2.7.x on the target machine and made sure that /usr/bin/python is symlinked to Python 2.7.x but I'm still getting the same error. I'm using DJ Wasabi's zabbix-server role

2 个答案:

答案 0 :(得分:1)

我认为您正在与您的代表团混在一起。我会简化事情。

选项一:在本地运行所有内容。假设您的数据库服务器可以通过网络访问:

self.repType.set('pn')

选项二:从数据库服务器运行SQL命令(然后在本地计算机上不需要mysql-python,但是在托管MySQL的远程服务器上需要python和mysql-python):

- hosts: localhost
  connection: local
  tasks:
    - name: "Debian | Install Mysql Client package"
      apt:
        name: "{{ item }}"
        state: present
      with_items:
        - mysql-client
        - python3-dev
        - libmysqlclient-dev
        - python3-mysqldb
      when:
        - zabbix_server_database == 'mysql'
      tags:
        - zabbix-server
        - init
        - database

    - name: "MySQL | Create database and import file >= 3.0"
      mysql_db:
        name: "{{ zabbix_server_dbname }}"
        encoding: "{{ zabbix_server_dbencoding }}"
        collation: "{{ zabbix_server_dbcollation }}"
        state: import
        target: "{{ ls_output_create.stdout }}"
      when:
        - zabbix_version is version_compare('3.0', '>=')
        - zabbix_database_sqlload
        - not done_file.stat.exists
      tags:
        - zabbix-server
        - database

答案 1 :(得分:0)

在 ansible.cfg 中添加 ansible_python_interpreter 如下:

const [appState, setAppState] = React.useState(AppState.currentState);
  const webview = React.useRef(null);
  React.useEffect(() => {
    AppState.addEventListener('change', handleAppStateChange);
    return () => AppState.removeEventListener('change', handleAppStateChange);
  }, [webview.current]);//    <---- CHANGED
  function backHandler() {
    popScreen(Screens.About);
    return true;
  }
  function handleAppStateChange(nextAppState) {
    if (nextAppState === 'active') {
      webview.current.reload(); //     <---- CHANGED
    }
    setAppState(nextAppState);
  }
  const WebView = require('react-native-webview').default; //  <---- remove it and import it at top of file
  return (
      <View style={styles.container}>
        <View style={styles.web}>
          <WebView
            ref={webview} //    <---- CHANGED
            ..