Ansible AWX Multiple Credentials for Play
-
What Are Custom Credential Types?
Custom credential types in AWX and AAP allow you to define new forms of credentials tailored to specific authentication needs. These can include SSH keys, API tokens, passwords, or any other unique authentication method required by your automation scripts. They are customizable templates that dictate how credentials are structured, stored, and used.Why Use Custom Credential Types?
- Flexibility: Create credentials that match your specific needs.
- Security: Ensure sensitive data is securely managed according to your organization’s policies.
- Consistency: Standardize credentials across various automation tasks and environments.
Creating Custom Credential Types in AWX/AAP
- Log in to the AWX/AAP Web Interface: Open your browser and access the AWX dashboard.
- Navigate to the Credential Types Tab: Click on “Administration” in the sidebar, then go to “Credential Types.” and click "Add"
Create a New Credential Type:
Example:
Name: BackupJob Credential TypeAdd the input_configuration arguments:
fields: - id: arista_username type: string label: arista username - id: arista_password type: string label: arista password secret: true - id: opnsense_username type: string label: opnsense username - id: opnsense_password type: string label: opnsense password secret: true required: - arista_username - arista_password - opnsense_username - opnsense_password
Add the injector Configuration: - This is what is used to inject the credential in to the playbook
extra_vars: arista_password: '{{ arista_password }}' arista_username: '{{ arista_username }}' opnsense_password: '{{ opnsense_password }}' opnsense_username: '{{ opnsense_username }}'
Using Custom Credential Types in AWX/AAP
The new credential type will now to available for you to use as a template to create new credentials- Create a New Credential:
- Navigate to the Credentials: Click on “Resources” in the sidebar, then go to “Credentials” and click "Add"
- Give it a name and Description
- Form the Credential Type dropdown choose the Template you just created
- Add your credentials and save your new credential
Using Custom Credential in a job template
- Navigate to the Templates: Click on “Resources” in the sidebar, then go to “Templates” and click on the template you wish to add the credential
The Variable you define in the injector configuration is how you will use the new credential in your playbook:
--- - name: Backup config to SFTP Server hosts: opnsense ignore_unreachable: true vars: ansible_user: "{{ opnsense_username }}" ansible_password: "{{ opnsense_password }}"
Best Practices for Custom Credential Types
- Secure Input Fields: Mark sensitive fields as secret to protect them.
- Consistent Naming: Use descriptive names for credential types to avoid confusion.
- Regular Updates: Periodically update credentials to maintain security.