Maths on variables in tasks/playbooks

You can do things like this trivially in Jinaj2 if you are using templates.

I am considering for Ansible 1.2 allowing {{ foo }} syntax in
playbooks (as the preferred form, actually... but it may not actually
be Jinja2, in which case, yes, this will be possible.

What you ask for is basically an "$EVAL" lookup plugin, which is
something I've been hesistant to add because it needs to be very well
sandboxed and I want to make sure the syntax is decent.

In general, I dislike the look of lookup macros, so this is why I'm
pushing for {{ foo / 2 }} being possible in 1.2.

I understand the syntax you've shown is somewhat suboptimal, but it's
what you have for now.

I would of course be very tempted to not use Lineinfile -- I *ALWAYS*
try not to, and just use a template, in which case this becomes easy
and you can use math trivally.

--Michael

You can do things like this trivially in Jinaj2 if you are using templates.

I am considering for Ansible 1.2 allowing {{ foo }} syntax in
playbooks (as the preferred form, actually… but it may not actually
be Jinja2, in which case, yes, this will be possible.

{{ foo }} syntax was what I was hoping for. It opens a whole bunch of possibilities and is consistant. Even better (from my user point of view) if it’s Jinja2 as what works in templates would work in playbooks.

What you ask for is basically an “$EVAL” lookup plugin, which is
something I’ve been hesistant to add because it needs to be very well
sandboxed and I want to make sure the syntax is decent.

Simple template-like function is enough. I don’t really want to be shelling out to do this stuff.

I understand the syntax you’ve shown is somewhat suboptimal, but it’s
what you have for now.

I can dig that. It’s more a matter of aesthetics :slight_smile:

I would of course be very tempted to not use Lineinfile – I ALWAYS
try not to, and just use a template, in which case this becomes easy
and you can use math trivally.

The nice thing about lineinfile is I can leave everything at the OS defaults apart from the bits I want to modify which is useful where configs include paths and the like, though I take the point about templates.

Matt