Skip to content

Instantly share code, notes, and snippets.

@robphoenix
Created February 9, 2017 15:31

Revisions

  1. robphoenix created this gist Feb 9, 2017.
    82 changes: 82 additions & 0 deletions ios_command_example
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,82 @@
    ---
    - name: Create tmp Directory
    hosts: 127.0.0.1
    connection: local
    tasks:

    - name: Create tmp Directory
    file: path=../../tmp state=directory


    - name: Fetch running-config
    gather_facts: no
    hosts: stage_2_dev_1
    tasks:

    - name: Execute write mem
    ios_command:
    provider: "{{ provider }}"
    commands:
    - wr mem
    register: output

    - debug:
    var: output

    - name: Execute 'show run' command
    ios_command:
    provider: "{{ provider }}"
    commands:
    - show run
    register: output

    - name: Write 'show run' to file
    template:
    src: output.txt.j2
    dest: "../../tmp/{{ inventory_hostname }}-pre-running-config.txt"


    - name: Move files
    hosts: 127.0.0.1
    connection: local
    tasks:

    - name: Delete directory
    file: path=./backups/running_configs state=absent

    - name: Move files to shared directory
    command: mv ../../tmp ./backups/running_configs

    - name: Remove tmp Directory
    file: path=../../tmp state=absent


    - name: Reload
    gather_facts: no
    hosts: stage_2_dev_1
    tasks:

    - name: Reload in 15 minutes
    ntc_reboot:
    platform: cisco_ios_ssh
    username: "{{ ansible_user }}"
    password: "{{ ansible_password }}"
    host: "{{ ansible_host }}"
    confirm: true
    timer: 15
    register: output

    - debug:
    var: output

    - name: Change transport settings
    ios_config:
    provider: "{{ provider }}"
    lines:
    - transport input ssh
    - transport output ssh
    parents: line vty 0 15
    register: output

    - debug:
    var: output