Do conditionals work with the replace module?

20 views
Skip to first unread message

Slim Slam

unread,
Mar 15, 2016, 3:59:07 PM3/15/16
to Ansible Project
Do conditionals work with the replace module?

I have something like this:

- name: Set date for demo 1
  replace
: dest={{ workdirectory2 }}/junk.java regexp='2016' replace="{{ hostvars['localhost']['year'] }}"
 
when: (is_demo and "'{{ hostvars['localhost']['soft'] }}' == 'newapp'")

And it appears to ignore the "when" conditional entirely and always executes the replace.

J

Slim Slam

unread,
Mar 15, 2016, 4:20:05 PM3/15/16
to Ansible Project
So, this DOES work:

- name: Set date for demo 1
  replace
: dest={{ workdirectory2 }}/junk.java regexp='2016' replace="{{ hostvars['localhost']['year'] }}"
 
when: (is_demo and '{{ hostvars['localhost']['soft'] }}' == 'newapp')

Simply removing the double quotes around the 2nd part of the conditional makes it work. So the new question is:  Is that a bug?

J

Brian Coca

unread,
Mar 15, 2016, 4:39:56 PM3/15/16
to ansible...@googlegroups.com
no, you are doing and " " string before, which is always true. unless its an empty string. The when will not arbitrarily look inside quotes in hopes there is another conditional in there.

----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages