AnsibleでIOS XEの設定を管理する2 / 7

Playbook

- name: Set the branch uplink description
  hosts: branch
  gather_facts: false
  serial: 1
  tasks:
    - name: Merge the intended interface command
      cisco.ios.ios_config:
        parents: interface GigabitEthernet0/1
        lines:
          - description LAB-UPLINK
        match: line
        save_when: modified
      register: change
    - name: Read the interface configuration
      cisco.ios.ios_command:
        commands:
          - show running-config interface GigabitEthernet0/1
      register: observed
      changed_when: false
    - name: Verify the description
      ansible.builtin.assert:
        that:
          - "'description LAB-UPLINK' in observed.stdout[0]"

parentsはcommandを入れる階層、linesは希望する行である。running-configと同じ表現で書くと、line比較による不要な再変更を減らせる。serial:1は一台ずつ処理する指定で、二台間の通信や冗長性の成功を自動保証するものではない。

学習パスへ
参考資料