-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathtextfsm_parser.py
70 lines (62 loc) · 2.27 KB
/
textfsm_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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') }}"
'''