AWX Tower Secret Plugin#
This example utilizes the HashiCorp Vault Secret Lookup AWX Tower Credential Plugin
Note
There are two ways to retrieve Hashicorp Vault secrets for AWX Tower. To see the other option, reference Ansible Lookup
See this example terraform repository to setup approle authentication for ansible to connect to vault
Vault Policies#
Team's are responsible for setting up policies to give ansible access to specific secrets or paths. Use this terrraform or the following CLI commands to setup a role to read any secrets at secret/ansible/*
. Depending on which lookup module you use, there are two different paths that will be needed.
vault policy write approle_ansible_access_policy - <<EOF
# Required path for community.hashi_vault.hashi_vault & Tower HashiCorp Vault Secret Lookup
path "secret/data/ansible/*" {
capabilities = ["read"]
}
# Required path for community.hashi_vault.vault_kv2_get lookup
path "secret/ansible/*" {
capabilities = ["read"]
}
EOF
Approle#
In order for ansible to connect to vault, it must authenticate. One option for authentication is an approle. To create an approle, run this terrraform or use the following CLI command and associate the policy that you created in the last step:
vault write auth/approle/role/ansible \
token_policies="default,approle_ansible_access_policy"
role_id & secret_id#
Ansible will use a role_id & secret_id to authenticate to vault. The example terraform will automatically display the role_id, and you can run terraform output secret_id
to obtain the secret_id. For production, the following CLI commands should likely be used instead so the secret_id is not stored to the terraform state.
# Read role-id
vault read auth/approle/role/ansible/role-id
# Create a secret-id
vault write -f auth/approle/role/ansible/secret-id
AWX Tower Integration#
-
Navigate to AWX Tower>Credentials>Add
-
Fill out the following information (all other fields can be left blank):
- Name i.e. secm_hcp_plugin_credential
- Description i.e. Approle for AWX plugin to connect to Vault
- Organization Your team's AWX Tower organization
- Credential Type HashiCorp Vault Secret Lookup
- Server URL https://hcp-vault-private-vault-fc507e0d.5d5b1f21.z1.hashicorp.cloud:8200
- AppRole role_id role_id retrieved from vault in previous section
- AppRole secret_id secret_id retrieved from vault in previous section
- Namespace name admin/CESI or admin/CESI/subteam (i.e.
admin/secm
oradmin/iam/appsec
) - Path to Auth approle
- API Version v2
-
Click the Test button to test the credential
-
You can now use this plugin to retrieve secrets values for other credential types. The following steps are for the UMN custom Single Secret credential type, but this can be used for other credential types as well.
-
Navigate to AWX Tower>Credentials>Add
-
Fill out the following information (all other fields can be left blank):
- Name i.e. secm_hcp_plugin_credential
- Description i.e. Approle for AWX plugin to connect to Vault
- Organization Your team's AWX Tower organization
- Credential Type Single Secret Credential
- single_secret Click the key icon
- Select the name of the plugin credential created in step 2
- Path to Secret secret/ansible/test
- Key Name pizza
-
Associate that newly created credential from step 6 to your tower template
-
Use this example playbook to print the test credential.