mito’s blog

IT技術メインの雑記。思い立ったが吉日。

Ansible2.10とASAを立て、PlaybookでAccess Control Listを確認したときのメモ

やりたいこと

Ansible2.10もASAも初めてですが、ちょうど良い記事があったのでAnsible2.10でASAを触ってみました。
https://www.ansible.com/blog/ansible-security-automation-resource-modules

環境

Software Versions
Ansible 2.10.0b1
ASAv 9.13
ASDM 7.13

1.Ansible2.10の構築

こちらの記事を参考にしました。 https://tekunabe.hatenablog.jp/entry/2020/06/21/ansible_stumble_07

  • cisco.asa モジュールのインストール
    モジュールは、別途インストールします。
# ansible-galaxy collection install cisco.asa  -f 
Starting galaxy collection install process
Process install dependency map
|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-Starting collection install process
|Installing 'cisco.asa:1.0.0' to '/root/.ansible/collections/ansible_collections/cisco/asa'
/-\|/-\|/-\|/-\|/-\|Skipping 'ansible.netcommon' as it is already installed
# 
# ansible-galaxy collection list

# /root/.ansible/collections/ansible_collections
Collection           Version
-------------------- -------
ansible.netcommon    1.0.0  
ansible.posix        1.0.0  
cisco.asa            1.0.0  
community.general    0.2.0  
community.kubernetes 0.11.1 
google.cloud         0.10.1 
#

2.ASAの構築

  • 仮想アプライアンス
    AWS Marketplace の Cisco Adaptive Security Virtual Appliance (ASAv) - BYOLを使いました。

  • ログイン後の設定
    HTTPSの有効化とアクセス元の許可です。

ciscoasa> enable
The enable password is not set.  Please set it now.
Enter  Password: *******
Repeat Password: *******
Note: Save your configuration so that the password persists across reboots
("write memory" or "copy running-config startup-config").
ciscoasa# conf t
ciscoasa(config)#

***************************** NOTICE *****************************

Help to improve the ASA platform by enabling anonymous reporting,
which allows Cisco to securely receive minimal error and health
information from the device. To learn more about this feature,
please visit: http://www.cisco.com/go/smartcall

Would you like to enable anonymous error reporting to help improve
the product? [Y]es, [N]o, [A]sk later: a

ciscoasa(config)#
ciscoasa(config)# http server enable 443
ciscoasa(config)# http 【IPアドレス】 255.255.255.0 management      ☆接続元の許可
ciscoasa(config)# username 【ユーザ名】 password 【パスワード】 privilege 15 ☆ユーザ作成
ciscoasa(config)# exit
ciscoasa# write memory
Building configuration...
Cryptochecksum: 6b9b7d55 030f7cab 0597a569 40cd0d9d

7421 bytes copied in 0.180 secs
[OK]
ciscoasa#
  • ブラウザでアクセス
    https://XX.XX.XX.XX にアクセスすると、アプリのインストールが求められます。 今回はASDMをインストールしました。

  • ASDMの起動
    ASAのIP、ユーザ名、パスワードを入力します。

  • Interfaceの追加
    Configuration > Device Setup > Interface Settings > Interfaces より、 VNIインターフェイスを追加します。

    • IPaddress 10.1.0.1/16
  • ACLの追加 Configuration > Firewall > Access Rules より、 ACLを追加します。

3.inventoryとplaybookの作成

  • inventory
# cat inventory/inventory.ini
[asa]
ciscoasa ansible_host=XX.XX.XX.XX

[all:vars]
ansible_user=【ユーザ名】
ansible_password=【パスワード】
ansible_become=true
ansible_become_method=ansible.netcommon.enable
ansible_become_pass=【パスワード】
ansible_connection=ansible.netcommon.network_cli
ansible_network_os=cisco.asa.asa
ansible_python_interpreter=$(which python)


- playbook
追加したACLを表示します。

# cat asa_get-acl.yml
---
- name: Get structured data
  hosts: ciscoasa
  gather_facts: false
  collections:
  - cisco.asa

  tasks:
  - name: Gather facts
    asa_acls:
      state: gathered
    register: gather

  - name: output data
    debug:
      msg: "{{ gather }}"

4.playbookの実行

追加したACLが表示されました。

# ansible-playbook -i inventory/inventory.ini asa_get-acl.yml

PLAY [Get structured data] ************************************************

TASK [Gather facts] *******************************************************
ok: [ciscoasa]

TASK [output data] ********************************************************
ok: [ciscoasa] => {
    "msg": {
        "changed": false,
        "failed": false,
        "gathered": [
            {
                "acls": [
                    {
                        "aces": [
                            {
                                "destination": {
                                    "address": "10.2.0.0",
                                    "netmask": "255.255.0.0"
                                },
                                "grant": "permit",
                                "line": 1,
                                "protocol": "ip",
                                "protocol_options": {
                                    "ip": true
                                },
                                "source": {
                                    "any": true
                                }
                            }
                        ],
                        "acl_type": "extended",
                        "name": "global_access"
                    }
                ]
            }
        ]
    }
}

PLAY RECAP ****************************************************************
ciscoasa : ok=2  changed=0  unreachable=0  failed=0  skipped=0  rescued=0  ignored=0

雑記

動かすことはできたけど、理解はこれから。
あと雨が続くので、腹筋ローラーを買った。ブログを書かない、走らない日は腹筋を鍛えるしかない。