Remove the curly braces in your condition

On Thu, 5 Sep 2019 at 13:45, Mohtashim S <[email protected]> wrote:

> MYUSER should be assigned value "wsadm" or "user1" based on the output of
> {{ command_result.stdout.split('\t')[1] }}
>
> I tried the below however, I'm getting error when I run.
>
> My playbook looks like below:
>
> ---
> - name: "Play 1-Find the details here"
>
>
>   hosts: localhost
>   gather_facts: no
>
>
>   tasks:
>    - name: "Search for {{ Number }} in the database"
>
>
>      command: >
>        mysql --user=root --password=mypass deployment
>        --host=localhost  -Ns -e "SELECT dest_ip,layer FROM deploy_dets
> WHERE num LIKE '{{ Number }}'"
>      register: command_result
>
>
>    - set_fact:
>
>
>        dest_ip: "{{ command_result.stdout.split('\t')[0] }}"
>        MYUSER: "wsadm"
>      when: "{{ command_result.stdout.split('\t')[1] }}" == 'WAS'
>        MYUSER: "user1"
>      when: "{{ command_result.stdout.split('\t')[1] }}" == 'APP'
>
>
>
>
>    - name: "Print output for Number Search"
>      debug:
>        msg: "{{ command_result.stdout.split('\t')[1] }}"
>        msg: "{{ MYUSER }}"
>
>
>
> Error Output:
>
>  [WARNING]: provided hosts list is empty, only localhost is available.
>> Note that the implicit localhost does not match 'all'
>> ERROR! Syntax Error while loading YAML.
>>   did not find expected key
>> The error appears to be in
>> '/app/axmw/Ansible/playbook/finacle_deployment/assignvars.yml': line 22,
>> column 57, but may
>> be elsewhere in the file depending on the exact syntax problem.
>> The offending line appears to be:
>>        MYUSER: "wsadm"
>>      when: "{{ command_result.stdout.split('\t')[1] }}" == 'WAS'
>>                                                         ^ 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.
>
>
> Can you please suggest ?
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/d335b876-90da-4fb5-be2e-972bc08e3c73%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/d335b876-90da-4fb5-be2e-972bc08e3c73%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
-- 
Sent from a mobile device - please excuse the brevity, spelling and
punctuation.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAL8fbwMLWdLkRep%2B%2BHn7R0RxUV%3DOcDovhd1dgpWFSZwKhZRYBw%40mail.gmail.com.

Reply via email to