title: Ansible - The PyMySQL (Python 2.7 and Python 3.X) or MySQL-python (Python 2.X) module is required
body: <p>My ansible code looks like this:</p>
  <pre class="lang-yaml prettyprint-override"><code>---
  - name: Install python
    apt:
      pkg: &quot;{{ item }}&quot;
      update-cache: yes
      state: latest
    with_items:
      - python
      - python-dev
  
  - name: Install pymysql
    pip:
      name: &quot;{{ item }}&quot;
      executable: pip
      state: present
    with_items:
      - PyMySQL==0.7.11
      - MySQL-python
  
  - name: Install mysql and deps
    apt:
      pkg: &quot;{{ item }}&quot;
      update-cache: yes
      state: latest
    with_items:
      - mysql-server
      - libmysqlclient-dev
      - python-mysqldb
      - python-pip
  
  - name: Create DB
    mysql_db:
      name: &quot;{{ item }}&quot;
      collation: utf8_general_ci
      encoding: utf8
    with_items: &quot;{{ database_names }}&quot;
  </code></pre>
  <p>When I run it, I get the error,</p>
  <blockquote>
  <p>failed: [xxxxx] (item=xxxxx) =&gt; {&quot;ansible_loop_var&quot;: &quot;item&quot;, &quot;changed&quot;: false, &quot;item&quot;: &quot;xxxxx&quot;, &quot;msg&quot;: &quot;The PyMySQL (Python 2.7 and Python 3.X) or MySQL-python (Python 2.X) module is required.&quot;}</p>
  </blockquote>
  <p>But from my sensible code you see I installed both PyMySQL and MySQL-python prior to calling <code>mysql_db</code>. Also, from ansible runtime log, I see both PyMySQL and MySQL-python got installed successfully:</p>
  <pre><code>TASK [mysql : Install python] **************************************************
  ok: [aquila] =&gt; (item=python)
  ok: [aquila] =&gt; (item=python-dev)
  
  TASK [mysql : Install pymysql] *************************************************
  ok: [aquila] =&gt; (item=PyMySQL==0.7.11)
  ok: [aquila] =&gt; (item=MySQL-python)
  
  TASK [mysql : Install mysql and deps] ******************************************
  ok: [aquila] =&gt; (item=mysql-server)
  ok: [aquila] =&gt; (item=libmysqlclient-dev)
  ok: [aquila] =&gt; (item=python-mysqldb)
  ok: [aquila] =&gt; (item=python-pip)
  
  TASK [mysql : Create DB] ************************************************
  failed: [xxxxx] (item=xxxxx) =&gt; {&quot;ansible_loop_var&quot;: &quot;item&quot;, &quot;changed&quot;: false, &quot;item&quot;: &quot;aquila&quot;, &quot;msg&quot;: &quot;The PyMySQL (Python 2.7 and Python 3.X) or MySQL-python (Python 2.X) module is required.&quot;}
  </code></pre>
  <p>Why <code>mysql-db</code> is not getting the PyMySQL or MySQL-python module?</p>