Using Cloud Credentials
Last updated
Last updated
Ansible Cloud Credentials can be defined in the Automation -> Ansible -> Credentials section of the WebUI (see screenshot Adding an OpenStack Cloud Credential).
These credentials can then be associated with an embedded Ansible playbook service or method in the creation dialog (see screenshot Adding Cloud Type and Cloud Credential to a Method).
When a cloud credential is associated with a playbook service or method in this way, the cloud credential values are made available to the playbook via environmental variables, although the format of these is different for the various types of cloud credential.
For an OpenStack cloud credential an environment variable called OS_CLIENT_CONFIG_FILE
is used. This contains the filename of a temporary YAML file such as /tmp/awx_977_foAfn4/tmpu0gAQG written by the embedded Ansible engine. The contents of the YAML file are similar to the following:
The YAML file can be loaded into the Ansible variable space using the OS_CLIENT_CONFIG_FILE
variable, as follows:
The output from the debug
task would be similar to the following:
Note
The cloud is always
devstack
in the YAML imported via theOS_CLIENT_CONFIG_FILE
variable, regardless of the credential name.
These variables can then be used as normal in the Ansible playbook, for example:
Not all cloud credentials are passed via the OS_CLIENT_CONFIG_FILE variable. For example the individual VMware cloud credential fields are passed as separate environment variables, for example:
These can be accessed from the ansible_env
hash, for example: {{ ansible_env.VMWARE_HOST }}
Tip
The
ansible_env
hash contains all environment variables accessible to the running playbook.
This chapter has shown how cloud credentials can be securely stored and retrieved at run-time by an embedded Ansible playbook service or method.