This tutorial guides you through the process of installing Ansible, creating a new Ansible collection, and adding a custom module to it.
Use pip to install Ansible:
pip install ansibleInitialize a new collection with the namespace devconf and collection name ansible_workshop. This command sets up the structure for your collection:
~/.local/bin/ansible-galaxy collection init devconf.ansible_workshopChange to the newly created collection directory:
cd devconf/ansible_workshop/Within the collection, navigate to the plugins directory:
cd plugins/Inside the plugins directory, create a directory named modules where your custom modules will reside:
mkdir modulesMove into the modules directory and create a new Python file for your module:
cd modules
cp ../../../../mitwpustudent.pyEdit the mitwpustudent.py file to implement your module’s functionality.
From here, you can navigate to opensourceops/developing_ansible_modules to find the custom module code.
Finally, copy your collection to the Ansible collections directory:
cd ~/.ansible
mkdir -p collections/ansible_collections
cd collections/ansible_collections
cp -r ~/devconf .Now, let's create a playbook to use the module.