community.general.snmp_facts module – Retrieve facts for a device using SNMP

Note

This module is part of the community.general collection (version 9.4.0).

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: community.general.snmp_facts.

Synopsis

  • Retrieve facts for a device using SNMP, the facts will be inserted to the ansible_facts key.

Requirements

The below requirements are needed on the host that executes this module.

  • pysnmp

Parameters

Parameter

Comments

authkey

string

Authentication key.

Required version=v3.

community

string

The SNMP community string, required if version is v2 or v2c.

host

string / required

Set to target SNMP server (normally {{ inventory_hostname }}).

integrity

string

Hashing algorithm.

Required if version=v3.

Choices:

  • "md5"

  • "sha"

level

string

Authentication level.

Required if version=v3.

Choices:

  • "authNoPriv"

  • "authPriv"

privacy

string

Encryption algorithm.

Required if level=authPriv.

Choices:

  • "aes"

  • "des"

privkey

string

Encryption key.

Required if level=authPriv.

retries

integer

added in community.general 2.3.0

Maximum number of request retries, 0 retries means just a single request.

timeout

integer

added in community.general 2.3.0

Response timeout in seconds.

username

string

Username for SNMPv3.

Required if version=v3.

version

string / required

SNMP Version to use, v2, v2c or v3.

Choices:

  • "v2"

  • "v2c"

  • "v3"

Attributes

Attribute

Support

Description

check_mode

Support: full

added in community.general 3.3.0

This action does not modify state.

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: N/A

This action does not modify state.

Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode.

facts

Support: full

Action returns an ansible_facts dictionary that will update existing host facts.

Examples

- name: Gather facts with SNMP version 2
  community.general.snmp_facts:
    host: '{{ inventory_hostname }}'
    version: v2c
    community: public
  delegate_to: local

- name: Gather facts using SNMP version 3
  community.general.snmp_facts:
    host: '{{ inventory_hostname }}'
    version: v3
    level: authPriv
    integrity: sha
    privacy: aes
    username: snmp-user
    authkey: abc12345
    privkey: def6789
  delegate_to: localhost

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

ansible_all_ipv4_addresses

list / elements=string

List of all IPv4 addresses.

Returned: success

Sample: ["127.0.0.1", "172.17.0.1"]

ansible_interfaces

dictionary

Dictionary of each network interface and its metadata.

Returned: success

Sample: {"1": {"adminstatus": "up", "description": "", "ifindex": "1", "ipv4": [{"address": "127.0.0.1", "netmask": "255.0.0.0"}], "mac": "", "mtu": "65536", "name": "lo", "operstatus": "up", "speed": "65536"}, "2": {"adminstatus": "up", "description": "", "ifindex": "2", "ipv4": [{"address": "192.168.213.128", "netmask": "255.255.255.0"}], "mac": "000a305a52a1", "mtu": "1500", "name": "Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)", "operstatus": "up", "speed": "1500"}}

ansible_syscontact

string

The textual identification of the contact person for this managed node, together with information on how to contact this person.

Returned: success

Sample: "Me <me@example.org>"

ansible_sysdescr

string

A textual description of the entity.

Returned: success

Sample: "Linux ubuntu-user 4.4.0-93-generic"

ansible_syslocation

string

The physical location of this node (for example, telephone closet, 3rd floor).

Returned: success

Sample: "Sitting on the Dock of the Bay"

ansible_sysname

string

An administratively-assigned name for this managed node.

Returned: success

Sample: "ubuntu-user"

ansible_sysobjectid

string

The vendor’s authoritative identification of the network management subsystem contained in the entity.

Returned: success

Sample: "1.3.6.1.4.1.8072.3.2.10"

ansible_sysuptime

integer

The time (in hundredths of a second) since the network management portion of the system was last re-initialized.

Returned: success

Sample: 42388

Authors

  • Patrick Ogenstad (@ogenstad)