Adding Netbox
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2018 Red Hat
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'network'}
|
||||
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: command_parser
|
||||
short_description: Parses text into JSON facts based on rules
|
||||
description:
|
||||
- Provides a rules base text parser that is closely modeled after the Ansible
|
||||
playbook language. This parser will iterate of the rules and parse the
|
||||
output of structured ASCII text into a JSON data structure that can be
|
||||
added to the inventory host facts.
|
||||
version_added: "2.5"
|
||||
options:
|
||||
dir:
|
||||
description:
|
||||
- The path to the directory that contains the parsers. The module will
|
||||
load all parsers found in this directory and pass the content through
|
||||
the them. This argument is mutually exclusive with C(file).
|
||||
default: null
|
||||
file:
|
||||
description:
|
||||
- The path to the parser to load from disk on the Ansible
|
||||
controller. This can be either the absolute path or relative path.
|
||||
This argument is mutually exclusive with C(dir).
|
||||
Default path is {{ playbook_dir }}/parser_templates/{{ ansible_network_os }}
|
||||
or {{ playbook_dir }}/parser_templates or {{ playbook_dir }}
|
||||
default: "{{ playbook_dir }}/parser_templates/{{ ansible_network_os }}"
|
||||
content:
|
||||
description:
|
||||
- The text content to pass to the parser engine. This argument provides
|
||||
the input to the text parser for generating the JSON data.
|
||||
required: true
|
||||
author:
|
||||
- Peter Sprygada (@privateip)
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- command_parser:
|
||||
file: files/parser_templates/show_interface.yaml
|
||||
content: "{{ lookup('file', 'output/show_interfaces.txt') }}"
|
||||
'''
|
||||
58
roles/ansible-network.network-engine/library/net_facts.py
Normal file
58
roles/ansible-network.network-engine/library/net_facts.py
Normal file
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# (c) 2018, Red Hat, Inc.
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'network'}
|
||||
|
||||
|
||||
DOCUMENTATION = """
|
||||
---
|
||||
module: net_facts
|
||||
version_added: "2.7"
|
||||
short_description: Collect device capabilities from Network devices
|
||||
description:
|
||||
- Collect basic fact capabilities from Network devices and return
|
||||
the capabilities as Ansible facts.
|
||||
|
||||
author:
|
||||
- Trishna Guha (@trishnaguha)
|
||||
options: {}
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- facts:
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
"""
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.connection import Connection
|
||||
|
||||
|
||||
def main():
|
||||
""" main entry point for Ansible module
|
||||
"""
|
||||
argument_spec = {}
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
|
||||
|
||||
connection = Connection(module._socket_path)
|
||||
facts = connection.get_capabilities()
|
||||
facts = module.from_json(facts)
|
||||
result = {
|
||||
'changed': False,
|
||||
'ansible_facts': {'ansible_network_facts': {'capabilities': facts['device_info']}}
|
||||
}
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2018 Red Hat
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'network'}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: textfsm_parser
|
||||
author: Peter Sprygada (@privateip)
|
||||
short_description: Parses text into JSON facts using TextFSM
|
||||
description:
|
||||
- Provides textfsm rule based templates to parse data from text.
|
||||
The template acting as parser will iterate of the rules and parse
|
||||
the output of structured ASCII text into a JSON data structure
|
||||
that can be added to the inventory host facts.
|
||||
requirements:
|
||||
- textfsm
|
||||
version_added: "2.5"
|
||||
options:
|
||||
file:
|
||||
description:
|
||||
- Path to the TextFSM parser to use to parse the output from a command.
|
||||
The C(file) argument accepts either a relative or absolute path
|
||||
to the TextFSM file.
|
||||
default: null
|
||||
src:
|
||||
description:
|
||||
- The C(src) argument can be used to load the content of a TextFSM
|
||||
parser file. This argument allow the TextFSM parser to be loaded
|
||||
from an external source. See EXAMPLES.
|
||||
default: null
|
||||
content:
|
||||
description:
|
||||
- The output of the command to parse using the rules in the TextFSM
|
||||
file. The content should be a text string.
|
||||
required: true
|
||||
name:
|
||||
description:
|
||||
- The C(name) argument is used to define the top-level fact name to
|
||||
hold the output of the parser. If this argument is not provided,
|
||||
the output from parsing will not be exported.
|
||||
default: null
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: parse the content of a command
|
||||
textfsm_parser:
|
||||
file: files/parser_templates/show_interface.yaml
|
||||
content: "{{ lookup('file', 'output/show_interfaces.txt') }}"
|
||||
|
||||
- name: store returned facts into a key call output
|
||||
textfsm_parser:
|
||||
file: files/parser_templates/show_interface.yaml
|
||||
content: "{{ lookup('file', 'output/show_interfaces.txt') }}"
|
||||
name: output
|
||||
|
||||
- name: read the parser from an url
|
||||
textfsm_parser:
|
||||
src: "{{ lookup('url', 'http://server/path/to/parser') }}"
|
||||
content: "{{ lookup('file', 'output/show_interfaces.txt') }}"
|
||||
'''
|
||||
Reference in New Issue
Block a user