Hello there~
Is this possible using when conditional with variables?
For instance, I use two kind of was (Jboss, Weblogic)
I create for checking process id some yml files like under line
check.yml
- shell: ps -ef | grep ‘{{ nodename }}’ | grep XX | awk {‘print $2’}
register: pid
ignore_errors: True
when: {{ was }} == jboss
- shell: /usr/ucb/ps -auxwww | grep ‘{{ nodename }}’ | grep XX | awk {‘print $2’}
register: pid
ignore_errors: True
when: {{ was }} == weblogic
and then, put this yml file in main.yml
main.yml
- include: check.yml
tags: check
now I would execute this command
ansible-playbook playbook -i inventory -t check -e component=somecomponent -e nodename=somenodename -e was=jboss
however It gives me under error message?
{“failed”: true, “reason”: “ERROR! Syntax Error while loading YAML.
The error appears to have been in ‘check.yml’: line 5, column 19, but maybe elsewhere in the file depending on the exact syntax problem.
The offending line appears to be: ignore_errors: True\n when: {{ was }} == jboss^ 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 }}"”}
What’s problem in my check.yml??