Something like include_vars but for playbooks

36 views
Skip to first unread message

Diego Lagos

unread,
Oct 13, 2015, 10:40:44 AM10/13/15
to Ansible Project
Hello to all,

I need to choose between two variables file depending on an external parameter.

E.g in a task file
- include_vars: jboss_5.yml
 
when: "{{ my_app_version | version_compare('8', '=') }}"

- include_vars: jboss_7.yml
 
when: "{{ my_app_version | version_compare('10', '=') }}"

This files vars contains the java version, the paths, and others info, useful for the installation.
Because my app use different version of jboss.

Inside tasks I can safely use include_vars and version compare, as showed.

But I want that this mechanism could be used in a playbook, so that all my play can use variables valorised correctly
right now i must use this workaround that i don't like it

- name: Install app_node_1
  hosts: node_1
  remote_user: "{{ remote_host_user }}"
  sudo: yes
  gather_facts: yes

  vars_files:

  - roles/my_app/vars/{{ my_app_version }}_vars.yml

  etc ....


- name: Install app_node_2
  hosts: node_2
  remote_user: "{{ remote_host_user }}"
  sudo: yes
  gather_facts: yes

  vars_files:

  - roles/my_app/vars/{{ my_app_version }}_vars.yml

  etc ....


In this case if for example there are two problems
1. there are a repeated code
2. if for example my app version is 9, and have the same configuration as 8 for jboss, i need to create another file even if i don't need it.

There are a simple and more linear way to include global vars for playbook, but with a condition as showed before?


Thx so much.

Diego Mauricio
Reply all
Reply to author
Forward
0 new messages