How to filter string in Ansible using jinja2?

31 views
Skip to first unread message

Saravanan

unread,
Dec 29, 2018, 10:14:55 PM12/29/18
to Ansible Project
Hi Ansible experts,

{
   
"outcome" => "success",
   
"result" => "running"
}
{
   
"outcome" => "success",
   
"result" => 2160063879L
}


Please help to filter the string running and the numeric value 2160063879 from the above stdout output using jinja2 filter into two different variables.

Piyush Bansal

unread,
Dec 31, 2018, 12:55:00 PM12/31/18
to ansible...@googlegroups.com
Hello Saravanan,

Have you tried "Regular Expression Filters" (regex_search) ??

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/133888b5-6b7d-4397-90ee-66a7d6c7a343%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Saravanan

unread,
Jan 9, 2019, 7:33:26 AM1/9/19
to Ansible Project
Hi Piyush,
Using the below Jinja2 filter, able to extract the value 2160063879L. However need to extract exact numeric value alone from sub String by eliminating the letter 'L' from the output. Any help much appreciated.

- set_fact:
    upTime: "{{ status.stdout.split()[-2] }}"
  delegate_to: localhost
 
become: false
 
become_user: awx
 
when: status.rc | int == 0
 
ignore_errors: yes

STANDARD OUTPUT
2160063879L
Reply all
Reply to author
Forward
0 new messages