Post

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

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

Ansible Junos RPC 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_rpc). Existing playbooks run unmodified while new automation may adopt juniper.device.rpc. You can also call the RedHat RPC task using the juniper.device namespace (juniper.device.junos_rpc). This post shows:

  1. RedHat module path playbook (junipernetworks.junos.junos_rpc)
  2. Native module path playbook (juniper.device.rpc)
  3. Executing RedHat RPC via juniper.device namespace
  4. Inventory patterns (NETCONF / PyEZ / local)
  5. RPC naming patterns
  6. RPC 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
17
---
- name: Run RPC using RedHat module path
  hosts: junos
  gather_facts: false
  connection: ansible.netcommon.netconf
  collections:
    - junipernetworks.junos

  tasks:
    - name: Get system information
      junipernetworks.junos.junos_rpc:
        rpc: get-system-information
      register: sysinfo

    - name: Show RPC result
      debug:
        var: sysinfo.xml

Run

1
ansible-playbook -i inventory_rh pb.redhat_rpc.yml

Sample Output (Excerpt)

1
2
3
<rpc-reply>
  <system-information>...</system-information>
</rpc-reply>

2. Native Module Path Playbook (juniper.device.rpc)

Inventory (PyEZ Transport)

1
2
3
4
5
6
[junos]
pyez_rpc 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
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
---
- name: Run RPCs using native module path
  hosts: junos
  gather_facts: false
  collections:
    - juniper.device

  tasks:
    - name: Execute single RPC
      juniper.device.rpc:
        rpcs:
          - get-system-information
      register: rpc_single

    - name: Show single RPC
      debug:
        var: rpc_single.stdout

    - name: Execute multiple RPCs
      juniper.device.rpc:
        rpcs:
          - get-system-information
          - get-chassis-inventory
          - get-interface-information terse
        format: xml
      register: rpc_multi

    - name: Show multi RPC output
      debug:
        var: rpc_multi.stdout

Run

1
ansible-playbook -i inventory_native pb.native_rpc.yml

Sample Output (Excerpt)

1
2
3
stdout[0]: <system-information>...</system-information>
stdout[1]: <chassis-inventory>...</chassis-inventory>
stdout[2]: <interface-information>...</interface-information>

3. Executing RedHat RPC Using juniper.device Namespace

You can invoke the RedHat RPC module through juniper.device.junos_rpc.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
---
- name: Run RedHat RPC via juniper.device namespace
  hosts: junos
  gather_facts: false
  connection: ansible.netcommon.netconf
  collections:
    - juniper.device

  tasks:
    - name: Get system information
      juniper.device.junos_rpc:
        rpc: get-system-information
      register: compat_rpc

    - debug:
        var: compat_rpc.xml

4. Directory Structure Example

1
2
3
4
5
6
_playbooks/
  pb.redhat_rpc.yml
  pb.native_rpc.yml
  pb.compat_namespace_rpc.yml
inventory_rh
inventory_native

5. RPC Naming Patterns

Correct (hyphenated, lower-case):

1
2
3
4
get-system-information
get-chassis-inventory
get-interface-information
get-interface-information terse

Avoid:

1
2
get_system_information
Get-System-Information

6. RPC Usage Cheat Sheet

GoalRedHat PathNative Path
Single RPCrpc: get-system-informationrpcs: [get-system-information]
Multiple RPCsOne task per RPCrpcs: [list, of, rpcs]
XML output(default)format: xml
Basic text (CLI alt)Use junos_commandN/A (rpc is NETCONF)
Increase timeoutansible_command_timeout in inventorysame
Namespace compatibilityjunipernetworks.junos.junos_rpcjuniper.device.junos_rpc

Common return fields:

  • RedHat path: xml (full ), changed (False), failed
  • Native path: stdout (list of inner XML blocks), rpcs (list), changed (False), failed

7. Troubleshooting

SymptomCauseFix
ConnectionError get_capabilitiesNETCONF disabledset system services netconf ssh
Empty stdout/xmlMisspelled RPCVerify with show rpc
Timeout on inventory RPCLarge chassis / many FPCsIncrease ansible_command_timeout
Warning: NoneType .getLoader quirkIgnore if task succeeds
Auth failureBad credentials / SSHssh -s netconf
Multi-RPC fails mid-runOne RPC invalidValidate list individually

Quick diagnostics:

1
2
ssh -s netconf <device-ip>
nc -vz <device-ip> 830

Inventory timeout example:

1
ansible_command_timeout=300

8. Summary

  • RedHat junipernetworks.junos.junos_rpc runs unchanged within the juniper.device collection.
  • Native juniper.device.rpc supports multiple RPCs per task and cleaner inner XML output.
  • You can also call the RedHat RPC via juniper.device.junos_rpc namespace.
  • Both approaches coexist; adopt native for new automation while keeping existing playbooks intact.
This post is licensed under CC BY 4.0 by the author.