Hi Eugene,
I'm always glad to seen new folks using Ansible with Junos. Please do continue to reach out to us if you have any additional questions.
To start with, it is helpful to understand the difference between how Ansible communicates with most hosts/servers and how it communicates with most networking devices.
In the typical Ansible communication model, the Ansible control machine establishes/maintains an SSH session to the target host. The playbook/modules are downloaded to the host and then executed by a Python interpreter on the host itself. The result (in JSON format) is then returned over the the SSH session to the Ansible control machine.
When communicating with network devices, the Ansible control machine executes the playbook/modules locally on the Ansible control machine itself. Each module establishes a communication channel with the target network device. In the case of Junos device's, that communication channel is typically a NETCONF over SSH connection which is provided by the PyEZ library on which the Junos for Ansible modules are built.
This atypical communication model means that many of the standard Ansible modules can not be used with networking devices. This includes the standard "setup" module which normally does fact gathering on most hosts/servers. That's why the first attempt in your previous email didn't work.
This atypical communication model also means that you must pass connection parameters (hostname, username, and password) as arguments to each Junos module.
The next important point to understand is that there are currently two sets of Junos modules for Ansible. The "core" modules are included in Ansible 2.1 and greater and are documented at
http://docs.ansible.com/ansible/list_of_network_modules.html#junos. These core modules were developed by Ansible with input from Juniper. The older "galaxy" modules were developed by Juniper directly and work with older 1.x releases as well as current 2.x releases. The galaxy modules must be installed using
sudo ansible-galaxy install Juniper.junos. Documentation for the galaxy modules can be found at
http://junos-ansible-modules.readthedocs.io/en/1.4.0/. You can use any combination of core and/or galaxy modules in your playbooks.
Currently there is some overlap between the core modules and the galaxy modules and there are some differences in how arguments are specified for each set of modules. Juniper is actively working with Ansible on a plan to consolidate and standardize the modules.
With that explanation, here's an example playbook which uses the core junos_facts module to gather and print Junos facts (using the core debug module):
---
- name: Get facts using the core module
hosts: all
connection: local
gather_facts: no
tasks:
- name: Get Junos Facts Using Core Module
junos_facts:
host: "{{ inventory_hostname }}"
username: "user"
password: "user123"
config: yes
config_format: xml
register: response
- name: Print Facts via Registered Response
debug:
var: response.ansible_facts
and here is an example playbook which uses the galaxy get_junos_facts module:
---
- name: Get facts using the galaxy module
hosts: all
connection: local
gather_facts: no
roles:
- Juniper.junos
tasks:
- name: Get Junos Facts Using Galaxy Module
junos_get_facts:
host: "{{ inventory_hostname }}"
user: "user"
passwd: "user123"
register: response
- name: Print Facts via Registered Response
debug:
var: response.facts
Hope this helps,
--Stacy