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
---
module:
name: "apache"
version: "1.0.4"
status: "Installed"And this is a task which writes this variables to local facts on remote machine:
- name: Write variable to json file
copy: content="{{ module }}" dest=/etc/ansible/facts.d/{{ module.name }}.fact
owner=root group=root mode=0644And json is written to localfacts - which is working well.
Now I am trying to do something like that in main playbook:
roles:
- { role: test_roleversion,
when: "module.version > ansible_local.apache.version" }This is working well if local facts already exists with 'version' variable. Hower when file is not there ansible complain about not defined variable:
fatal: [IP-HERE] => error while evaluating conditional: module.version > ansible_local.apache version
Question:How to run role only if:
- module.version > ansible_local.apache.version (<- this come from local facts), or
- ansible_local.apache.version is not defined?
Following example does't work :(
roles:
- { role: test_roleversion,
when: "module.version > ansible_local.apache.version or ansible_local.apache.version not defined" }
Thanks for helping in advance.
Best regards,
Marcin Praczko