I tried all the suggestions but it did not work.
With the following in my config file:
sp_ver: 2016
and with following code:
sp = ‘abc’
When: sp_ver | int == 2016
sp = ‘def’
When: sp_ver == “2016”
Both variations did not work. Jordan mentioned on the irc channel a nice
solution which was to create dictionary item and then use sp_ver as a lookup
which worked very nicely. But I am really interested for learning purposes why
the above do not work.
Thanks again.
Sent from Mail for Windows 10
From: Edmund Cheng
Sent: Tuesday, May 8, 2018 5:42 AM
To: Ansible Project
Subject: [ansible-project] Re: if-elseif-if
As the guys have mentioned, try removing the {{}}, variables in the when
condition is implicit i think..
On Saturday, May 5, 2018 at 3:25:58 PM UTC+8, Ali Khawaja wrote:
i am trying to set a variable based on the value of a variable in the config
file but unable to do so.
here's my config file:
sql_ver: "2012" # available sql versions are: 2008 | 2012 | 2014 | 2016
sp_ver: "2010" # available sp versions are: 2007 | 2010 | 2013 | 2016
sp2k10: en_sharepoint_server_2010_with_service_pack_2_x64_dvd_4178583.iso
sp2k13: en_sharepoint_server_2013_with_sp1_x64_dvd_3823428.iso
sp2k16: en_sharepoint_server_2016_x64_dvd_8419458-003.iso
sql2k12:
en_sql_server_2012_standard_edition_with_service_pack_3_x64_dvd_7286878.iso
sql2k14: en_sql_server_2014_standard_edition_with_service_pack_2_x64_dvd_8961564
sql2k16: en_sql_server_2016_standard_with_service_pack_1_x64_dvd_9540929
and my ansible file is:
- name: Software Version Selection
hosts: localhost
vars_files:
- testcfg.yml
gather_facts: false
tasks:
- debug:
msg: "{{sp_ver}}"
- set_fact:
sp : "{{sp2k10}}"
when: "{{sp_ver}} == 2010"
sp : "{{sp2k13}}"
when: "{{sp_ver}} == 2013"
sp : "{{sp2k16}}"
when: "{{sp_ver}} is match(2016)"
- debug:
msg: "{{sp}}"
i have tried many things: "{{sp_ver}} == 2010" , "{{sp_ver}}" == 2010,
"{{sp_ver}} is match(2016)" but nothing worked. i dont know why there is a
syntax error for this: "{{sp_ver}}" is match(2016)
basically what is want is for the selected sp_ver, the proper variable gets
selected.
Thanks in advance
Ali
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/73b68aea-8be8-4edb-b7be-e9f807695c71%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/5af1acaf.1c69fb81.b88ce.04d6%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.