【AnsibleでCisco機器にconfigを投入する基本的な流れ】 ~playbook実行とconfigをGithubにpushするまで~1回目

 【 社内ハンズオン動画 】

 

【 社内ハンズオン概要 】

  • 1回目、roleを作成する。static追加role、ホスト名設定role、wr memするroleの3つ作成。
  • 2回目、作成したrollを実行するplaybookにする。インベントリーを作成する。playbookを実行する。
  • 3回目、playbookのymlと保存したconfigをgit commit する。ローカルgitからリモートのgithubにgit pushする

 

【 構成図 】

f:id:pinn38:20190331134204p:plain

 

★1回目-1 Ansibleサーバにコンソール接続しsuに移行

 su -

 

★1回目-2 ディレクトリ移動

cd /etc/ansible/roles/

 

★1回目-3 static追加role作成

ディレクトリ作成

cp -r common/ cisco_static2

vi cisco_static2/tasks/main.yml

---
- name: configure static route
  ios_static_route:
    prefix: 192.168.200.0
    mask: 255.255.255.0
    next_hop: 192.168.100.200
#    state: absent
    state: present
- name: Add static route aggregates
  ios_static_route:
    aggregate:
      - { prefix: 172.16.32.0, mask: 255.255.255.0, next_hop: 192.168.100.200 }
      - { prefix: 172.16.33.0, mask: 255.255.255.0, next_hop: 192.168.100.200 }
      - { prefix: 7.7.7.7, mask: 255.255.255.255, next_hop: 10.100.12.185 }
#    state: absent
    state: present

★1回目-4 ホスト名設定role作成

ディレクトリ作成

cp -r common/ cisco_hostname2

vi cisco_hostname2/tasks/main.yml

---
- name: configure top level configuration 
  ios_config:    
    lines: hostname {{ inventory_hostname }}    


★1回目-5 wr memを実行するrole作成

ディレクトリ作成

cp -r common/ cisco_wr_m2

vi cisco_wr_m2/tasks/main.yml

---
- name: check the startup-config against the running-config
  ios_config:
    diff_against: startup
    diff_ignore_lines:
      - ntp clock .*

- name: save running to startup when modified
  ios_config:
    save_when: modified