Using External Ansible Modules
Use external Ansible modules locally#
I used an Ansible module developed for VMware vCloud Director. It helped speed up provisioning and kept changes more consistent than a human user clicking through the interface.
At first I created the playbooks within the module repo and tested them from there.
Once the playbooks were ready, I wanted to keep only the relevant module code in the project library and import the module from where I was running the scripts.
The relevant Ansible documentation is adding a module locally.
Check that you have access to a module#
The ansible-module-vcloud-director repo has a number of modules under the modules/ folder:
vcd_catalogvcd_external_networkvcd_rolesvcd_vapp_networkvcd_vapp_vm_nicvcd_vdc_networkvcd_catalog_itemvcd_orgvcd_uservcd_vapp_vmvcd_vapp_vm_snapshotvcd_diskvcd_org_vdcvcd_vappvcd_vapp_vm_diskvcd_vdc_gateway
To check if your module is available, use:
ansible-doc -t module vcd_org
If it is found you will get the documentation. If it does not exist you get a warning:
[WARNING]: module vcd_org not found in: /Users/xxx...
Add the module locally#
To add the module locally, add it to one of these places:
- Any directory added to the
ANSIBLE_LIBRARYenvironment variable.$ANSIBLE_LIBRARYtakes a colon-separated list like$PATH ~/.ansible/plugins/modules//usr/share/ansible/plugins/modules/
You can also add an ansible.cfg to your project directory, /etc/ansible or ~/.ansible.cfg, and set the default module path:
[defaults]
library = ./<my-module-folder>
You can also put the modules in your project folder, like you would when running on AWX, and then put an ansible.cfg into that folder specifying the module and module utils paths:
[defaults]
library = modules
module_utils = module_utils