Ansible Junos Facts Module: Running RedHat junipernetworks.junos Modules in juniper.device Collection
The juniper.device collection allows continued use of RedHat style module paths (junipernetworks.junos.junos_facts). Existing playbooks run unmodified while new automation may adopt juniper.device.facts. You can also execute the RedHat facts task using the juniper.device collection namespace. This post shows:
- RedHat module path playbook (
junipernetworks.junos.junos_facts) - Native module path playbook (
juniper.device.facts) - Executing RedHat task via juniper.device namespace
- Inventory patterns (NETCONF / PyEZ / local)
- Returned data fields
- Facts usage cheat sheet
- Troubleshooting
- Summary
1. RedHat Module Path Playbook (Unchanged)
Inventory (NETCONF)
1
2
3
4
5
6
7
8
9
10
11
12
| [junos]
<Device IP>
[junos:vars]
ansible_network_os=juniper.device.junos
ansible_ssh_user=<username>
ansible_ssh_pass=<password>
ansible_port=22
ansible_connection=ansible.netcommon.netconf
[all:vars]
ansible_python_interpreter=<python interpreter path>
|
Playbook
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| ---
- name: Gather Junos facts (RedHat module path)
hosts: junos
gather_facts: false
connection: ansible.netcommon.netconf
collections:
- junipernetworks.junos
tasks:
- name: Collect default subset
junipernetworks.junos.junos_facts:
register: rh_facts
- name: Show facts
debug:
var: rh_facts
|
Run
1
| ansible-playbook -i inventory_rh pb.redhat_facts.yml
|
Sample Output (Excerpt)
1
2
3
4
| ansible_net_hostname: evoeventtestb
ansible_net_model: mx960
ansible_net_system: junos
ansible_net_version: 25.4I-20250615_dev_common.0.1157
|
2. Native Module Path Playbook (juniper.device.facts)
Inventory (PyEZ Transport)
1
2
3
4
5
6
| [junos]
pyez_facts ansible_host=x.x.x.x ansible_user=<user> ansible_ssh_pass=<pass> ansible_port=22 \
ansible_connection=juniper.device.pyez ansible_command_timeout=300
[all:vars]
ansible_python_interpreter=<python interpreter path>
|
(Local/on-box)
1
2
| [junos]
localhost ansible_connection=local ansible_python_interpreter=/usr/bin/python3
|
Playbook
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| ---
- name: Gather Junos facts (native module path)
hosts: junos
gather_facts: false
collections:
- juniper.device
tasks:
- name: Run native facts
juniper.device.facts:
register: native_facts
- name: Show native facts
debug:
var: native_facts.ansible_facts.junos
|
Run
1
| ansible-playbook -i inventory_native pb.native_facts.yml
|
Sample Output (Excerpt)
1
2
3
4
5
6
| hostname: evoeventtestb
model: MX960
serialnumber: VM685037CBB2
version: 25.4I-20250615_dev_common.0.1157
RE0.mastership_state: master
RE1.mastership_state: backup
|
3. Executing RedHat Facts Using juniper.device Namespace
Same RedHat module (junos_facts) callable through juniper.device collection namespace.
1
2
3
4
5
6
7
8
9
10
11
12
| [junos]
<Device IP>
[junos:vars]
ansible_network_os=juniper.device.junos
ansible_ssh_user=<username>
ansible_ssh_pass=<password>
ansible_port=22
ansible_connection=ansible.netcommon.netconf
[all:vars]
ansible_python_interpreter=<python interpreter path>
|
Playbook
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| ---
- name: Gather Junos facts (RedHat module path via juniper.device namespace)
hosts: junos
gather_facts: false
connection: ansible.netcommon.netconf
collections:
- juniper.device
tasks:
- name: Collect default subset
juniper.device.junos_facts:
register: rh_facts
- name: Show facts
debug:
var: rh_facts
|
Run
1
| ansible-playbook -i inventory_rh pb.redhat_facts.yml
|
Sample Output (Excerpt)
1
2
3
4
| ansible_net_hostname: evoeventtestb
ansible_net_model: mx960
ansible_net_system: junos
ansible_net_version: 25.4I-20250615_dev_common.0.1157
|
4. Directory Structure Example
1
2
3
4
5
| _playbooks/
pb.redhat_facts.yml
pb.native_facts.yml
inventory_rh
inventory_native
|
5. Returned Data Fields
| RedHat Path Key (ansible_facts) | Native Path Key (ansible_facts.junos) | Notes |
|---|
| ansible_net_hostname | hostname | Device host-name |
| ansible_net_model | model | Chassis model |
| ansible_net_version | version | Junos version |
| ansible_net_serialnum | serialnumber | Serial number |
| (not present) | RE0 / RE1 maps | RE operational states |
| (not present) | up_time | Human readable uptime |
| ansible_net_system | (implicit junos) | OS identifier |
Native adds richer per-RE/platform context.
6. Facts Cheat Sheet (Native)
| Goal | Approach |
|---|
| Basic platform data | Run module without params |
| Hostname | native_facts.ansible_facts.junos.hostname |
| Serial | native_facts.ansible_facts.junos.serialnumber |
| RE master state | native_facts.ansible_facts.junos.RE0.mastership_state |
| Conditional task | when: native_facts.ansible_facts.junos.model == “MX960” |
7. Troubleshooting
| Symptom | Cause | Fix |
|---|
| Warning: NoneType .get | Loader quirk | Ignore if success |
| Connection failure | NETCONF disabled | set system services netconf ssh |
| Timeout | Large chassis | Increase ansible_command_timeout |
| Missing RE1 data | Single RE device | Normal |
| Empty facts | Auth/privilege | Verify creds & NETCONF |
Quick tests:
1
2
| ssh -s netconf <device-ip>
nc -vz <device-ip> 830
|
8. Summary
- RedHat
junipernetworks.junos.junos_facts runs unchanged inside juniper.device. - Native
juniper.device.facts returns enhanced Junos-specific structures. - Both can coexist; adopt native for new automation while keeping existing