- Network Automation Cookbook
- Karim Okasha
- 162字
- 2025-04-04 13:10:14
There's more...
In order to use the SSH keys that we have generated in our playbooks, we can specify the username and the SSH private key file that we will use to authenticate to our Juniper devices as host or group variables in Ansible. In our case, we will set these variables as group variables for the junos group. We create the group_vars directory, and we create the junos.yml file, and we specify the variables as shown in the following code:
$ cat group_vars/junos.yml
Ansible_user: admin
Ansible_SSH_private_key_file: Ansible_SSH_key
We test the connection between Ansible and our devices again using the Ansible command; however, this time, without specifying any parameters, as shown in the following code:
$ Ansible all -m ping -c network_cli
mxp02 | SUCCESS => {
"changed": false,
"ping": "pong"
}
mxpe02 | SUCCESS => {
"changed": false,
"ping": "pong"
}
mxpe01 | SUCCESS => {
"changed": false,
"ping": "pong"
}
mxp01 | SUCCESS => {
"changed": false,
"ping": "pong"
}?