I have a pretty easy playbook to connect to a Juniper switch and provide me the show version output. All works when I place the username and password into the playbook no problem. What I would prefer to do is set the username and password in group_vars/all and have the username and password read from there. Any tips? I can’t seem to get this going. I think I may need to pass along a hostvars but can’t seem to figure it out.
playbook:
- hosts: juniper
gather_facts: no
connection: local
tasks:
- name: DEFINE PROVIDER
set_fact:
hostinfo:
host: “{{ inventory_hostname }}”
password: xxxxx
username: admin - debug: var=hostvars[inventory_hostname]
- name: show command
junos_command:
provider: “{{ hostinfo }}”
commands: - show version
register: version - debug: msg=“{{ version.stdout }}”
group_vars/all
username=admin
password=xxxxxx