30
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ansible-playbook内でもYAMLのマージ記法が使えます! Cisco ios_commandモジュールなどでどうぞ。

Last updated at Posted at 2016-04-13

はじめに

AnsibleのplaybookはYAML形式で記述するので重複する行などを
以下の通りYAMLのマージ記法(<< : &,<< : *)で表現できます。
重複を排除できるのでスマートに書けます。

以下はCisco機器へのios_commandモジュールでの使用例です。

なお、AnsibleでのCisco関連のモジュールの使い方については
同僚の記事も参照してください。

環境

  • Ansible version:2.1.0 (gitでインストール)
  • CentOS6.7 / OSX Yosemite
[root@ansible cisco]# ansible --version
ansible 2.1.0 (devel 81788e627d) last updated 2016/03/14 06:41:49 (GMT +000)
  lib/ansible/modules/core: (detached HEAD c86a0ef84a) last updated 2016/03/14 02:09:35 (GMT +000)
  lib/ansible/modules/extras: (detached HEAD 33a557cc59) last updated 2016/03/14 02:09:54 (GMT +000)
  config file = /opt/cisco/ansible.cfg
  configured module search path = Default w/o overrides
  • Cisco

    • IOS version 12.2
    • Catalyst3560-E
  • インベントリファイル
    hosts

[cisco]
192.168.1.1
192.168.1.2

[cisco:vars]
cisco_enable_secret=cisco
ansible_user=ansible
ansible_password=ansible
ios_command.yml
---
- hosts: cisco
  gather_facts: no
  tasks:
   - name: sh run by cisco ios_command module
     local_action:
       module:   ios_command
       commands: sh run
       << : &IOS_INFO
         host:     "{{ inventory_hostname }}"
         username: "{{ ansible_user }}"
         password: "{{ ansible_password }}"
         authorize: true
         auth_pass: "{{ cisco_enable_secret }}"
     register: result
   - debug: var=result.stdout_lines
   - name: sh int by cisco ios_command module
     local_action:
       module:   ios_command
       commands: sh int
       << : *IOS_INFO
     register: result
   - debug: var=result.stdout_lines
30
31
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?