---
- hosts: localhost
  connection: local
  vars:
    my_list: "hello,how,are,you"
 
  tasks:
    - debug: msg="hi how are ? "         
      when: 
        - "{{ my_list | select('search','are') }}" == "are" 
        
    - debug: msg="hi how you ? "          
      when: 
        - "{{ my_list | select('search','you') }}" == "you" 

I did but got below error : 

 [WARNING]: Could not match supplied host pattern, ignoring: all

 [WARNING]: provided hosts list is empty, only localhost is available

ERROR! Syntax Error while loading YAML.


The error appears to have been in '/home/vagrant/a.yml': line 10, column 
52, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

      when:
        - "{{ my_list | select('search','are') }}" == "are"
                                                   ^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes.  Always quote template expression brackets when they
start a value. For instance:

    with_items:
      - {{ foo }}

Should be written as:

    with_items:
      - "{{ foo }}"

exception type: <class 'yaml.parser.ParserError'>
exception: while parsing a block collection
  in "<unicode string>", line 10, column 9
did not find expected '-' indicator
  in "<unicode string>", line 10, column 52

************************************************************8 

Could you please help me for this 

On Friday, December 15, 2017 at 10:01:09 PM UTC+5:30, Matt Martz wrote:
>
> `match` matches from the start of the string, so your examples would only 
> match if the string started with `are` or `you`.  So effectively it is the 
> equivalent of `^are` or `^you` in regex terms.
>
> You likely want `search` instead of `match`, which will search anywhere in 
> the string.
>
>
>
> On Fri, Dec 15, 2017 at 10:21 AM, Saurabh <saurab...@gmail.com 
> <javascript:>> wrote:
>
>> ---
>> - hosts: localhost
>>   connection: local
>>   vars:
>>     my_list: "hello,how,are,you"
>>  
>>   tasks:
>>     - block:
>>          ---- some logic 
>>       when: 
>>         - "{{ my_list | select('match','are') }}" == "are" 
>>         
>>      - block:
>>           ---- some logic 
>>        when: 
>>         - "{{ my_list | select('match','you') }}" == "you" 
>>
>> I'm not able to get exact match value or please correct me 
>>
>> Please help me for this issue 
>>
>> -- 
>> 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-deve...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> 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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to