著者:平田 千浩
「Red Hat Ansible Automation Platform」は、OSS のAnsibleとAWXを基とした企業向け自動化の基盤です。RHELを含むさまざまなOS、さまざまなアプリケーション、さまざまな機器に対応し、局所的な作業からバージョン管理システムと連携した構成管理までを自動化できます。
シェルスクリプトマガジン Vol.66は以下のリンク先でご購入できます。![]()
![]()
図2 インベントリファイルの例(hosts)
[all:vars]
ansible_ssh_private_key_file=/home/student1/.ssh/aws-private.pem
[ios]
ios1 ansible_host=XX.XX.XX.XX
[ios:vars]
ansible_user=ec2-user
ansible_network_os=ios
ansible_connection=network_cli
図3 Cisco IOS向けの簡単なPlaybookの例(snmp.yml)
---
- name: snmp ro / rw string configuration
hosts: ios
gather_facts: no
tasks:
- name: ensure that the desired snmp strings are present
ios_config:
commands:
- snmp-server community ansible-public RO
- snmp-server community ansible-private RW
図6 Arista EOSを追加したインベントリファイル例(hosts)
[all:vars]
ansible_ssh_private_key_file=/home/student1/.ssh/aws-private.pem
[ios]
ios1 ansible_host=XX.XX.XX.XX
[ios:vars]
ansible_user=ec2-user
ansible_network_os=ios
ansible_connection=network_cli
[eos]
eos1 ansible_host=YY.YY.YY.YY
[eos:vars]
ansible_user=ec2-user
ansible_network_os=eos
ansible_connection=network_cli
ansible_become=true
ansible_become_method=enable
[control]
ansible ansible_host=AA.AA.AA.AA ansible_user=student1 ansible_password=PASSWORD
図7 Arista EOSのコンフィグをバックアップするPlaybookの例(eos_backup.yml)
---
- name: retrieve router configurations
hosts: eos
gather_facts: no
tasks:
- name: BACKUP THE CONFIG
eos_config:
backup: yes
register: config_output
- name: Save THE CONFIG
vars:
ansible_connection: ssh
copy:
src: "{{config_output.backup_path}}"
dest: "/backup/{{inventory_hostname}}"
delegate_to: ansible
become: yes
図10 CISCO IOSのコンフィグをバックアップするPlaybookの例
- name: retrieve router configurations
hosts: ios
gather_facts: no
tasks:
- name: BACKUP THE CONFIG
ios_config:
backup: yes
register: config_output
- name: REMOVE NON CONFIG LINES - REGEXP
lineinfile:
path: "{{config_output.backup_path}}"
line: "Building configuration..."
state: absent
- name: Save THE CONFIG
vars:
ansible_connection: ssh
copy:
src: "{{config_output.backup_path}}"
dest: "/backup/{{inventory_hostname}}"
delegate_to: ansible
become: yes
図11 保存したArista EOSのコンフィグからリストアするPlaybookの例(eos_restore.yml)
---
- name: Restore the EOS Config
hosts: eos
gather_facts: no
tasks:
- name: RESTORE THE CONFIG
eos_config:
replace: config
src: "/backup/{{inventory_hostname}}"
図12 保存したCisco IOSのコンフィグからリストアするPlaybookの例
---
- name: Restore the IOS Config
hosts: ios
gather_facts: no
tasks:
- name: RESTORE THE CONFIG
ios_config:
src: "/backup/{{inventory_hostname}}"