Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ansible/ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

inventory = /etc/ansible/hosts
library = library:library/ixia
module_utils = module_utils
remote_tmp = $HOME/.ansible/tmp
pattern = *
forks = 5
Expand Down
7 changes: 7 additions & 0 deletions ansible/library/conn_graph_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from operator import itemgetter
from itertools import groupby
from collections import defaultdict
from ansible.module_utils.debug_utils import create_debug_file, print_debug_msg

DOCUMENTATION='''
module: conn_graph_facts.py
Expand Down Expand Up @@ -270,10 +271,12 @@ def find_graph(hostnames):

# Finding the graph file contains all duts from hostnames,
for fn in file_list:
print_debug_msg(debug_fname, "Looking at conn graph file: %s for hosts %s" % (fn, hostnames))
filename = os.path.join(LAB_GRAPHFILE_PATH, fn)
lab_graph = Parse_Lab_Graph(filename)
lab_graph.parse_graph()
if lab_graph.contains_hosts(hostnames):
print_debug_msg(debug_fname, ("Returning lab graph from conn graph file: %s for hosts %s" % (fn, hostnames)))
return lab_graph

# Fallback to return an empty connection graph, this is
Expand All @@ -284,6 +287,8 @@ def find_graph(hostnames):
lab_graph.parse_graph()
return lab_graph

debug_fname = None

def main():
module = AnsibleModule(
argument_spec=dict(
Expand All @@ -297,6 +302,8 @@ def main():
supports_check_mode=True
)
m_args = module.params
global debug_fname
debug_fname = create_debug_file("/tmp/conn_graph_debug.txt")

hostnames = m_args['hosts']
anchor = m_args['anchor']
Expand Down
Empty file.
25 changes: 25 additions & 0 deletions ansible/module_utils/debug_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
from pprint import pprint
from ansible.module_utils.basic import datetime


def create_debug_file(debug_fname, add_timestamp=True):
curtime = datetime.datetime.now().isoformat()
if add_timestamp:
# Check if there is an extension
fname_split = os.path.splitext(debug_fname)
if fname_split[1] != '':
# We have an extension
timed_debug_fname = (fname_split[0] + ".%s" + fname_split[1]) % curtime
else:
timed_debug_fname = (fname_split[0] + ".%s") % curtime
else:
timed_debug_fname = debug_fname
if os.path.exists(timed_debug_fname) and os.path.isfile(timed_debug_fname):
os.remove(timed_debug_fname)
return timed_debug_fname


def print_debug_msg(debug_fname, msg):
with open(debug_fname, 'a') as fp:
pprint(msg, fp)