Hi,
I create a AWX credential with machine type.
How can I access username and password fields of this credential in a playbook ?
Thank you.
Hi,
I create a AWX credential with machine type.
How can I access username and password fields of this credential in a playbook ?
Thank you.
Hello Ahmed,
The following playbook is an example that how to use machine credentials in your playbook:
`
tasks:
var: machine
`
Thanks
Soniya
Hello Soniya,
I have tried your solution but it does not work. I get “VARIABLE IS NOT DEFINED!” error.
is there any documentation about cred injection in AWX ?
Hello Ahmed,
You are getting this error because ansible fact caching is disabled. Variables ‘{{ machine_credential_user }}’ and ‘{{ machine_credential_password }}’ are present in ansible fact cache. To use these credentials you have to enable fact caching by setting gather_facts: true.
is there any documentation about cred injection in AWX ?
Yes we can achieve this task by creating a custom credential type. Credential types consist of two key concepts – “inputs” and “injectors“. Where:
Inputs: define the value types that are used for this credential – such as a username, a password, a token, or any other identifier that’s part of the credential.
Injectors: describe how these credentials are exposed for Ansible to use – this can be Ansible extra variables, environment variables, or templated file content.
Here are the steps:
Creating the Custom Credential type in Ansible AWX:
Input:
`
fields:
type: string
id: machine_credential_user
label: Machine username
type: string
id: machine_credential_password
label: “Machine password”
secret: True
required:
`
Injector:
`
extra_vars:
username: ‘{{ machine_credential_user }}’
password: ‘{{ machine_credential_password }}’
`
And then you will see the newly created credential type.
Example:
`
<Your_JobName>:
name: MachineJobdemo
user: “{{ username }}”
password: “{{ password }}”
`
Hope this solution will work for you. Please revert in case of any query
Thanks
Soniya