feat: Working on not needing to supply template path when using a repo in setup-project

This commit is contained in:
2024-11-27 11:53:46 -05:00
parent e81d9b8f0c
commit ee91b060eb
4 changed files with 92 additions and 9 deletions

View File

@@ -1,12 +1,14 @@
--- ---
# TODO: When using a template repo, we should probably clone it into
# the project directory somewhere.
# template_dir: # template_dir:
# path: "/path/to/template/dir # path: "/path/to/template/dir
# vars: "repo_vars" # vars: "repo_vars"
# repo: (optional if using a repo as a template) # repo: (optional if using a repo as a template)
template: template:
path: "/path/to/template/dir" #path: "/path/to/template/dir"
vars: "repo_vars" #vars: "repo_vars"
# When using a repository as a template dir. In general, it's # When using a repository as a template dir. In general, it's
# probably best to pin to a particular version of the repo template # probably best to pin to a particular version of the repo template
@@ -15,10 +17,10 @@ template:
# repo: # repo:
# url: "https://example.com/repo.git" # url: "https://example.com/repo.git"
# version: "main" # version: "main"
repo: {} #repo: {}
# The output directory to setup a project in. # The preject directory to setup in.
output_dir: "{{ lookup('env', 'PWD') }}" project_dir: "{{ lookup('env', 'PWD') }}"
# Files that are copied from the template directory to the output # Files that are copied from the template directory to the output
# directory. # directory.

View File

@@ -1,11 +1,43 @@
--- ---
- name: Starting setup project. - name: Starting setup project.
ansible.builtin.debug: ansible.builtin.debug:
msg: "Output dir: {{ output_dir }}" msg: "Project dir: {{ project_dir }}"
- name: Debug template vars pre parse.
ansible.builtin.debug:
var: template
tags:
- debug
- never
- name: Parse template path.
ansible.builtin.set_fact:
template:
path: "{{ project_dir }}/{{ build_dir | default('.build') }}/template"
when: not template.path is defined
- name: Parse template vars.
ansible.builtin.set_fact:
template:
vars: "repo_vars"
when: not template.vars is defined
# - name: Prepare variables.
# ansible.builtin.include_tasks:
# file: "prepare_vars.yml"
# vars:
# template: "{{ template }}"
- name: Debug template vars post parse.
ansible.builtin.debug:
var: template
tags:
- debug
- never
- name: Ensure output directory exists. - name: Ensure output directory exists.
ansible.builtin.file: ansible.builtin.file:
path: "{{ output_dir }}" path: "{{ project_dir }}"
state: directory state: directory
- name: Ensure repo. - name: Ensure repo.
@@ -37,6 +69,6 @@
file: "copy_if_not_exists.yml" file: "copy_if_not_exists.yml"
vars: vars:
source: "{{ template.path }}/{{ item.src | default(item) }}" source: "{{ template.path }}/{{ item.src | default(item) }}"
destination: "{{ output_dir }}/{{ item.dest | default(item) }}" destination: "{{ project_dir }}/{{ item.dest | default(item) }}"
mode: "{{ item.mode | default('0600') }}" mode: "{{ item.mode | default('0600') }}"
loop: "{{ copy_on_setup }}" loop: "{{ copy_on_setup }}"

View File

@@ -0,0 +1,16 @@
---
- name: Parse template path.
ansible.builtin.set_fact:
template:
path: "{{ project_dir }}/{{ build_dir | default('.build') }}/template"
when: not template.path is defined
tags:
- always
- name: Parse template vars.
ansible.builtin.set_fact:
template:
vars: "repo_vars"
when: not template.vars is defined
tags:
- always

View File

@@ -10,7 +10,7 @@
template_dir: template_dir:
path: "/tmp/hpa-playbook-tmp" path: "/tmp/hpa-playbook-tmp"
vars: "repo_vars" vars: "repo_vars"
output_dir: "/tmp/hpa-setup-project-tmp" project_dir: "/tmp/hpa-setup-project-tmp"
- role: repo-template - role: repo-template
tags: tags:
@@ -25,3 +25,36 @@
path: "/tmp/hpa-playbook-tmp" path: "/tmp/hpa-playbook-tmp"
vars: "repo_vars" vars: "repo_vars"
project_dir: "/tmp/hpa-setup-project-tmp" project_dir: "/tmp/hpa-setup-project-tmp"
tasks:
- name: Test complex var, set fact.
ansible.builtin.set_fact:
template_path: "{{ template.path | default('.build') }}"
vars:
template:
repo:
url: "https://example.com"
version: "main"
tags:
- vars
- never
- name: Test complex var, set fact when path is specified.
ansible.builtin.set_fact:
template_path_specified: true
vars:
template:
repo:
url: "https://example.com"
version: "main"
when: template.path is defined
tags:
- vars
- never
- name: Test complex var was set.
ansible.builtin.debug:
msg: "Template path: {{ template_path }}, specified: {{ template_path_specified | default(false) }}"
tags:
- vars
- never