How to search for a Word in a Register variable from a Shell script in Ansible?

Viewed 496

I am very new to ansible, i am writing a set of code where the result of a shell command goes to a Register variable, and in that variable, I need to find the keyword "happy". If the keyword is found, execute ANOTHER shell script. Shell command apparently outputs multiple different values, looks like a dictionary, it is not a straight forward string, so how do i find ONE word in the entire shell result.

My attempt:

- name: execute first task
 shell: /tmp/somescript
 register: myResult
- name: another shell script
  shell: /tmp/anotherscript
  when: "happy" in myResult.

This returns saying "condition was false", when the output DOES have happy in it per the output result.

0 Answers
Related