I tried both suggestion but it still errors out:
MYUSER: "wsadm"
when: command_result.stdout.split('\t')[3] == 'WAS'
MYUSER: "user1"
when: command_result.stdout.split('\t')[3] == 'APP'
MYUSER: "wsadm"
when: "command_result.stdout.split('\t')[3]" == 'WAS'
MYUSER: "user1"
when: "command_result.stdout.split('\t')[3]" == 'APP'
Still getting error:
The offending line appears to be:
> MYUSER: "wsadm"
> when: "command_result.stdout.split('\t')[3]" == 'WAS'
>
> ^ here
> This one looks easy to fix. It seems that there is a value started
> with a quote, and the YAML parser is expecting to see the line ended
> with the same kind of quote. For instance:
On Thursday, September 5, 2019 at 6:03:37 PM UTC+5:30, Dick Visser wrote:
>
> Remove the curly braces in your condition
>
> On Thu, 5 Sep 2019 at 13:45, Mohtashim S <[email protected] <javascript:>>
> 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] <javascript:>.
>> 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/edf77d2e-a12d-4906-9784-d0c521a1611e%40googlegroups.com.