Sandro Koch
Sandro Koch

Reputation: 315

Ansible create variable depending on condition

I want to create a variable depending on the distribution, the following code does not work and i dont know why:

- name: Get Release
  vars: release: xenial
  when: (ansible_distribution_release == 'qiana') or 
        (ansible_distribution_release == 'rebecca') or 
        (ansible_distribution_release == 'rafaela') or 
        (ansible_distribution_release == 'rosa')

Upvotes: 2

Views: 955

Answers (1)

udondan
udondan

Reputation: 60079

the following code does not work and i dont know why

Because there is no module named vars.

You can do this with the set_fact module:

- name: Get Release
  set_fact:
    release: xenial
  when: (ansible_distribution_release == 'qiana') or 
        (ansible_distribution_release == 'rebecca') or 
        (ansible_distribution_release == 'rafaela') or 
        (ansible_distribution_release == 'rosa')

Upvotes: 5

Related Questions