Post

Ansible Junos Facts Module: Running RedHat junipernetworks.junos Modules in juniper.device Collection

Ansible Junos Facts Module: Running RedHat junipernetworks.junos Modules in juniper.device Collection

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:

  1. RedHat module path playbook (junipernetworks.junos.junos_facts)
  2. Native module path playbook (juniper.device.facts)
  3. Executing RedHat task via juniper.device namespace
  4. Inventory patterns (NETCONF / PyEZ / local)
  5. Returned data fields
  6. Facts usage cheat sheet
  7. Troubleshooting
  8. 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_hostnamehostnameDevice host-name
ansible_net_modelmodelChassis model
ansible_net_versionversionJunos version
ansible_net_serialnumserialnumberSerial number
(not present)RE0 / RE1 mapsRE operational states
(not present)up_timeHuman readable uptime
ansible_net_system(implicit junos)OS identifier

Native adds richer per-RE/platform context.


6. Facts Cheat Sheet (Native)

GoalApproach
Basic platform dataRun module without params
Hostnamenative_facts.ansible_facts.junos.hostname
Serialnative_facts.ansible_facts.junos.serialnumber
RE master statenative_facts.ansible_facts.junos.RE0.mastership_state
Conditional taskwhen: native_facts.ansible_facts.junos.model == “MX960”

7. Troubleshooting

SymptomCauseFix
Warning: NoneType .getLoader quirkIgnore if success
Connection failureNETCONF disabledset system services netconf ssh
TimeoutLarge chassisIncrease ansible_command_timeout
Missing RE1 dataSingle RE deviceNormal
Empty factsAuth/privilegeVerify 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
This post is licensed under CC BY 4.0 by the author.