-2

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
  • 168
  • 8
  • Not exactly a duplicate, but pretty close: https://serverfault.com/questions/640130/display-output-with-ansible – Gerald Schneider Sep 09 '19 at 10:22
  • It is not about pretty printing. It is about usability and integration withn linux/unix tools – kakaz Sep 09 '19 at 10:29
  • I'm aware of that. That's why I didn't vote to close your question as a duplicate. Nevertheless the linked question contains some pointers how you could achieve what you want. – Gerald Schneider Sep 09 '19 at 10:35
  • There is no point in pretty printing - it is just aesthetic expectation. But imagine You have to check 300 switches for given config... If tool have to be used it have to work with grep/awk/sed tools without any friction. – kakaz Sep 09 '19 at 10:48
  • why down-vote? Because nobody knows how to do it? Maybe the correct answer is: not possible at all? – kakaz Sep 11 '19 at 09:06
  • Possible progress: You can quiet some ansible by setting [defaults] stdout_callback = full_skip in ansible.cfg. At least You will see only the "working part" of your playbook. – kakaz Sep 11 '19 at 13:39
  • Ansible is not a scripting language, and it isn't intended to be one. It is an orchestration tool. You are trying to use ansible in a way that it wasn't meant to be used. You don't pipe output from ansible to other tools you use ansible to run those other tools. Run a task register the results, run a second task, perhaps a shell task doing your sed/awk/group and pass in the previous results. – Zoredache Sep 17 '19 at 17:48
  • `I allow assembler code,`- BTW, this makes your question seem like a troll. Expecting someone to give you assembly code for a project that is mostly python is just silly. It is part of why I gave you a downvote. – Zoredache Sep 17 '19 at 17:54
  • Orchestration tool should integrate with much more mature tools, just for giving ability for checking results in automated way. It is just stupid philosophy to build something like Microsoft does. – kakaz Sep 17 '19 at 20:45
  • I have wrote about assembler because all of ansible power users immediately answer: write a fragment of python code and this is solution. I just think that building such great tool even without simple clear stout and simple stderr is result of lack of broader picture – kakaz Sep 19 '19 at 16:57
  • So basically there is nobody who knows, by nobody is able to say: it is not possible because of design? – kakaz Sep 26 '19 at 15:13

3 Answers3

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
  • 30,009
  • 1
  • 17
  • 32
  • As i'm saying above, I will accept such kind of answer only if assembler code is provided. All other way for me is incomplete. – kakaz Sep 09 '19 at 18:34
  • How far would be it world now if ls command would give you jsonish output connected with cows... – kakaz Sep 24 '19 at 15:57
0

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
  • 168
  • 8
-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.

user2986553
  • 390
  • 1
  • 4