I am using Ansible as part of my GitLab CI/CD pipeline, and I have separate playbooks for rendering configs for my app and Nginx. The folder structure looks like this
├── XXX/YYY/playbook.yml
├── templates
│ ├── app
│ │ └── app_template.j2
│ │ └── common_var.inc
│ │
│ └── nginx
│ └── sites-available
│ └── nginx_template.j2
All works fine until I try to include some vars from common_var.inc
in the nginx_template.j2
. No matter what type of path I am using, relative or absolute, I have got the following error:
jinja2.exceptions.TemplateNotFound: /home/gitlab-runner/builds/inqzetdg/0/configs/ZZZ/templates/app/common_var.inc
The file exists and contains a line like this:
{% set C.domain = "domain.tld" %}
Here is a Snippet from the Playbook that I use for rendering NGINX configs:
- name: Rendering nginx configs
template:
src: "{{ lookup('env','CI_PROJECT_DIR') }}/templates/nginx/sites-available/{{ item }}.j2"
dest: "/etc/nginx/sites-available/{{ item }}.stage"
force: yes
with_items: "{{ vhost_list.stdout_lines }}"
I added debug for the ‘ansible_search_path’ var, and it looks in the following way:
# search: ['/home/gitlab-runner/builds/inqzetdg/0/configs/ZZZ/XXX/YYY/playbooks', '/home/gitlab-runner/builds/inqzetdg/0/configs/ZZZ/XXX/YYY/playbooks', '/home/gitlab-runner/builds/inqzetdg/0/configs/ZZZ/templates/nginx/sites-available', '/home/gitlab-runner/builds/inqzetdg/0/configs/ZZZ/XXX/YYY/playbooks', '/home/gitlab-runner/builds/inqzetdg/0/configs/ZZZ/templates/nginx/sites-available']
How can I add {{ lookup('env','CI_PROJECT_DIR') }}/templates/app
to the ansible_search_path
?
Why does the absolute path not work?
Thank you!