From 5f1cd13bf9eab583276196e913a43e27f0b88707 Mon Sep 17 00:00:00 2001 From: "Tejeda, Engelbert" Date: Fri, 2 Aug 2019 18:03:50 -0400 Subject: [PATCH] The echo flag now includes logic for displaying the embedded inventory command --- ansible_taskrunner/lib/providers/ansible.py | 27 ++++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/ansible_taskrunner/lib/providers/ansible.py b/ansible_taskrunner/lib/providers/ansible.py index bcf2407..d5f31b0 100644 --- a/ansible_taskrunner/lib/providers/ansible.py +++ b/ansible_taskrunner/lib/providers/ansible.py @@ -85,26 +85,32 @@ def invocation(yaml_input_file=None, '-e {k}="{v}"'.format(k=key, v=value) for key, value in kwargs.items() if value] ansible_extra_options.append('-e %s' % paramset_var) # Build command string + inventory_command = ''' + if [[ ($inventory) && ( '{emb}' == 'True') ]];then + echo -e """{ins}""" | while read line;do + eval "echo -e ${{line}}" >> "{inf}" + done + fi + '''.format( + emb=embedded_inventory, + ins=inventory_input, + inf=ansible_inventory_file_path, + ) + inventory_command = reindent(inventory_command,0) pre_commands = ''' {anc} {dsv} {dlv} {clv} {bfn} - if [[ ($inventory) && ( '{emb}' == 'True') ]];then - echo -e """{ins}""" | while read line;do - eval "echo -e ${{line}}" >> "{inf}" - done - fi + {inc} '''.format( anc=ansi_colors, dlv='\n'.join(list_vars), dsv='\n'.join(string_vars), clv=cli_vars, bfn='\n'.join(bash_functions), - ins=inventory_input, - inf=ansible_inventory_file_path, - emb=embedded_inventory, + inc=inventory_command, deb=debug ) ansible_command = ''' @@ -122,7 +128,10 @@ def invocation(yaml_input_file=None, if prefix == 'echo': if debug: print(pre_commands) - print(ansible_command) + print(ansible_command) + else: + print(inventory_command) + print(ansible_command) else: CLIInvocation().call(command) # Debugging