junos_rpc - run given rpc

Author:Nitin Kumar, Juniper Networks

Synopsis

New in version 1.9.

run given rpc

Options

parameter required default choices comments
dest no None
    Path to the local server directory where configuration will be saved.
    filter_xml no
      This options can be used with get-config rpc only, to retrieve specific config
      format no xml
      • text
      • xml
      • json
      text - configuration saved as text (curly-brace) format. xml - configuration saved as XML. json - configuration saved as json, supported only for devices >=14.2 Also with this format, rpc_reply attribute can be used with results
      host yes
        Set to {{ inventory_hostname }}
        kwargs no
          params need to be passed to rpc kwargs="interface_name=em0" or kwargs="interface_name=em0,media=True" kwargs={interface_name:em0} kwargs={interface_name:em0,media:True}
          logfile no None
            Path on the local server where the progress status is logged for debugging purposes. This option is used only with the console option.
            mode no None
              mode of console connection (telnet/serial). If mode is not provided SSH connection is used.
              passwd no assumes ssh-key active
                Login password
                port no 830
                  port number to use when connecting to the device
                  rpc no
                    rpc to be executed
                    timeout no 0
                      Set the NETCONF RPC timeout. Set this value to accommodate Cli commands that might take longer than the default timeout interval. Setting to 0 will use the PyEZ default (30 seconds).
                      user no $USER
                        Login username

                        Note

                        Requires junos-eznc >= 1.2.2

                        Examples


                        # retrieve rpc response using NETCONF
                        
                        - junos_rpc:
                          host={{ inventory_hostname }}
                          rpc=get-interface-information
                          dest=get_interface_information.conf
                          register=junos
                        
                        - junos_rpc:
                          host={{ inventory_hostname }}
                          rpc=get-interface-information
                          kwargs="interface_name=em0"
                          format=xml/text/json
                          dest=get_interface_information.conf
                          register=junos
                        
                        # Example to fetch device configuration
                        - name: Get Device Configuration
                          junos_rpc:
                            host={{ inventory_hostname }}
                            rpc=get-config
                            dest=get_config.conf
                        
                        # Fetch configuration over console server connection using PyEZ >= 2.0
                        - name: Get Device Configuration
                          junos_rpc:
                            host={{ inventory_hostname }}
                            port=7005
                            mode='telnet'
                            rpc=get-config
                            dest=get_config.conf
                        
                        # Example to fetch device configuration
                        - name: Get Device Configuration for interface
                          junos_rpc:
                            host={{ inventory_hostname }}
                            rpc=get-config
                            filter_xml="<configuration><interfaces/></configuration>"
                            dest=get_config.conf
                          register: junos
                        
                        # Example to fetch configuration in json for >=14.2
                        # and use it with rpc_reply
                        - name: Get Device Configuration
                          hosts: all
                          roles:
                            - Juniper.junos
                          connection: local
                          gather_facts: no
                          tasks:
                            - name: Get interface information
                              junos_rpc:
                                host={{ inventory_hostname }}
                                rpc=get-interface-information
                                kwargs={interface_name:em0,media:True}
                                format=json
                                dest=get_interface_information.conf
                              register: junos
                        
                            - name: Print configuration
                              debug: msg="{{ junos.rpc_reply }}"