I'm trying to create a directory in Ansible if the variable contains the string 7.0.0.GA
Below is my playbook:
- name: Determine the version of Tom
raw: "cat {{ homefound.path | dirname }}/version.txt | grep -i version"
register: Tomver
- debug:
msg: "Tom VERSION IS: {{ Tomver.stdout }}"
- name: Create patch folder /app/Tom_Patches/7.0 on target servers
file:
path: /app/Tom_Patches/7.0
state: directory
mode: '0755'
when: Tomver.stdout is match('7.0.0.GA*')
In the output I can see that the variable has string 7.0.0.GA
but still when condition
fails and skips.
Output:
TASK [debug] ***********************************************************************************************************************************************************
ok: [10.9.156.126] => {
"msg": "Tom VERSION IS: Red Hat Tom Enterprise Application Platform - Version 7.0.0.GA\r\n"
}
TASK [Create patch folder /app/Tom_Patches/7.0 on target servers] ****************************************************************************************************
skipping: [10.9.156.126]
I even tried the following condition check but that too fails:
when: Tomver.stdout | join('') | search('7.0.0.GA')
I prefer using raw
module instead of command
or shell
module to avoid python dependency.
Can someone please suggest?
you can have a try with the in
when: "'7.0.0.GA' in res.stdout"