Reputation: 14470
I am new to ansible and looking for some guideline to run some tasks if desired OS version/release is found else skip all tasks ( i.e exist with message).
Upvotes: 0
Views: 1971
Reputation: 20719
If you want to exit with a message if a variable isn't set to what you want then something like this will work:
- name: Fail if not running on CentOS 6
fail: msg="These tasks should only be run on CentOS 6 servers"
when: ansible_distribution != "CentOS" or ansible_distribution_version|int != 6
Or if the variable simply doesn't exist:
- name: Fail if variable foo is unknown
fail: msg="Variable foo is not defined"
when: foo is not defined
If you want to just skip over tasks when the OS doesn't match but want to continue execution then you'll need to add "when" clauses to all your tasks that verify the OS variables.
Upvotes: 2