Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to evaluate a when condition for Ansible task

I am having a variable with the following value:

   name_prefix: stage-dbs

I am having a task in my playbook which will have to check this variable and see if it contains *-dbs , if the condition is met then it should process. I wrote something like this :

- name: Ensure deployment directory is present
  file:
    path=/var/tmp/deploy/paTestTool
    state=directory
  when: name_prefix =="*-dbs" # what condition is required here to evaulate the rest part of variable?? 

What regex pattern should be used or how to use a regex here ?

like image 200
Nishant Singh Avatar asked Dec 23 '15 06:12

Nishant Singh


1 Answers

No need to use regex for pattern searching. You can use search like this:

when: name_prefix | search("stage-dbs")

It will definitely work.

like image 155
kohi Avatar answered Nov 15 '22 16:11

kohi