Parse registered output into a variable?

33 views
Skip to first unread message

burn...@umn.edu

unread,
Nov 29, 2016, 3:30:56 PM11/29/16
to Ansible Project
Hello - Is there a way to parse registered output into a variable? 

Pseudo Code:
  tasks:
 
- name: Sample Task
    command
: 'blah'
   
register: output
 
- debug: var=output.stdout

TASK [debug] *******************************************************************
ok: [target] => {
    "output.stdout": "Foo: Bar"
}

So I can easily register and use "Foo: Bar". But is there a way where I can just store "Bar" for later use? 
For context, the command uses some black box vendor provided classes so I'm unable to change the actual output. I need to work with what is presented.

Thank you!

Matt Martz

unread,
Nov 29, 2016, 3:35:05 PM11/29/16
to ansible...@googlegroups.com
set_fact:
    just_bar: "{{ output.stdout.split()|last }}"

Or any other number of things.  The key there is to use set_fact to set a new variable.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/85114542-064a-4a8b-b733-9720e108bb25%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

burn...@umn.edu

unread,
Nov 29, 2016, 3:49:13 PM11/29/16
to Ansible Project
Ah - works like a charm. Thank you for the speedy response!


On Tuesday, November 29, 2016 at 2:35:05 PM UTC-6, Matt Martz wrote:
set_fact:
    just_bar: "{{ output.stdout.split()|last }}"

Or any other number of things.  The key there is to use set_fact to set a new variable.
On Tue, Nov 29, 2016 at 2:30 PM, <burn...@umn.edu> wrote:
Hello - Is there a way to parse registered output into a variable? 

Pseudo Code:
  tasks:
 
- name: Sample Task
    command
: 'blah'
   
register: output
 
- debug: var=output.stdout

TASK [debug] *******************************************************************
ok: [target] => {
    "output.stdout": "Foo: Bar"
}

So I can easily register and use "Foo: Bar". But is there a way where I can just store "Bar" for later use? 
For context, the command uses some black box vendor provided classes so I'm unable to change the actual output. I need to work with what is presented.

Thank you!

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages