From 932cea2494377ddb28db6c3382ee12f1ea8328e4 Mon Sep 17 00:00:00 2001 From: Dan Mick Date: Tue, 30 Sep 2025 19:23:34 -0700 Subject: [PATCH] builder.yml: make playbook more flexible for finding templates Many things are relative to 'playbook_dir', but some people keep a symlink to examples/builder.yml and some don't. I can't think of a way to fix, say, the module library path 'library/', but I can make it better for templates. Signed-off-by: Dan Mick --- ansible/examples/builder.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ansible/examples/builder.yml b/ansible/examples/builder.yml index d422ffa1..ecec0b4a 100644 --- a/ansible/examples/builder.yml +++ b/ansible/examples/builder.yml @@ -1049,9 +1049,24 @@ force: yes register: jar_changed + - name: look for templates/ + ansible.builtin.stat: + path: templates + delegate_to: localhost + run_once: true + register: template_dir + + - name: choose proper templates dir + set_fact: + template_path: "{{ 'templates' if template_dir.stat.exists else '../templates' }}" + + - name: echo template_path + debug: + msg: "template_path: {{ template_path }}" + - name: Install the systemd unit files for jenkins ansible.builtin.template: - src: "{{ playbook_dir }}/../templates/systemd/jenkins.{{ item }}.j2" + src: "{{ template_path }}/systemd/jenkins.{{ item }}.j2" dest: "/etc/systemd/system/jenkins.{{ item }}" force: yes with_items: -- 2.39.5