title: Ansible not finding custom python modules on remote server
body: <p>I am trying to call a python function from another script in a different directory. Have a playbook to execute this.</p>
  <p>This works fine on localhost but on remote_server it is failing with &quot;ModuleNotFoundError: No module named 'script2'&quot;</p>
  <h1>Here are my scripts:</h1>
  <pre><code>[root@server Test]# ls
  hosts  playbook  python1  python2
  </code></pre>
  <pre><code>[root@server Test]# cat playbook/playbook.yml 
  
  - hosts: &quot;{{ host }}&quot;
    gather_facts: yes
    become: yes
  
    vars:
      ansible_python_interpreter: /usr/bin/python3
  
    tasks:
  
      - name: Connect to MongoDB
        script: ../python1/script1.py
        args:
          executable: python3
  </code></pre>
  <pre class="lang-py prettyprint-override"><code>[root@server Test]# cat python1/script1.py 
  #!/usr/bin/python
  
  import os
  import sys
  
  sys.path.append(&quot;../python2&quot;)
  
  from script2 import dbServer
  
  
  def main():
  
      cursor = dbServer()
      print(cursor.count())
  
  
  if __name__ == '__main__':
      main()
  </code></pre>
  <pre class="lang-py prettyprint-override"><code>[root@server Test]# cat python2/script2.py 
  
  #! /usr/bin/python
  
  from pymongo import MongoClient
  
  def connectToMongoDB():
  
      global db
  
      try:
          conn = MongoClient(&quot;myserver.com&quot;)
          db = conn.CMDB
      except Exception as e:
          print(&quot;\nUnable to fetch details from MongoDB..!!!\n%s\n&quot; % e)
          sys.exit()
  
  
  def dbServer():
  
      connectToMongoDB()
  
      collection = db.dbServer
      cursor = collection.find()
  
      return cursor
  </code></pre>
  <h1>Execution:</h1>
  <pre><code>[root@server playbook]# ansible-playbook -i ../hosts playbook.yml -e &quot;host=localhost&quot;
  
  PLAY [localhost] ****************************************************************************************************
  
  TASK [Gathering Facts] **********************************************************************************************
  ok: [localhost]
  
  TASK [Connect to MongoDB] *******************************************************************************************
  changed: [localhost]
  
  PLAY RECAP **********************************************************************************************************
  localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
  </code></pre>
  <pre><code>[root@server playbook]# ansible-playbook -i ../hosts playbook.yml -e &quot;host=myremote&quot;
  
  PLAY [remote_server] ************************************************************************************************
  
  TASK [Gathering Facts] **********************************************************************************************
  ok: [myremote]
  
  TASK [check ping status of P10 systems] *****************************************************************************
  fatal: [myremote]: FAILED! =&gt; {&quot;changed&quot;: true, &quot;msg&quot;: &quot;non-zero return
  code&quot;, &quot;rc&quot;: 1, &quot;stderr&quot;: &quot;Shared connection to myremote closed.\r\n&quot;,
  &quot;stderr_lines&quot;: [&quot;Shared connection to myremote closed.&quot;], &quot;stdout&quot;:
  &quot;Traceback (most recent call last):\r\n  File
  \&quot;/root/.ansible/tmp/ansible-tmp-1602453181.740341-
  25196530470896/script1.py\&quot;, line 8, in &lt;module&gt;\r\n    from script2
  import dbServer\r\nModuleNotFoundError: No module named 'script2'\r\n&quot;,
  &quot;stdout_lines&quot;: [&quot;Traceback (most recent call last):&quot;, &quot;  File
  \&quot;/root/.ansible/tmp/ansible-tmp-1602453181.740341-
  25196530470896/script1.py\&quot;, line 8, in &lt;module&gt;&quot;, &quot;    from script2
  import dbServer&quot;, &quot;ModuleNotFoundError: No module named 'script2'&quot;]}
  
  PLAY RECAP **********************************************************************************************************
  myremote : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
  </code></pre>
  <p>Please help how can I get my module copied to remote server. I need to get this working in AWX as well.</p>