-1

I have several tasks to do with ansible ( because it is great environment). However I want to achieve two things:

  1. have on stdout only exactly what I want ( I mean only this output which I place in msg variable, and NOTHING ELSE)
  2. I would like to be able to use this output as input via pipe to other tools like grep, awk, sed etc.

Is there any way ( without writing my own C++, Perl, Cobol, SQL, VisualBasic and Java whatever, code) to do it? As the only option if You have to write eternal code - I allow assembler code, so if You would like to propose something like that: feel free!

kakaz
  • 195

3 Answers3

2

It is not possible by design. Ansible is written without clear separation of stout, stderr and even output from ansible itself versus output from external execution procedures/functions. It is debatable why such design is used, however society around ansible is even not able to discuss possiblity it is not very well suited for enterprise use.

kakaz
  • 195
0

Write your own custom stdout callback plugin. This type of plugin (although not to stdout) is how reporting tools like ARA work.

Possibly ansible-runner will be interesting as a stable interface designed for automation, one if its output options is JSON.


By default an adhoc ansible command looks vaguely JSON-ish and parsable, but it isn't entirely due to human readable headers at the beginning.

John Mahowald
  • 36,071
-2

I think you may try to register to get stdout of your command. For example when you using shell. Basically it creates structure which you can iterate or even update. There are lots of examples how to work with variables: ansible print debug msg variable

Regarding second part, you also may place ansible variable in shell as part of command. Example. But it is better to use native ansible module if such exist for you task.