ab’s blog

インフラの呟きです。

Ansible ciscoのrunning-config取得

hahahahahaha

はじめに

Ansible使ったらやりたいことランキング上位(※個人の見解です)、シスコのランニングコンフィグ取得です。Ansibleの「ios_command」モジュールを使ってできました。

プレイブック例

※Ansible2.9で確認した内容です。「terminal length 0」は入れなくても大丈夫でした。

  hosts: all
  gather_facts: no
  connection: local

  tasks:
  - name: get running-config
    ios_command:
            commands: "show running-config"
            register: result

  - name: show result
    debug:
            msg: "{{ result }}"


  - name: バックアップフォルダ作成
    local_action:
            module: file
            path: "/tmp/backup/"
            state: directory
            owner: root
            group: root
            mode: 0755

  - name: ファイルとしてバックアップ
    local_action:
            module: copy
            content: "{{ result.stdout_lines | to_nice_json }}"
            dest: "/tmp/backup/{{ inventory_hostname }}_runnning_config.txt"

以上