Perform an SNMP set against a remote device for one or more OIDs
Version added: 1.0.0
- Perform an SNMP get against a remote device for one or more OIDs
Parameter |
Choices/Defaults |
Comments |
oids
list
/ elements=dictionary
/ required
|
|
A dictionary of OID, value to set on the remote device
|
|
iid
string
/ required
|
|
The dotted-decimal, instance identifier, for scalar MIB objects use '0'
|
|
oid
string
/ required
|
|
The OID to update.
aliases: tag
|
|
type
string
|
Choices:
- OBJECTID
- OCTETSTR
- INTEGER
- NETADDR
- IPADDR
- COUNTER
- COUNTER64
- GAUGE
- UINTEGER
- TICKS
- OPAQUE
- NULL
|
The type of value
|
|
value
raw
/ required
|
|
The value to be set for the OID.
aliases: val
|
Note
- The SNMP set task will always return 'changed'
- Tested against ubuntu 18.04 using net-snmp.
- This module works with connection
v1
, v2c
, v3_usm
.
# Update 2 individual entries
- name: Set several individual OIDs
ansible.snmp.set:
oids:
- oid: "SNMPv2-MIB::sysContact"
iid: "0"
value: "cidrblock @ {{ ts }}"
- oid: "SNMPv2-MIB::sysLocation"
iid: "0"
value: "Office @ {{ ts }}"
vars:
ts: '{{ lookup(''pipe'', ''date -u +"%Y-%m-%dT%H:%M:%SZ"'') }}'
# Update the description of all interfaces matching a regex
- name: Retrieve the index and name from the interface table
ansible.snmp.walk:
oids:
- oid: IF-MIB::ifIndex
- oid: IF-MIB::ifDescr
register: if_indicies
- name: Set a timestamp and the regex to use for matching interface names
set_fact:
ts: '{{ lookup(''pipe'', ''date -u +"%Y-%m-%dT%H:%M:%SZ"'') }}'
regex: "(Ethernet|Gigabit|Intel).*"
- name: Update all matching interfaces
ansible.snmp.set:
oids:
- oid: IF-MIB::ifAlias
iid: "{{ iid }}"
value: "Configured by ansible @ {{ ts }}"
vars:
matching_interfaces: "{{ lookup('ansible.utils.index_of', if_indicies.result, 'match', regex, 'ifDescr', wantlist=True) }}"
iid: "{{ if_indicies['result'][int_id]['ifIndex'] }}"
loop: "{{ matching_interfaces }}"
loop_control:
loop_var: int_id
register: changes
- name: Review all changes
ansible.utils.fact_diff:
before: "{{ interface.before.result|ansible.utils.to_paths }}"
after: "{{ interface.after.result|ansible.utils.to_paths }}"
loop: "{{ changes.results }}"
loop_control:
loop_var: interface
index_var: idx
label: "{{ idx }}"
Common return values are documented here, the following are the fields unique to this module:
Key |
Returned |
Description |
after
dictionary
|
always |
The result of an SNMP get for the OIDs after the set
Sample:
{'raw': {'description': 'The raw result from the snmp walk', 'returned': 'always', 'type': 'list', 'elements': 'dict', 'entries': {'iid': {'description': 'The instance id', 'returned': 'always', 'type': 'str'}, 'tag': {'description': 'The OID', 'returned': 'always', 'type': 'str'}, 'type': {'description': 'The type of the value', 'returned': 'always', 'type': 'str'}, 'value': {'description': 'The currently set value for the oid', 'returned': 'always', 'type': 'raw'}}}, 'result': {'description': 'The transformed result from the snmp walk', 'returned': 'always', 'type': 'list', 'elements': 'dict', 'entries': {'_raw': {'description': 'The individual oid entry and the currently set value', 'returned': 'always'}}}}
|
before
dictionary
|
always |
The result of an SNMP get for the OIDs prior to set
Sample:
{'raw': {'description': 'The raw result from the snmp walk', 'returned': 'always', 'type': 'list', 'elements': 'dict', 'entries': {'iid': {'description': 'The instance id', 'returned': 'always', 'type': 'str'}, 'tag': {'description': 'The OID', 'returned': 'always', 'type': 'str'}, 'type': {'description': 'The type of the value', 'returned': 'always', 'type': 'str'}, 'value': {'description': 'The currently set value for the oid', 'returned': 'always', 'type': 'raw'}}}, 'result': {'description': 'The transformed result from the snmp walk', 'returned': 'always', 'type': 'list', 'elements': 'dict', 'entries': {'_raw': {'description': 'The individual oid entry and the currently set value', 'returned': 'always'}}}}
|
elapsed
dictionary
|
always |
The amount of time in seconds spent for the snmp calls
Sample:
{'post_set_get': {'description': 'The amount of time spent in seconds for the get after the set', 'type': 'float', 'returned': 'always'}, 'pre_set_get': {'description': 'The amount of time spent in seconds for the get prior to the set', 'type': 'float', 'returned': 'always'}, 'set': {'description': 'The amount of time spent in seconds for the set', 'type': 'float', 'returned': 'always'}, 'total': {'description': 'the amount of time spent on all snmp calls', 'type': 'float', 'returned': 'always'}}
|
- Bradley Thornton (@cidrblock)