Skip to content

Instantly share code, notes, and snippets.

@zeitounator
Last active October 16, 2023 23:29
Show Gist options
  • Save zeitounator/d2b9b577f7224633a31f32457ef1d9f0 to your computer and use it in GitHub Desktop.
Save zeitounator/d2b9b577f7224633a31f32457ef1d9f0 to your computer and use it in GitHub Desktop.
######################################
# Step 1: basic fix so it just works #
######################################
# In role
- name: Upload template.text
become: true
template:
src: templates/template.text
dest: /lib/template.text
vars:
VARIABLE_A: {{ PLAYBOOK_VARIABLE_A }}
# In playbook
- name: Setup Management Server
hosts: management_server
roles:
- ../roles/test-role
vars:
PLAYBOOK_VARIABLE_A: test_value
#######################################################
# Step 2: remove backward dep from role #
# Set that `VARIABLE_A` in your role default/main.yml #
# and override it in playbook to what you wish #
#######################################################
# In role
- name: Upload template.text
become: true
template:
src: templates/template.text
dest: /lib/template.text
# In playbook
- name: Setup Management Server
hosts: management_server
roles:
- ../roles/test-role
vars:
VARIABLE_A: test_value
#############################################################
# Option: now if you really need that env var for something #
# You don't show in your question, just declare it with the #
# value from the var #
#############################################################
# In playbook
- name: Setup Management Server
hosts: management_server
roles:
- ../roles/test-role
vars:
VARIABLE_A: test_value
environment:
AN_ENV_VAR_USED_ON_TARGET: "{{ VARIABLE_A }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment