Ansibleでcontrollerの設定を管理する3 / 4
Meraki APIをuriで扱う
controller専用moduleのほか、APIの契約へ沿ってansible.builtin.uriを使える。Merakiの既存VLAN名を変える構成では、GET→差分時だけPUT→GET/assertを行う。
- name: Read the existing VLAN
ansible.builtin.uri:
url: "https://api.meraki.com/api/v1/networks/{{ network_id }}/appliance/vlans/10"
method: GET
headers:
X-Cisco-Meraki-API-Key: "{{ meraki_key }}"
validate_certs: true
return_content: true
register: current
changed_when: false
no_log: true
- name: Set the VLAN name only when needed
ansible.builtin.uri:
url: "https://api.meraki.com/api/v1/networks/{{ network_id }}/appliance/vlans/10"
method: PUT
headers:
X-Cisco-Meraki-API-Key: "{{ meraki_key }}"
body_format: json
body: {name: Corp}
validate_certs: true
status_code: 200
when: current.json.name != 'Corp'
no_log: true
これはlocal playのtasksへ入れる部分例で、更新後も同じGETとassertで確認する。PUT taskを無条件にchanged_when:falseへして、実際の変更を隠さない。no_logは出力を抑制する。