I am just new on the AWX and ansible. How do i tell the playbook to use the credentials on a playbook that is going to be run via AWX?. I create the credentials via AWX GUI for Network in my case. What variable or values i need to pass it on the playbook so that AWX will grab it properly to use it?.
Thanks for your clear answer. Based on it, I could see I wasn’t using a Network-type credential but machine-type credentials instead. I’ve now changed my credential to this and I can see some content in the ANSIBLE_NET_SSH_KEYFILE
However, I’m still unable to access my devices. As the content of the ssh file is encrypted, is it expected to see the following:? SSH Key file content
`
TASK [Show the content of the SSH Key] *****************************************
ok: [man3-rc-core4500-01] => {
“msg”: “/tmp/awx_77_dZzrdo/tmpli6mRb”
`
In an ideal scenario, shouldn’t I see something like this: instead ?
I’m struggling as I cannot see what I’m passing to my network devices as a credential. Error
`
TASK [Retrieving full config from devices] *************************************
e30=DeyJ1dWlkIjogIjJiZDMzZmE0LTMxZjItNDMwZi1iMDExLTE5NWU0MGNkM2Q5OCJ9Dfatal: [man3-rc-voip4200-04]: FAILED! => {“changed”: false, “msg”: “Unable to make a PyEZ connection: ConnectAuthError(man3-rc-core4500-01)”}
`
Next, you can see the playbook I’m using. I’ve got 2 tasks:
Task 1- To debug the content of the ANSIBLE_NET_SSH_KEYFILE that I’m using to pass to my devices on the 2 task
Task 2 - Pass the credentials to my network devices.
name: Show the content of the SSH Key
debug:
msg: ‘{{ lookup(“env”, “ANSIBLE_NET_SSH_KEYFILE”) }}’
^^ will not show the contents of the file, it will just print the file location.
{{ lookup(“file”, “ANSIBLE_NET_SSH_KEYFILE” }} ← will print the contents of the file.
I’m not super familiar with network modules. Might you need to tell the networking modules to accept ssh host keys?
As per the Juniper network module documentation I’m using, the default behavior for this module is to look for the path this way:
The first defined value from the following list
The ANSIBLE_NET_SSH_KEYFILE environment variable. (used by Ansible Tower)
The value specified using the --private-key or --key-file command line arguments to the ansibleor ansible-playbook command.
none (the file specified in the user’s SSH configuration, or the operating-system-specific default)
If that’s the case then AWX is passing the following path to the module:
/tmp/awx_77_dZzrdo/tmpli6mRb
Which as I understand would be the location of the network-type credential (encrypted). Should then the module be able to decrypt the file by itself?.
Based on your suggestion I’ve modified my playbook to output the content of the file
`
name: Show the content of the SSH Key
debug:
msg: ‘{{ lookup(“file”, “ANSIBLE_NET_SSH_KEYFILE”) }}’
`
When I re-run the Job in AWX I get back the following:
`
TASK [Show the content of the SSH Key] *****************************************
[WARNING]: Unable to find ‘ANSIBLE_NET_SSH_KEYFILE’ in expected paths (use
-vvvvv to see paths)
fatal: [man3-rc-core4500-01]: FAILED! => {“msg”: “An unhandled exception occurred while running the lookup plugin ‘file’. Error was a <class ‘ansible.errors.AnsibleError’>, original message: could not locate file in lookup: ANSIBLE_NET_SSH_KEYFILE”}
[WARNING]: Unable to find ‘ANSIBLE_NET_SSH_KEYFILE’ in expected paths (use
-vvvvv to see paths)
`
What I’m trying to understand here is if this is expected from the AWX perspective or if this is something the 3rd party (Juniper) is failing to handle from its module?
Thanks once again for your help and for taking the time to answer this query.
Regards
The minute I posted my reply I realised that what you’re saying about reading the path first and then the content. I have restructured my playbook now to achieve it, read the path and then the content.
What I can see in stdout is the content of the private key (as expected) but I’m a bit unsure of whether I should see the new lines \n. Is this expected? When I copy my private key to AWX, obviously there are some newlines \n (invisible) in it. Please have a look at the output of task 2.
Task 1 Output (The path that AWX is using to store my encrypted private key)
Task2 Output (The content of my private key unencrypted - You can see the \n)
`
ok: [man2-rc-access4200-09a] => {
“msg”: “-----BEGIN RSA PRIVATE KEY-----\nProc-Type: 4,ENCRYPTED\nDEK-Info: AES-128-CBC,14\n\nPRIVATE_RANDOM_KEY_n/xZiB\n-----END RSA PRIVATE KEY-----”,
`
See the end of lines… \n → I’m not too sure if this is actually what gets passed to the network module. I guess it is but if that’s the case, would that be a problem?
Task 3 - Network Module Error
`
TASK [Retrieving full config from devices] *************************************
e30=DeyJ1dWlkIjogImFkNmU2YTM0LWVjNmMtNDY0My04OTYwLTQ1MDlhZTg5YjE5NSJ9Dfatal: [man3-rc-voip4200-02]: FAILED! => {“changed”: false, “msg”: “Unable to make a PyEZ connection: ConnectAuthError(man3-rc-voip4200-02)”}
I couldn’t resist on trying now and it worked locally from the container. Not from AWX though but I’m getting really close
From inside the AWX_TASK_1 container, I can see that key totally matches to what AWX is passing to the network module.
Now, the only difference that I can think of is that locally from the container I’m using the ansible-playbook -k option to pass my ssh_key passphrase to the network module. Is there any way to replicate this in AWX?
I’ve added my passphrase to the network-type credentials so it should be encrypted. However, I don’t know to what environment variable this gets mapped to.
Is there any way I can pass passphrase from AWX to the network module?. What would it be the environment variable I should user for this?
Just to be clear on what I’m thinking. Something like this
As a side note. The ANSIBLE_NET_PASSWORD gets passed from the AWX “password” field on the Network-type credential (See picture attached). I would like to understand to where, the “private key passphrase” field gets mapped to.
How can I get information about the environment variables that AWX uses to map it’s credential fields?. Is there any documentation page that shows me what you’ve been telling me?
I’m leaving the information here hoping that some else comes across the same issue and can benefit of this loop.
Sorry, but I haven’t’ had much time lately to do any work for my AWX project. I’m now using the devel branch for the test and I can see your commit on the logs so I can see the fix is there.
Can you please guide me on the expected result or how can I test this fix?. I’ve been reading your fix and the build_password() function and as I understand, based on your comment the fix should prefer the ssh passphrase over the password?
for testing, remove the following line:
passwd: ‘{{ lookup(“env”, “ANSIBLE_NET_PASSWORD”) }}’
Do not set the password field in your Netscript credential
We now disallow jinja2 in extra_vars by default so don’t have the level of indirection i.e. remove SSH_LOCATION: ‘{{ lookup(…) }}’ and replace usages of SSH_LOCATION with ANSIBLE_NET_SSH_KEYFILE