Answers: <p>That's still a XY problem IMHO, why do you want an output in  a single line at all ? what's the need for it ? </p>
  
  <p>If you can't explain more and wish to footgun yourself by replacing newlines with spaces the use <code>command | tr '\n' ' '</code> (you'll probably end up loosing the end of the log). </p>
  
  <p>If your goal if to parse the last line then </p>
  
  <p><code>command | awk '/ok=/ { for (i=3; i &lt; 7; i++) { split($i,a,"="); printf a[1]":"a[2]" " } }'</code> </p>
  
  <p>will give <code>ok:3 changed:1 unreachable:0 failed:0</code> </p>
  
  <p>This select the lines containing <code>ok=</code> and split each <code>key=value</code> field (3 to 6) on the <code>=</code> char, thus giving the key as first element of array <code>a</code> and the value as the second element.</p>
  
  <p>use <code>print</code> instead of <code>printf</code> to get each state on separate lines.</p>
  
Answers: CC BY-SA 3.0
Answers: 2017-08-28T08:40:47.913Z
Answers: 2017-08-28T08:40:47.913Z
Answers: Tensibai
Answers: <p>I am not sure if that is possible or not but you can write same command in bash script</p>
  
  <pre><code>#!/bin/bash
  
  ansible-playbook playbookname.yaml &gt; output.txt
  
  # Then grep from output.txt what you want
  
  grep -A 5 "PLAY" output.txt
  </code></pre>
  
  <p>May not be good way but will achieve what you want.</p>
  
Answers: CC BY-SA 3.0
Answers: 2018-04-12T09:48:35.530Z
Answers: Would work only if there's less than 6 lines after the PLAY keyword...
Answers: Tensibai
Answers: CC BY-SA 3.0
Answers: 2018-04-12T11:21:56.493Z
Answers: (well would work, but not answering the question as it would output the same thing as in the question, which is not what the question is about)
Answers: Tensibai
Answers: CC BY-SA 3.0
Answers: 2018-04-12T11:45:18.587Z
Answers: just an example s/he can grep anything s/he like
Answers: Prakash
Answers: CC BY-SA 3.0
Answers: 2018-04-12T11:59:23.830Z
Answers: I don't get the point of showing how to grep multiple lines where the question is how to get the output in one line ... For sure it does not achieve what the OP is after
Answers: Tensibai
Answers: CC BY-SA 3.0
Answers: 2018-04-12T09:42:27.470Z
Answers: 2018-04-12T09:42:27.470Z
Answers: Prakash
Body: <p>In Ansible we are running a playbook using <code>ansible-playbook playbookname.yaml</code>. The output will be multiple lines (like below). I need output in single line.  How can I get that?</p>
  
  <pre><code>PLAY [localhost] **************************************************************
  GATHERING FACTS ***************************************************************
  localhost                  : ok=3    changed=1    unreachable=0    failed=0
  </code></pre>
  
Comments: CC BY-SA 3.0
Comments: 2017-08-23T12:21:13.177Z
Comments: Why and what did you try?
Comments: 030
Comments: CC BY-SA 3.0
Comments: 2017-08-24T11:43:08.880Z
Comments: Hi. As @030 asked, please add in more info. about what do you mean by not wanting output in multiple lines. In the current state, this qn is very unclear.  We shall consider reopening the post once you clear things up :)
Comments: Dawny33
Comments: CC BY-SA 3.0
Comments: 2017-08-26T18:10:20.180Z
Comments: You probably want to look into callback plugins.
Comments: LEI
Comments: CC BY-SA 3.0
Comments: 2017-09-30T10:47:09.167Z
Comments: You could literally translate the newlines by piping to `tr '\n' ' '`  But a custom callback plugin is the way to do this.
Comments: Zlemini 
Tags: <ansible>
Title: How to get Ansible playbook ouput in one line?
UserDisplayName: venkat
ThreadText: # How to get Ansible playbook ouput in one line?
  
  (Asked by: username_0 on 2017-08-23)
  
  In Ansible we are running a playbook using `ansible-playbook playbookname.yaml`. The output will be multiple lines (like below). I need output in single line. How can I get that?
  
  ```
  PLAY [localhost] **************************************************************
  GATHERING FACTS ***************************************************************
  localhost                  : ok=3    changed=1    unreachable=0    failed=0
  
  ```
  
  **Tags:** ansible
  
  > **Comments:**
  > **username_1**: Why and what did you try?  
  > **username_2**: Hi. As @username_1 asked, please add in more info. about what do you mean by not wanting output in multiple lines. In the current state, this qn is very unclear.  We shall consider reopening the post once you clear things up :)  
  > **username_3**: You probably want to look into callback plugins.  
  > **username_4**: You could literally translate the newlines by piping to `tr '\n' ' '`  But a custom callback plugin is the way to do this.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_5 on 2017-08-28. Score: 5
  
  That's still a XY problem IMHO, why do you want an output in a single line at all ? what's the need for it ?
  
  If you can't explain more and wish to footgun yourself by replacing newlines with spaces the use `command | tr '\n' ' '` (you'll probably end up loosing the end of the log).
  
  If your goal if to parse the last line then
  
  `command | awk '/ok=/ { for (i=3; i < 7; i++) { split($i,a,"="); printf a[1]":"a[2]" " } }'`
  
  will give `ok:3 changed:1 unreachable:0 failed:0`
  
  This select the lines containing `ok=` and split each `key=value` field (3 to 6) on the `=` char, thus giving the key as first element of array `a` and the value as the second element.
  
  use `print` instead of `printf` to get each state on separate lines.
  
  
  ---
  
  ### Answer by username_6 on 2018-04-12. Score: -1
  
  I am not sure if that is possible or not but you can write same command in bash script
  
  ```
  #!/bin/bash
  
  ansible-playbook playbookname.yaml > output.txt
  
  # Then grep from output.txt what you want
  
  grep -A 5 "PLAY" output.txt
  
  ```
  
  May not be good way but will achieve what you want.
  
  > **Comments:**
  > **username_5**: Would work only if there's less than 6 lines after the PLAY keyword...  
  > **username_5**: (well would work, but not answering the question as it would output the same thing as in the question, which is not what the question is about)  
  > **username_6**: just an example s/he can grep anything s/he like  
  > **username_5**: I don't get the point of showing how to grep multiple lines where the question is how to get the output in one line ... For sure it does not achieve what the OP is after  
  
  ---
  
  