Skip to content

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_catalog
  • vcd_external_network
  • vcd_roles
  • vcd_vapp_network
  • vcd_vapp_vm_nic
  • vcd_vdc_network
  • vcd_catalog_item
  • vcd_org
  • vcd_user
  • vcd_vapp_vm
  • vcd_vapp_vm_snapshot
  • vcd_disk
  • vcd_org_vdc
  • vcd_vapp
  • vcd_vapp_vm_disk
  • vcd_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_LIBRARY environment variable. $ANSIBLE_LIBRARY takes 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

Sources#