i having trouble getting jinja2 template ansible able read global variable set in group_vars/all.yml.
** question **: how can j2 template able see global variables set within group_vars/all.yml? understanding, group_vars/all should apply groups.
my ansible project follows:
group_vars/ all.yml playbooks/ roles/ some-role/ tasks/ main.yml templates/ template.conf.j2 my-playbook.yml tasks/main.yml
--- - name: template: src: template.conf.j2 dest: ... templates/template.conf.j2
the global variable is: {{ globalvariable }} group_vars/all.yml
globalvariable: when run playbook, error when trying write template.
ansibleundefinedvariable: 1 or more undefined variables: 'globalvariable' undefined
place group_vars folder inside playbooks folder , should solve problem.
something that:
playbooks/ group_vars/ all.yml roles/ some-role/ tasks/ main.yml templates/ template.conf.j2 my-playbook.yml then no matter executing ansible-playbook -i hosts my-playbook.yml command (outside of playbook or inside) should work
here little more explanation reference source-code
""" loads variables group_vars/<groupname> , host_vars/<hostname> in directories parallel inventory base directory or in same directory playbook. variables in playbook dir win on inventory dir if files in both. """
Comments
Post a Comment