Run role based on local facts - if variable is not defined.

Good morning.

I am trying using local facts for tracking version of the role, and run this role only if version increased (version kept locally within role comparing with version from local fatcs).

So this is how is working:
Role folder

  • vars/main.yml
  • tasks/main.yml

So this is example for: vars/main.yml

Python (and Jinja) practices short circuit evaluation. So move the “is defined” test ahead of the numeric test, and you should be ok.

Hi,

Can I have a bit of more light of this please?
I checked what means short circuit evaluation (http://en.wikipedia.org/wiki/Short-circuit_evaluation) however my evaluation is not working.

roles:

  • { role: test_roleversion,
    when: “ansible_local.apache.version not defined or module.version > ansible_local.apache.version” }

Return error:
fatal: [IP-HERE] => error while evaluating conditional: ansible_local.apache.version not defined or module.version > ansible_local.apache.version

Thanks for help.
Marcin P.

Hi,

Seems be working - that to be some TABS instead of spaces on the begining of line:

roles:

  • { role: test_roleversion,
    when: ansible_local.apache.version is not defined or module.version > ansible_local.apache.version}Best regards,

Thanks for help.
Marcin Praczko

Hi,

Don’t know why worked only once, no luck with this still.
Givining up.: ( :frowning:

This syntax at a least run condition everytime and not reporting error:
roles:

  • { role: test_roleversion,
    when: { ansible_local.apache.version is not defined or module.version > ansible_local.apache.version } }

Everything else which I tried after running command on remote node: rm -f /etc/ansible/facts/* failed with error:

error while evaluating conditional: ansible_local.apache.version is not defined or module.version > ansible_local.apache.version

Marcin.

The YAML parser may be reading the ‘>’ as the line continuation character, so you may need to wrap that in quotes:

  • { role: test_roleversion, when: “ansible_local.apache.version is not defined or module.version > ansible_local.apache.version” }

Hi,

I think problem lies in multi level of variable:
Checking if ansible_local is defined working as expected, however checking
ansible_local.somevars - here automatically raise and error.

This means that variable must be check from top level to bootom.

If ansible_local is not defined and ansible_local.somevar is not define and if ansible_local.somevar.a is not defined …

Best regards,
Marcin