title: Correct way to setup the environment when developing custom ansible modules that use 3rd party python libraries
body: <p>I have developed a custom ansible module that has a dependency on a 3rd party library PyYAML. However running the playbook yields</p>
  
  <pre><code>ansible_module_my_module.py, line 5, in &lt;module&gt;
    import yaml
  ImportError: No module named yaml
  </code></pre>
  
  <p>I see PyYAML in the ansible requirements.txt (<a href="https://github.com/ansible/ansible/blob/stable-2.8/requirements.txt" rel="nofollow noreferrer">https://github.com/ansible/ansible/blob/stable-2.8/requirements.txt</a>) so I know its installed/used on the host machine. I'm wondering if there is a recommended way to install it on the remote machine?</p>
  
  <p>I can add a step in the playbook using the pip ansible module to install it on the remote. Something like</p>
  
  <pre><code>- hosts: all
    tasks:
    - name: Installing PyYAML python library using Ansible pip module
      pip:
        name: PyYAML
  </code></pre>
  
  <p>But that means the playbook knows implementation details about modules buried deep down the stack which seems wrong. My expectation is that there is some way to tell ansible to install the 3rd party libraries on the remote machine as part of its setup. For example adding a requirements.txt in my module and ansible appends it to its setup, but I can't seem to find an elegant way to do it. Any help is appreciated.</p>