Hi,

Is there a clean and efficient 'ansible' way by which the playbook 
developer can gain more control over the formatting of information to be 
put in front of the resource that executes the playbook?

I'm relatively new at developing with ansible, having developed only about 
a half dozen playbooks that execute in a dev-ops like environment, where 
the goal of my playbooks has been to validate configuration and ensure 
requested customizations/configuration changes can be made safely and 
consistently.

In some cases, the playbook encounters configuration drift or other 
findings where it seems unwise to resolve the finding in an automated 
manner and instead seems better to abort while highlighting the need for 
manual review/remediation.

When the Play aborts it has a lot of detailed information about the problem 
that needs to be communicated back to the resource who initiated the 
Playbook as the focus of the manual review needed. To date I have been 
struggling to format this in a suitable way for the resources to easily 
relate to, which is surprising --- surely this level of reporting is a 
fundamental tenet for computer automation?

I'm not looking for anything too sophisticated, just a way to output some 
static text (ideally controlling indentation, line and paragraph 
boundaries) and also merge in some output from previously executed commands 
or dynamically created 'dict' / 'list' objects, such that escaped newlines 
are expanded and reasonably complex findings from the execution can be 
consumed in a way that is easy to follow.

While researching this topic I've seen similar questions raised in 
different forms over many years but never really seen these adequately 
addressed. I'm therefore aware of custom (and less efficient) ad-hoc 
approaches that have been  suggested and also about  '
ANSIBLE_STDOUT_CALLBACK', but don't want to change formatting as globally 
(I don't control the config and am not the only developer implementing 
playbooks) or even on the command line.

In general I am happy enough with the formatting of task related output  
and the formatting achieved for general calls to 'debug' (like how it 
formats a 'dict' when using the 'var:' directive). The requirement here 
seems just a corner case where having more control would be beneficial to 
clearly set out a specific finding that is the basis for the Playbook 
aborting and therefore needs to be easily understood so the operator is 
clear on what needs to be reviewed further.

To accommodate this flexibility it seems surprising that the built in 'debug' 
module doesn't have a number of modifiers so the developer can utilize 
additional formatting when the need arises, perhaps something like:

debug:
  expand_newlines: true
  format_mask: "{{ Service: %s (pid: %d)\nConfig:\n%j\n",
                   service_name, service_pid, json_config }}" 

In absence of any support for formatting more natively, in modules like '
debug', is there any way to control formatting when writing to a file 
(perhaps building it over multiple tasks) and then getting ansible to just 
cat the file to stdout at the very end, so that the output retains 
formatting and doesn't get missed in with other formatting (perhaps via a 
handler?).

Any ideas welcomed --- I've experimented a lot and researched a lot but am 
surprised not to have achieved the limited additional formatting needed to 
ensure findings can be presented in a way that is easily relatable.

Sorry for the long posting and thanks in advance for any input you might be 
able to offer.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-devel/376ca05a-5a02-4d3c-b0a8-47bf3fff3349n%40googlegroups.com.

Reply via email to