Last active
October 16, 2023 23:29
-
-
Save zeitounator/d2b9b577f7224633a31f32457ef1d9f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###################################### | |
# 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