Skip to content

Instantly share code, notes, and snippets.

@dgarros
Last active October 20, 2016 18:54
Show Gist options
  • Save dgarros/9a9d943ee7d2231fa83800f8668afb89 to your computer and use it in GitHub Desktop.
Save dgarros/9a9d943ee7d2231fa83800f8668afb89 to your computer and use it in GitHub Desktop.
Ansible 2.1 - Junos Modules Playbook examples
Playbooks examples for Ansible 2.1
- name: run a set of commands
  junos_command:
    commands: ['show version', 'show ip route']
- name: run a command with a conditional applied to the second command
  junos_command:
    commands:
      - show version
      - show interfaces fxp0
    waitfor:
      - "result[1].interface-information.physical-interface.name eq fxp0"
- name: collect interface information using rpc
  junos_command:
    rpcs:
      - "get_interface_information interface=em0 media=True"
      - "get_interface_information interface=fxp0 media=True"
- name: load configuration lines in device
  junos_config:
    lines:
      - set system host-name {{ inventory_hostname }}
      - delete interfaces ge-0/0/0 description
    comment: update config
- name: rollback the configuration to id 10
  junos_config:
    rollback: 10
- name: zero out the current configuration
  junos_config:
    zeroize: yes
- name: confirm a candidate configuration
  junos_config:
- name: collect default set of facts
  junos_facts:
- name: collect default set of facts and configuration
  junos_facts:
    config: yes
- name: collect default set of facts and configuration in set format
  junos_facts:
    config: yes
    config_format: set
- name: collect default set of facts and configuration in XML and JSON format
  junos_facts:
    config: yes
    config_format: xml
@kkirsche
Copy link

For me, I can't get the JunOS modules to work. If I try a local connection like Juniper's role was I get the following even though I have paramiko installed:

fatal: [hostname.net]: FAILED! => {"changed": false, "failed": true, "msg": "paramiko is required but does not appear to be installed"}

if I try paramiko / default connection I get:

fatal: [hostname.net]: FAILED! => {"failed": true, "msg": "failed to transfer file to error: unknown command: /bin/sh/junos_netconf:\nsftp> put /var/folders/8y/pj9zz4b12r37490xnlqb7gb13tt57z/T/tmpTT4nw7 'error: unknown command: /bin/sh/junos_netconf'\n\nremote open(\"/var/home/username/error: unknown command: /bin/sh/junos_netconf\"): No such file or directory\r\n"}

Any tips on how to use these in a role / playbook rather than just the task?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment