Reputation: 527
I am trying to use a variable in when statement in ansible , my code snippet looks like this :
- name: git repo for non prod env
git:
repo=http://url/repo.git
dest=/opt/dest
version={{ bld_env }}
when: ( "{{ bld_env }}" == "rc" ) or ( "{{ bld_env }}" == "sandbox" ) or ( "{{ bld_env }}" == "dev" ) or ( "{{ bld_env }}" == "qa" )
This is not working and gives an a error as :
The offending line appears to be:
version={{ bld_env }}
when: "{{ bld_env }}" == "rc"
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
Let me know where I am wrong.
Upvotes: 3
Views: 18832
Reputation: 1166
I think you don't have to use "{{ bld_env }}" == "rc"
.
Just compare variable to value bld_env == "rc"
and so on as it is written in documentation
Upvotes: 10