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 ?