Skip to content

Instantly share code, notes, and snippets.

@networkop
Created June 13, 2015 07:48
Show Gist options
  • Save networkop/1ae62939b268945cec10 to your computer and use it in GitHub Desktop.
Save networkop/1ae62939b268945cec10 to your computer and use it in GitHub Desktop.
test gist
class TraceParse(object):
def __init__(self, module):
self.std_out = module.params['std_out']
self.dest_host = module.params['dest_host']
def parse(self):
result = {}
path = list()
for line in self.std_out.split("\n"):
if 'msec' in line:
path.append(line.split()[1])
result[self.dest_host] = path
return 0, result
def main():
# creating module instance. accepting raw text output and abbreviation of command
module = AnsibleModule(
argument_spec=dict(
std_out=dict(required=True, type='str'),
dest_host=dict(required=True, type='str')
),
supports_check_mode=True,
)
# instantiate command parser
traceParser = TraceParse(module)
# parse the output of show ip interface brief command
rc, result = traceParser.parse()
# exiting module
#print "RESULT=" + str(result)
if rc != 0:
module.fail_json(msg="Failed to parse. Incorrect input.")
else:
module.exit_json(changed=False, ansible_facts=result)
# import module snippets
from ansible.module_utils.basic import *
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment