0

I've got a variable in Ansible that I use to pass environment variables to a task. However, I've got another playbook that uses the role, and I'd like to tack more values onto the variable. How can I accomplish this? For example, I want to have a different ORACLE_HOME depending on which type of server I'm running the playbook against.

--- group_vars/application.yml
environment_vars:
  PIP_EXTRA_INDEX_URL=https://my.local.repo/pypi

--- group_vars/ubuntu.yml
environment_vars:
  ORACLE_HOME: '/usr/lib/oracle/instantclient_11_2'

--- group_vars/centos.yml
environment_vars:
  ORACLE_HOME: '/opt/oracle/instantclient_11_2'

--- roles/test_role/tasks/main.yml
- name: Install Python Requirements
  pip:
    name: my_app==1.0
  environment: environment_vars

--- main.yml
- hosts: application
  roles: 
    - role: test_role

--- inventory
[application:children]
ubuntu
centos
Adam Ness
  • 6,224
  • 4
  • 27
  • 39

1 Answers1

0

I'd do it this way:

environment_vars:
  ORACLE_HOME: >
    {% if ansible_distribution=='CentOS' %}
      /opt/oracle/instantclient_11_2
    {% elif ansible_distribution == 'Debian' %}
      /usr/local/oracle/instantclient_11_2
    {% else %}
      /dev/null
    {% endif %}

It may need some tweaking to get rid of white space.

Antonis Christofides
  • 6,990
  • 2
  • 39
  • 57
  • That has the consequence of having ORACLE_HOME be /dev/null on unmatched hosts, which could be a destructive behavior. The if stuff might work though. – Adam Ness Jun 04 '15 at 20:44