Thanks for your quick help. But I need to use the conditionals for 
searching multiple  strings. Is it possible? When I use 
({{ stdout_lines|select('search', 'A')|first }}) or ({{ 
stdout_lines|select('search', 'B')|first }}) it dont work and returning me 
a generator object. Can you please help?

On Monday, July 22, 2019 at 10:59:24 PM UTC+5:30, Matt Martz wrote:
>
> I'd probably just use something like this instead:
>
> - debug:
>     msg: "{{ stdout_lines|select('search', 'A')|first }}"
>
> On Mon, Jul 22, 2019 at 12:18 PM Bubunia Patra <bubunia...@gmail.com 
> <javascript:>> wrote:
>
>> Hi all,
>>
>> I am trying to parse the stdout_lines to find the matching strings in a 
>> line. But the problem is stdout_lines adds new line at the end and the 
>> match string also contains new line which looks ugly. Any idea how I can 
>> fix it?
>> I tried trim, difference etc after some google around but it does not 
>> work inside the jinja template as below. I am stuck here... Can anyone 
>> please help?
>>
>> stdout_lines
>>
>> ok: [10.10.25.1] => {
>>
>>     "stdout_lines": [
>>
>>         "X",
>>
>>         "B",
>>
>>         "C",
>>
>>         "D",
>>
>>         "E",
>>
>>         "F",
>>
>>         "G",
>>
>>         "H",
>>
>>         "I",
>>
>>         "J",
>>
>>         "A"        
>>
>>     ]
>>
>> }
>>
>>
>>
>> -name : Test match string
>>
>>  - command: |
>>
>>         printf "X\nB\nC\n\D\nE\nF\n\G\nH\nI\nJ\nA\n"
>>
>>         register: cmd
>>
>>
>> - name: Find the matching string 
>>
>>   set_fact:
>>
>>     msg: | 
>>
>>       {% for line in cmd.stdout_lines %}
>>
>>       {% if line is defined and 'A' in line %}
>>
>>       {{ line }}
>>
>>       {% endif %}   
>>
>>       {% endfor %}
>>
>>   when:
>>
>>     - cmd.stdout_lines is defined 
>>
>>
>>
>> - debug:
>>
>>     var: msg
>>
>>
>> The output looks as below as it adds the new line till the match "A" 
>> found(e.g X\n,B\n blah blah) and it looks ugly. But I dont want these new 
>> lines in my output. Can anybody please throw some idea how can i fix it?
>>
>>
>> Actual Output:
>>
>> ===============
>>
>> TASK [Test : debug] 
>> ********************************************************************************************************************************
>>
>> *task path: *
>>
>> ok: [10.10.25.1] => {
>>
>>     "msg": "   \n   \n   \n   \n   \n   \n   \n   \n   \n   \n   A"
>>
>> }
>>
>>
>> Expected Output:
>>
>> ===============
>>
>>
>> TASK [Test : debug] 
>> ********************************************************************************************************************************
>>
>> *task path: *
>>
>> ok: [10.10.25.1] => {
>>
>>     "msg": "A"
>>
>> }
>>
>>
>> Some of the links are :
>>
>> https://github.com/ansible/ansible/issues/15099
>>
>>
>>
>> Regards
>>
>> Pradeep
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ansible Development" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to ansibl...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-devel/6f340736-78d7-4221-9d3f-e35136ac6d91%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-devel/6f340736-78d7-4221-9d3f-e35136ac6d91%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> Matt Martz
> @sivel
> sivel.net
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-devel/1ab013df-a89f-4334-8275-21013528d494%40googlegroups.com.

Reply via email to