Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


https://junos-ansible-modules.readthedocs.io/en/2.3.0/juniper_junos_rpc.html

...

https://www.juniper.net/documentation/en_US/junos-ansible/topics/task/configuration/junos-ansible-authenticating-users.html




rpc command


Code Block
titlerpc command
root@SRX300-1-RL102> show chassis hardware detail | display xml rpc
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/19.4R0/junos">
    <rpc>
        <get-chassis-inventory>
                <detail/>
        </get-chassis-inventory>
    </rpc>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>




ssh root@172.30.95.174 -p 830 -s netconf 
ansible.cfg file


Code Block
titleansible.cfg
labuser@saltsackmaster:~/project/ansible/gethw$ more ansible.cfg
[defaults]
ansible_python_interpreter=/usr/bin/python3
deprecation_warnings=False


Ansible hosts file


Code Block
titlehosts
collapsetrue
labuser@saltsackmaster:~/project/ansible/gethw$ more hosts
[All
-devices]
_95_netw:vars]
ansible_python_interpreter=/usr/bin/python3

[All
-srx]
_95_netw]
172.30.95.170
172.30.95.171
172.30.95.172
172.30.95.174
[QFX5100]
172.30.95.176
172.30.95.177
[EX4300]
172.30.95.197
172.30.95.207
172.30.95.210
172.30.95.
194
212



Ansible playbook


Code Block
titleplaybook
labuser@saltsackmaster:~/project/ansible/gethw$ more rpc_chassishw.yml
---
- name: Get facts
  hosts: All
-srx
_95_netw
  
connection
gather_facts: 
local
no
  
gather_facts
connection: 
no
local
  roles:
    - Juniper.junos
 
  tasks:
    - name: Get Chassis Hardware information
      juniper_junos_rpc:
        host: "{{ inventory_hostname }}" 
        user: "Netbox"
        passwd: "Netbox"
        
#savedir
dest_dir: "{{playbook_dir}}/inventory"
        rpcs:
          - "get-chassis-inventory"
        kwargs:

         
-
 detail: 
True
true
        formats: "xml"
      
dest
register: 
"chassis_hardware.xml"
junos
      
register:
# 
junos
   - name: Print facts
      
debug
#debug:
      #  var: junos.stdout