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.
            passwd no assumes ssh-key active
              Login password
              rpc no
                rpc to be executed
                user no $USER
                  Login username

                  Note

                  Requires junos-eznc >= 1.0.0

                  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
                  
                  # 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 }}"