はじめに
- 当記事は、日常の運用業務(NW機器設定)の自動化により、運用コストの削減 および 運用品質の向上 を目標に
「Ansible」を使用し、様々なNW機器設定を自動化してみようと 試みた記事です。
- Ansibleは、OSS版(AWX)+OSS版(Ansible)を使用しております。
PaloAltoの「Objects-サービス」の登録/変更/削除を実施してみた
事前設定
Playbook作成(YAML)
使用モジュール
- paloaltonetworks.panos.panos_service_object を使用。
※参考ページ:https://galaxy.ansible.com/ui/repo/published/paloaltonetworks/panos/content/module/panos_address_object/
接続情報(provider)の設定
Objects-サービスの登録
- 接続情報とサービス情報を指定して登録(state: ‘present’)を行う。
- name: Add Service1
paloaltonetworks.panos.panos_service_object:
provider: '{{ provider }}'
name: 'test_service001'
protocol: 'tcp'
destination_port: '10'
source_port: '110'
description: 'test_service001'
tag: ['test']
state: 'present'
register: wk_result
- 実行結果:対象のサービスが登録された。 ※Ansibleの実行結果(diff)を抜粋
"before": "",
"after" : "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<entry name=\"test_service001\">\n\t<protocol>\n\t\t<tcp>\n\t\t\t<source-port>110</source-port>\n\t\t\t<port>10</port>\n\t\t</tcp>\n\t</protocol>\n\t<description>test_service001</description>\n\t<tag>\n\t\t<member>test</member>\n\t</tag>\n</entry>\n"
Objects-サービスの変更 ※登録のつづき
- 接続情報とサービス情報を指定して 登録されたサービスの変更(state: ‘replaced’)を行う。 ※replacedの場合は、既存設定の置き換えとなる
- name: Change Service1
paloaltonetworks.panos.panos_service_object:
provider: '{{ provider }}'
name: 'test_service001'
protocol: 'tcp'
destination_port: '20'
source_port: '120'
description: 'test_service001'
# tag: ['test']
state: 'replaced'
register: wk_result
- 実行結果:登録時のtag指定ありのサービスが、Rreplaedによりtag指定なしのサービスに変更された。 ※Ansibleの実行結果(diff)を抜粋
"before": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<entry name=\"test_service001\">\n\t<protocol>\n\t\t<tcp>\n\t\t\t<source-port>110</source-port>\n\t\t\t<port>10</port>\n\t\t</tcp>\n\t</protocol>\n\t<description>test_service001</description>\n\t<tag>\n\t\t<member>test</member>\n\t</tag>\n</entry>\n",
"after" : "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<entry name=\"test_service001\">\n\t<protocol>\n\t\t<tcp>\n\t\t\t<source-port>120</source-port>\n\t\t\t<port>20</port>\n\t\t</tcp>\n\t</protocol>\n\t<description>test_service001</description>\n</entry>\n"
- 接続情報とサービス情報を指定して 登録されたサービスの変更(state: ‘merged’)を行う。 ※mergedの場合は、既存設定の上書きとなる
- name: Change Service2
paloaltonetworks.panos.panos_service_object:
provider: '{{ provider }}'
name: 'test_service001'
protocol: 'tcp'
destination_port: '30'
source_port: '130'
# description: 'test_service001'
tag: ['test']
state: 'merged'
register: wk_result
- 実行結果:上記変更時のtag指定なしのサービスが、mergedによりtag指定ありのサービスに変更された。また、サービス情報にdescriptionを指定しなくても、既存設定が維持されていることを確認。 ※Ansibleの実行結果(diff)を抜粋
"before": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<entry name=\"test_service001\">\n\t<protocol>\n\t\t<tcp>\n\t\t\t<source-port>120</source-port>\n\t\t\t<port>20</port>\n\t\t</tcp>\n\t</protocol>\n\t<description>test_service001</description>\n</entry>\n",
"after" : "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<entry name=\"test_service001\">\n\t<protocol>\n\t\t<tcp>\n\t\t\t<source-port>130</source-port>\n\t\t\t<port>30</port>\n\t\t</tcp>\n\t</protocol>\n\t<description>test_service001</description>\n\t<tag>\n\t\t<member>test</member>\n\t</tag>\n</entry>\n"
Objects-サービスの情報収集 ※変更のつづき
- 接続情報とサービスを指定して情報収集(state: ‘gathered’)を行う。
- name: Get Service Info
paloaltonetworks.panos.panos_service_object:
provider: '{{ provider }}'
name: 'test_service001'
state: 'gathered'
register: wk_result
- 実行結果:対象サービスの情報が取得できた。 ※Ansibleの実行結果(gathered_xml)を抜粋
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<entry name=\"test_service001\">\n\t<protocol>\n\t\t<tcp>\n\t\t\t<source-port>130</source-port>\n\t\t\t<port>30</port>\n\t\t</tcp>\n\t</protocol>\n\t<description>test_service001</description>\n\t<tag>\n\t\t<member>test</member>\n\t</tag>\n</entry>\n",
Objects-サービスの削除 ※変更のつづき
- 接続情報とサービスを指定して削除(state: ‘absent’)を行う。
- name: Delete Service1
paloaltonetworks.panos.panos_service_object:
provider: '{{ provider }}'
name: 'test_service001'
state: 'absent'
register: wk_result
- 実行結果:対象のサービスが削除された。 ※Ansibleの実行結果(diff)を抜粋
"before": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<entry name=\"test_service001\">\n\t<protocol>\n\t\t<tcp>\n\t\t\t<source-port>130</source-port>\n\t\t\t<port>30</port>\n\t\t</tcp>\n\t</protocol>\n\t<description>test_service001</description>\n\t<tag>\n\t\t<member>test</member>\n\t</tag>\n</entry>\n",
"after" : ""
最後に
- 「Ansible」の「paloaltonetworks.panos.panos_service_object」を使用し、「Objects-サービス」の登録/変更/削除 および 情報収集ができたことは良かった。何らかの変更申請の仕組みと連携することで、より 設定変更の自動化 が活用できるようになると考える。
- 現状 設定情報がベタ書きで使い勝手が悪いので、今後 設定内容をINPUTする仕組みを試みたいと思います。
また、引続き 他にも様々なNW機器設定を自動化してみようと思います。