title: Ansible unable to find `zabbix-api`
body: <h2>Problem</h2>
  
  <p>In this scenario Ansible is unable to locate Zabbix API. Ansible spits out the following error when running a playbook that calls the <code>zabbix-api</code> module:</p>
  
  <pre class="lang-sh prettyprint-override"><code>msg: 'Missing required zabbix-api module (check docs or install with: pip install zabbix-api)'
  </code></pre>
  
  <h2>Environment</h2>
  
  <p>The control node, running Ubuntu 18.04, contains multiple python interpreters (2.7/3.6/3.7). Zabbix API has been installed on the control node using pip (<code>pip install zabbix-api</code>) for python2.7 in <code>/usr/local/lib/python2.7/dist-packages/</code>. This can be observed after running the following:</p>
  
  <pre class="lang-sh prettyprint-override"><code>import imp
  imp.find_module('zabbix_api')
  </code></pre>
  
  <p>which outputs:</p>
  
  <pre class="lang-sh prettyprint-override"><code>(&lt;open file '/usr/local/lib/python2.7/dist-packages/zabbix_api.py', mode 'U' at 0x7f102e990540&gt;, '/usr/local/lib/python2.7/dist-packages/zabbix_api.py', ('.py', 'U', 1)
  </code></pre>
  
  <h2>Checks</h2>
  
  <p>I have made sure that:</p>
  
  <ul>
  <li>Ansible loads the correct Python interpreter: <code>ansible_python_interpreter=/usr/bin/python</code></li>
  <li>PATH contains the path to the interpreter's <code>site-packages</code> or <code>dist-packages</code></li>
  <li>the interpreter can load the <code>zabbix_api</code> library: <code>python -c "import zabbix_api"</code></li>
  <li><code>zabbix_api.py</code> permissions are correct</li>
  <li><code>sys.path</code> contains the path to <code>zabbix_api</code> dir:</li>
  </ul>
  
  <pre class="lang-sh prettyprint-override"><code>import sys
  print '\n'.join(sys.path)
  </code></pre>
  
  <p>Which outputs:</p>
  
  <pre class="lang-sh prettyprint-override"><code>    /usr/lib/python2.7
      /usr/lib/python2.7/plat-x86_64-linux-gnu
      /usr/lib/python2.7/lib-tk
      /usr/lib/python2.7/lib-old
      /usr/lib/python2.7/lib-dynload
      /home/peter/.local/lib/python2.7/site-packages
      /usr/local/lib/python2.7/dist-packages
      /usr/lib/python2.7/dist-packages
  </code></pre>
  
  <p>What am I missing here? Are there any other factors to take into account?</p>