You'll have to be sad then, at least for now. Too much fuzzy logic is involved for the system to know what is a condition and what is a string, so only bare words are evaluated as conditionals.
On Tue, Mar 4, 2014 at 8:41 AM, Arie Skliarouk <[email protected]> wrote: > Will it be easier for ansible to recognize pre-defined condition if I put > it in brackets? > > vars: > amazon: "yes" > lxc: "no" > is_amazon: (amazon == "yes") > is_lxc: (lxc == "yes") > > tasks: > - shell: echo hi 1 > when: is_amazon or is_lxc > > It would be sad if there is no way to use short syntax like this... > > On Tuesday, March 4, 2014 3:34:15 PM UTC+2, Michael DeHaan wrote: > >> Complex conditionals and or statements are fine. >> >> when: x > 2 or y >3 >> >> and complex conditionals are fine as well: >> >> when: (x > 2 or y > 3) and (zebras == 4) >> >> etc >> >> >> >> >> On Tue, Mar 4, 2014 at 8:28 AM, Arie Skliarouk <[email protected]> wrote: >> >>> In my scripts I also use "or" expression... How would I do that? And >>> what about the poor souls that want to use complex boolean expression?... >>> >>> -- >>> Arie >>> >>> >>> On Tuesday, March 4, 2014 2:49:44 PM UTC+2, Michael DeHaan wrote: >>> >>>> The following tricks are available: >>>> >>>> --- >>>> - hosts: all >>>> >>>> vars: >>>> x: 1 >>>> y: 2 >>>> alpha: x > 2 >>>> beta: y > 3 >>>> >>>> tasks: >>>> >>>> - shell: echo hi 1 >>>> when: alpha >>>> >>>> - shell: echo hi 2 >>>> when: >>>> - alpha >>>> - beta >>>> >>>> Note that 'when: "alpha and beta"' is ambigious to the system, and >>>> won't do what you want, because it has a hard time understanding whether a >>>> variable is a variable expression or a string or not. >>>> >>>> >>>> >>>> >>>> On Tue, Mar 4, 2014 at 7:11 AM, Arie Skliarouk <[email protected]>wrote: >>>> >>>>> Hi, >>>>> >>>>> I am migrating ansible from 0.9 to 1.5 and complex when condition >>>>> don't work anymore: >>>>> >>>>> vars: >>>>> not_main: "'$c_main' == 'no'" >>>>> is_main: "'$c_main' == 'yes'" >>>>> not_lxc: "'$lxc' != 'yes'" >>>>> >>>>> tasks: >>>>> # This does not work properly, it is always being applied >>>>> - name: test0.conf >>>>> action: template src=/tmp/test.conf.j2 dest=/tmp/test0.conf >>>>> owner=ops group=ops mode=0444 >>>>> when: not_main and not_lxc >>>>> # This works but prints warnings about using ${foo} or $foo. This is >>>>> what I used in the past with ansible 0.9 (with only_if). >>>>> - name: test1.conf >>>>> action: template src=/opt/opsfs/tmp/test.conf.j2 >>>>> dest=/tmp/test1.conf owner=ops group=ops mode=0444 >>>>> when: $not_main and $not_lxc >>>>> # This works but is longer to type and not as readable as the first >>>>> example >>>>> - name: test2.conf >>>>> action: template src=/opt/opsfs/tmp/test.conf.j2 >>>>> dest=/tmp/test2.conf owner=ops group=ops mode=0444 >>>>> when: c_main == 'no' and lxc != 'yes' >>>>> >>>>> What is the correct way to use complex when conditions? >>>>> >>>>> -- >>>>> Arie >>>>> >>>>> -- >>>>> 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/8d870518-5473-4e44-826c-f6674d1fc306% >>>>> 40googlegroups.com. >>>>> For more options, visit https://groups.google.com/groups/opt_out. >>>>> >>>> >>>> -- >>> 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/0f7f4886-4abe-4a15-bc67- >>> ec7f691e1f60%40googlegroups.com. >>> >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >> >> -- > 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/4714468c-370d-4dd0-b840-6ad3e22452e4%40googlegroups.com > . > > For more options, visit https://groups.google.com/groups/opt_out. > -- 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/CAEVJ8QOQXcGFyGADcqubDtwPc6eLs1RmdyC5r74jmSQR9Nr-5g%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
