Ansible・Python・Terraform CLIの設計1 / 6
装置へ接続するAnsible
Inventoryは接続する対象と変数を定める。NX-OSへCLIで接続する例では、network_cli接続、OSプラグイン、cisco.nxosコレクションのモジュールを組み合わせる。
- name: Configure a device interface
hosts: leaves
gather_facts: false
connection: ansible.netcommon.network_cli
vars:
ansible_network_os: cisco.nxos.nxos
tasks:
- name: Set the uplink description
cisco.nxos.nxos_interfaces:
config:
- name: Ethernet1/1
description: UPLINK
enabled: true
state: merged
このPlayはleavesへ接続し、指定した属性を既存の構成へマージする。merged、replaced、overriddenは管理する範囲と既存値の扱いが違う。広い範囲を置き換えるstateを選ぶと、意図しない既存設定を消す場合がある。renderedは機器へ反映せずにコマンドを生成し、gatheredは状態を取得する。changedはモジュールが変更したという結果であり、通信の成功や全体の要件達成まで表さない。