Getting Started with Ansible Module Development on Mac OS X

Prerequisite knowledge:

Ansible is great.

Sometimes though you may need to improve on modules, or patch them, or just create new ones.

Here’s what I did (and would do again) to get started:

source ansible/hacking/env-setup
  • Fork the repo where the module currently lives, either https://github.com/ansible/ansible-modules-core or https://github.com/ansible/ansible-modules-extras. If you’re developing a new module you most likely want to put it in ansible-modules-extras.
  • Create a branch to work in.
  • Setup your environment to run against these module locations first (if you didn’t do this step ansible would look at the main ansible directory cloned above first.)
export ANSIBLE_LIBRARY=~/ansible-modules-core:~/ansible-modules-extras
  • Setup an ansible playbook that uses the module you want to change.
  • Confirm the playbook runs before you make changes.
  • Make changes to the module.
  • Confirm the changes work.
  • Commit your changes to your branch.
  • Push your changes to your fork.
  • Open a PR.

Note: There is a test-module script that you can use to execute a module without writing a playbook. See http://docs.ansible.com/developing_modules.html#testing-modules

In my case, the module I was changing didn’t work with the test-module script, so I used the steps I outlined above.