I have developed a custom ansible module that has a dependency on a 3rd party library PyYAML. However running the playbook yields
ansible_module_my_module.py, line 5, in <module>
import yaml
ImportError: No module named yaml
I see PyYAML in the ansible requirements.txt (https://github.com/ansible/ansible/blob/stable-2.8/requirements.txt) 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?
I can add a step in the playbook using the pip ansible module to install it on the remote. Something like
- hosts: all
tasks:
- name: Installing PyYAML python library using Ansible pip module
pip:
name: PyYAML
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.