4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AnsibleでCisco IOSの情報収集 - snmp_facts

Last updated at Posted at 2017-03-23

#背景
AnsibleでCisco IOSの情報収集 - ios_factsの続編。今回はsnmp_factsの記録。Cisco用ではなく汎用モジュールなので、ベンダー意識しなくていい点と、MIB基準(?)で情報取得したい(でもsnmpgetとかしたくない)場合に使えるかも。

※ansible.cfgやinventoryの設定は省略。
※環境はこちらと同じなので省略。

#Playbookサンプル - snmp_facts

snmp_facts.yml
---
- hosts: ios
  gather_facts: False
  connection: local
  tasks:
    - name: snmp_facts
      snmp_facts:
        host: '{{ inventory_hostname }}'
        version: v2c
        community: public
      register: snmpfacts_out

    - debug: var=snmpfacts_out

#実行例
情報量が多くないので、debug出力のみにしたが、ファイルに保存して、ネットワークの全インターフェース調査などを(楽に)行っても良い。

snmp_facts.yml
[vagrant@localhost ansible]$ ansible-playbook snmp_facts.yml 

PLAY [ios] *********************************************************************

TASK [snmp_facts] **************************************************************
ok: [10.71.130.58]

TASK [debug] *******************************************************************
ok: [10.71.130.58] => {
    "snmpfacts_out": {
        "ansible_facts": {
            "ansible_all_ipv4_addresses": [
                "10.71.130.58"
            ], 
            "ansible_interfaces": {
                "1": {
                    "adminstatus": "up", 
                    "description": "", 
                    "ifindex": "1", 
                    "ipv4": [
                        {
                            "address": "10.71.130.58", 
                            "netmask": "255.255.248.0"
                        }
                    ], 
                    "mac": "005056a26a84", 
                    "mtu": "1500", 
                    "name": "GigabitEthernet1", 
                    "operstatus": "up", 
                    "speed": "1500"
                }, 
                "2": {
                    "adminstatus": "down", 
                    "description": "", 
                    "ifindex": "2", 
                    "mac": "005056a2aa72", 
                    "mtu": "1500", 
                    "name": "GigabitEthernet2", 
                    "operstatus": "down", 
                    "speed": "1500"
                }, 
                "3": {
                    "adminstatus": "down", 
                    "description": "", 
                    "ifindex": "3", 
                    "mac": "005056a25883", 
                    "mtu": "1500", 
                    "name": "GigabitEthernet3", 
                    "operstatus": "down", 
                    "speed": "1500"
                }, 
                "4": {
                    "adminstatus": "up", 
                    "description": "", 
                    "ifindex": "4", 
                    "mac": "", 
                    "mtu": "1500", 
                    "name": "VoIP-Null0", 
                    "operstatus": "up", 
                    "speed": "1500"
                }, 
                "5": {
                    "adminstatus": "up", 
                    "description": "", 
                    "ifindex": "5", 
                    "mac": "", 
                    "mtu": "1500", 
                    "name": "Null0", 
                    "operstatus": "up", 
                    "speed": "1500"
                }, 
                "6": {
                    "adminstatus": "up", 
                    "description": "", 
                    "ifindex": "6", 
                    "mac": "", 
                    "mtu": "1514", 
                    "name": "Loopback0", 
                    "operstatus": "up", 
                    "speed": "1514"
                }
            }, 
            "ansible_syscontact": "", 
            "ansible_sysdescr": "Cisco IOS Software [Everest], CSR1000V Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.4.1, RELEASE SOFTWARE (fc2)\r\nTechnical Support: http://www.cisco.com/techsupport\r\nCopyright (c) 1986-2016 by Cisco Systems, Inc.\r\nCompiled Sun 27-Nov-16 13:02 by", 
            "ansible_syslocation": "", 
            "ansible_sysname": "CSR-2.solse.local", 
            "ansible_sysobjectid": "1.3.6.1.4.1.9.1.1537", 
            "ansible_sysuptime": "28502267"
        }, 
        "changed": false
    }
}

PLAY RECAP *********************************************************************
10.71.130.58               : ok=2    changed=0    unreachable=0    failed=0  

#Playbookサンプル2 - snmp_facts

この装置のsysoidなんだっけ?(でもsnmpwalkしたくない)。

snmp_facts_2.yml
---
- hosts: ios
  gather_facts: False
  connection: local
  tasks:
    - name: snmp_facts
      snmp_facts:
        host: '{{ inventory_hostname }}'
        version: v2c
        community: public
      register: snmpfacts_out

    - debug: var=snmpfacts_out["ansible_facts"]["ansible_sysobjectid"]

#実行例

snmp_facts_2.yml
[vagrant@localhost ansible]$ ansible-playbook snmp_facts_2.yml 

PLAY [ios] *********************************************************************

TASK [snmp_facts] **************************************************************
ok: [10.71.130.58]

TASK [debug] *******************************************************************
ok: [10.71.130.58] => {
    "snmpfacts_out[\"ansible_facts\"][\"ansible_sysobjectid\"]": "1.3.6.1.4.1.9.1.1537"
}

PLAY RECAP *********************************************************************
10.71.130.58               : ok=2    changed=0    unreachable=0    failed=0 

以上です。ちょっと出来ることは少ないかも。お粗末さまでした。

4
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?