I’ve been racking my brain on this one but I haven’t been able to come up with an answer.
My Devs have named machines based on their task. I know you can set a conditional based on the hostname such as:
- name: Testing
shell: echo “String Found!”
when_string: ‘“String1” in “${ansible_hostname}”’
which will match String1.mycompany.com but not String2.mycompany.com or Different.mycompany.com
However, I need to execute that same command on hosts with more than just String1, say String2 and Different also. I tried using “or” but that is not supported apparently with when_string: the same way it is with when:
This works:
when: somevar == ‘String1’ or somevar == ‘String2’ or somevar == ‘Different’
But this does not:
when_string: ‘“String1” in “${ansible_hostname}”’ or ‘“String2” in “${ansible_hostname}”’ or ‘“Different” in “${ansible_hostname}”’
Anybody have an idea to get this working?
Thanks