The less than operator is documented at
http://jinja.pocoo.org/docs/dev/templates/#comparisons
Although, trying to use mathematical operations on string values isn't
exactly always straight forward.
You might get better results from the `version_compare` filter such as:
when: server_num|version_compare('100', 'lt')
See
http://docs.ansible.com/ansible/playbooks_filters.html#version-comparison-filters
On Tue, May 24, 2016 at 12:56 PM, Robert F <[email protected]>
wrote:
> Yea, it's weird. Sometimes "<" works for me and sometimes it doesn't. I
> couldn't find this operator documented in the Jinja2 or Ansible docs and I
> don't recall where I first learned it so I figured maybe it's an invalid
> operator. I put a debug statement right before the line where I'm
> referencing server_num and it said it was set as I expected it to be but
> the statement still failed.
>
> On Tuesday, May 24, 2016 at 10:29:13 AM UTC-7, Robert F wrote:
>>
>> I'm setting an Ansible fact like this:
>>
>> set_fact: server_num={{ ansible_hostname[-2:] }}
>>
>> server_num can take these values:
>>
>> '00'
>> '01'
>> '02'
>> '03'
>> '04'
>> ad infinitum
>>
>> If I want a conditional that will evaluate to True for all server numbers
>> less than a particular server number 'n' I'd like to be able to do this:
>>
>> when: server_num < 'n'
>>
>> However, this throws the error "error while evaluating conditional:
>> server_num < 'n'
>>
>> I could do this but clearly it doesn't scale:
>>
>> when: server_num == '00' or server_num == '01' or ... or server_num ==
>> 'n-1'
>>
>> Is there a more succinct way to do this? I can't seem to find a Jinja2
>> "less than" operator.
>>
>> Thanks.
>>
> --
> 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/a41571c0-9e9c-42c3-a6ed-b5abebc02732%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/a41571c0-9e9c-42c3-a6ed-b5abebc02732%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
Matt Martz
@sivel
sivel.net
--
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/CAD8N0v8_O%2B5SYiBJ68b5DykoqOwuTBgTYjWaGsZc5xkK3oBA1Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.