Print output in human readable format

1,899 views
Skip to first unread message

Ted Meller

unread,
Aug 1, 2017, 12:49:02 PM8/1/17
to Ansible Project
Im having troube in Ansible 2.3.0 to print out my output in a human format. Currently everything comes out as one line. below is a sample of my yaml output.

    register: output

   
- name: show output
      debug
:
       
var: output.stdout


Daniel JD

unread,
Aug 1, 2017, 2:12:42 PM8/1/17
to Ansible Project
Give an example please. Which output did you expected and what did you actually got?

Ted Meller

unread,
Aug 2, 2017, 9:47:16 AM8/2/17
to Ansible Project
ok: [192.168.14.25] => {
    "output.stdout": [
        "Radio power mode = ON\nChannel Number = 1062\nCurrent Band = WCDMA 850\nCurrent RSSI(RSCP) = -70 dBm\nLTE Technology Preference = AUTO\nLTE Technology Selected = UMTS"
    ]

Daniel JD

unread,
Aug 2, 2017, 11:01:55 AM8/2/17
to Ansible Project
Try it like this:

- name: Show output
  debug:
    msg: output.stdout.split("\n")

Which will result in:

localhost | SUCCESS => {
    "msg": [
        "Radio power mode = ON", 
        "Channel Number = 1062", 
        "Current Band = WCDMA 850", 
        "Current RSSI(RSCP) = -70 dBm", 
        "LTE Technology Preference = AUTO", 
        "LTE Technology Selected = UMTS"
    ]

Ted Meller

unread,
Aug 2, 2017, 11:19:34 AM8/2/17
to Ansible Project
That didn't work. The output I got  from that was:

ok: [192.168.14.25] => {
    "msg": "output.stdout.split(\"\\n\")"

Daniel JD

unread,
Aug 2, 2017, 4:20:42 PM8/2/17
to Ansible Project
Ups, my bad. Like this "{{ output.stdout.split('\n') }}"

Ted Meller

unread,
Aug 2, 2017, 8:12:44 PM8/2/17
to Ansible Project
Tried that and ended up getting the below error:

fatal: [192.168.14.25]: FAILED! => {
    "failed": true
}

MSG:

the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'list object' has no attribute 'split'

The error appears to have been in '/home/ansible/4G.yml': line 22, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


    - name: Show output
      ^ here

Kai Stian Olstad

unread,
Aug 8, 2017, 9:10:53 AM8/8/17
to ansible...@googlegroups.com
Since you output.stdout is a list you need to say which element in the
list you would like to do a split on.

{{ output.stdout.0.split('\n') }}


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages