Inline expressions

Reference: Inline ‘if’ expressions

It’s possible to use inline if-expressions:

{{ 'Update' if files else 'Continue' }} 

Note: See the Jinja2 Filters section for more information.

‘if/else’ example

Reference: cidr block’s git repo

"{{ 'unknown' if ssh_output|failed else ssh_output['stdout'][0]|determine_os}}"

Note: See the Jinja2 Filters section for more information.

‘When’ example

Reference: Ansible

tasks:
    - shell: echo "I've got '' and am not afraid to use it!"
      when: foo is defined

    - fail: msg="Bailing out. this play requires 'bar'"
      when: bar is undefined

As always, if you have any questions or have a topic that you would like me to discuss, please feel free to post a comment at the bottom of this blog entry, e-mail at will@oznetnerd.com, or drop me a message on Reddit (OzNetNerd).

Note: The opinions expressed in this blog are my own and not those of my employer.

Leave a comment