Created
April 11, 2018 07:34
-
-
Save mjuenema/18298ee770259319833683d936d34f6d to your computer and use it in GitHub Desktop.
Map SNMPv2::sysDescr.0 to ansible_network_os (or any other OS tag)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import (absolute_import, division, print_function) | |
__metaclass__ = type | |
DOCUMENTATION = """ | |
lookup: sysdescr2os | |
author: Markus Juenemann <markus@juenemann.net> | |
version_added: "2.5" | |
short_description: Derive OS from SNMPv2::sysDescr.0 | |
description: | |
- "Derive the OS from the SNMPv2::sysDescr.0. This lookup is meant ot be used in combination | |
with the `snmp_facts` modules and the `ansible_sysdescr` it returns." | |
options: | |
_terms: | |
description: the value of SNMPv2::sysDescr.0. | |
required: True | |
notes: | |
- This lookup is based on snmp_autodetect.py from Kirk Byers' netmiko library but the | |
returned value is one of the Ansible network module prefixes, e.g. 'eos', 'ios', 'panos'. | |
""" | |
EXAMPLES = """ | |
- set_facts: ansible_network_os="{{ lookup('sysdescr2os', ansible_sysdescr) }}" | |
""" | |
from ansible.errors import AnsibleError | |
from ansible.plugins.lookup import LookupBase | |
try: | |
from __main__ import display | |
except ImportError: | |
from ansible.utils.display import Display | |
display = Display() | |
OS_MAP = { | |
"Arista Networks EOS": "eos", | |
"Cisco IOS Software": "ios", | |
"IOS-XE Software": "ios", # Do ios_* modules work on IOS-XE??? | |
"Cisco IOS XR Software": "iosxr", | |
"Cisco Adaptive Security Appliance": "asa", | |
"Cisco NX-OS": "nxos", | |
"BIG-IP": "bigip", | |
"Forti": "fortios", | |
"Junos OS": "junos", | |
"JUNOS ": "junos", | |
# TO BE EXPANDED | |
} | |
class LookupModule(LookupBase): | |
def run(self, terms, variables=None, **kwargs): | |
sysdescr = terms[0] | |
for key,value in OS_MAP.items(): | |
if key in sysdescr: | |
return [value] | |
return [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment