feat: Reorganizes some of the roles and renames some variables
This commit is contained in:
@@ -13,23 +13,13 @@
|
||||
path: "{{ build_dir }}"
|
||||
state: directory
|
||||
|
||||
- name: Ensure template repo.
|
||||
ansible.builtin.git:
|
||||
repo: "{{ template.repo.url }}"
|
||||
dest: "{{ template.path }}"
|
||||
version: "{{ template.repo.version | default('main') }}"
|
||||
when: template.repo.url is defined
|
||||
|
||||
- name: Check for repo vars directory.
|
||||
ansible.builtin.stat:
|
||||
path: "{{ template.path }}/{{ template.vars }}"
|
||||
register: repo_vars
|
||||
|
||||
- name: Load repo vars if available.
|
||||
ansible.builtin.include_vars:
|
||||
dir: "{{ template.path }}/{{ template.vars }}"
|
||||
when: repo_vars.stat.isdir is defined
|
||||
- name: Parse template facts.
|
||||
ansible.builtin.include_role:
|
||||
name: "prepare-template-facts"
|
||||
|
||||
- name: Load repo vars.
|
||||
ansible.builtin.include_role:
|
||||
name: "load-template-vars"
|
||||
|
||||
- name: Copy build files.
|
||||
ansible.builtin.copy:
|
||||
|
||||
27
roles/load-template-vars/tasks/main.yml
Normal file
27
roles/load-template-vars/tasks/main.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
---
|
||||
# Used internally to clone the template repo, if applicable and load it's
|
||||
# variables.
|
||||
#
|
||||
# NOTE: This expects that you've called prepare-template-facts first.
|
||||
|
||||
- name: Check if template path exists.
|
||||
ansible.builtin.stat:
|
||||
path: "{{ template_dir }}"
|
||||
register: template_dir_stat
|
||||
|
||||
- name: Ensure repo.
|
||||
ansible.builtin.git:
|
||||
repo: "{{ template.repo.url }}"
|
||||
dest: "{{ template_dir }}"
|
||||
version: "{{ template.repo.version | default('main') }}"
|
||||
when: template.repo.url is defined and not template_dir_stat.stat.exists
|
||||
|
||||
- name: Check for repo vars directory.
|
||||
ansible.builtin.stat:
|
||||
path: "{{ template_vars_path }}"
|
||||
register: repo_vars
|
||||
|
||||
- name: Load repo vars if available.
|
||||
ansible.builtin.include_vars:
|
||||
dir: "{{ template_vars_path }}"
|
||||
when: repo_vars.stat.isdir is defined
|
||||
15
roles/prepare-template-facts/tasks/main.yml
Normal file
15
roles/prepare-template-facts/tasks/main.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
# This role is used internally to parse template variables, depending on
|
||||
# what is supplied.
|
||||
#
|
||||
- name: Set default template path.
|
||||
ansible.builtin.set_fact:
|
||||
repo_template_path: "{{ build_dir }}/template"
|
||||
|
||||
- name: Parse template path.
|
||||
ansible.builtin.set_fact:
|
||||
template_dir: "{{ template.path | default(repo_template_path) }}"
|
||||
|
||||
- name: Parse template vars path.
|
||||
ansible.builtin.set_fact:
|
||||
template_vars_path: "{{ template_dir }}/{{ template.vars | default('repo_vars') }}"
|
||||
@@ -1,29 +1,49 @@
|
||||
---
|
||||
# TODO: When using a template repo, we should probably clone it into
|
||||
# the project directory somewhere.
|
||||
|
||||
# template_dir:
|
||||
# path: "/path/to/template/dir
|
||||
# vars: "repo_vars"
|
||||
# repo: (optional if using a repo as a template)
|
||||
# template:
|
||||
# path: "/path/to/local/template/dir
|
||||
# vars: "repo_vars" (optional path inside template directory to find variables, defaults to 'repo_vars')
|
||||
#
|
||||
# OR
|
||||
#
|
||||
# template:
|
||||
# repo:
|
||||
# url: "https://example.com/template.git
|
||||
# version: "1.0.0" or "branch" (tagging to a version is more ideal)
|
||||
#
|
||||
template:
|
||||
#path: "/path/to/template/dir"
|
||||
#vars: "repo_vars"
|
||||
|
||||
# When using a repository as a template dir. In general, it's
|
||||
# probably best to pin to a particular version of the repo template
|
||||
# instead of a branch.
|
||||
#
|
||||
# repo:
|
||||
# url: "https://example.com/repo.git"
|
||||
# version: "main"
|
||||
#repo: {}
|
||||
|
||||
# The preject directory to setup in.
|
||||
project_dir: "{{ lookup('env', 'PWD') }}"
|
||||
|
||||
# Files that are copied from the template directory to the output
|
||||
# This path get's setup / parsed based on the template variable,
|
||||
# it will point to the directory of the template, which could be a
|
||||
# local path on the system or inside of the project directory, depending
|
||||
# on if the template is a repo or not.
|
||||
#
|
||||
# This is safe to use inside of the project or template specifications
|
||||
# for paths to files that live in the template directory not the project
|
||||
# directory.
|
||||
copy_on_setup:
|
||||
- "Report.md"
|
||||
- "vars.yml"
|
||||
template_dir: ""
|
||||
|
||||
# Files or directories that are copied from the template directory to the project
|
||||
# directory.
|
||||
#
|
||||
# These can be a simple item that is a path from the root of the template directory
|
||||
# to a file, which will copy the file to the root of the project directory or
|
||||
# in the form of:
|
||||
#
|
||||
# src: "path/in/template/dir"
|
||||
# dest: "path/in/project/dir"
|
||||
# mode: '0600' (optional mode of the file/dir to copy)
|
||||
#
|
||||
copy_on_setup: []
|
||||
|
||||
# Copies the entire contents of a directory to the root of the project directory.
|
||||
#
|
||||
# This is useful if you keep all the template files in a sub-directory of your project
|
||||
# template, it will copy that entire directory over when setting up a new project.
|
||||
#
|
||||
# NOTE: If the project has been setup (indicated by a .setup file) this
|
||||
# will be skipped so that it does not overwrite any changes to the
|
||||
# project files. This ensures that a project is only setup once.
|
||||
copy_directory_on_setup: []
|
||||
|
||||
@@ -10,27 +10,20 @@
|
||||
- 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.
|
||||
- name: Debug build dir.
|
||||
ansible.builtin.debug:
|
||||
var: template
|
||||
var: build_dir
|
||||
tags:
|
||||
- debug
|
||||
- never
|
||||
|
||||
- name: Parse template facts.
|
||||
ansible.builtin.include_role:
|
||||
name: "prepare-template-facts"
|
||||
|
||||
- name: Debug template path post parse.
|
||||
ansible.builtin.debug:
|
||||
var: template_dir
|
||||
tags:
|
||||
- debug
|
||||
- never
|
||||
@@ -40,22 +33,9 @@
|
||||
path: "{{ project_dir }}"
|
||||
state: directory
|
||||
|
||||
- name: Ensure repo.
|
||||
ansible.builtin.git:
|
||||
repo: "{{ template.repo.url }}"
|
||||
dest: "{{ template.path }}"
|
||||
version: "{{ template.repo.version | default('main') }}"
|
||||
when: template.repo.url is defined
|
||||
|
||||
- name: Check for repo vars directory.
|
||||
ansible.builtin.stat:
|
||||
path: "{{ template.path }}/{{ template.vars }}"
|
||||
register: repo_vars
|
||||
|
||||
- name: Load repo vars if available.
|
||||
ansible.builtin.include_vars:
|
||||
dir: "{{ template.path }}/{{ template.vars }}"
|
||||
when: repo_vars.stat.isdir is defined
|
||||
- name: Load template vars.
|
||||
ansible.builtin.include_role:
|
||||
name: "load-template-vars"
|
||||
|
||||
- name: Debug on_setup.
|
||||
ansible.builtin.debug:
|
||||
@@ -64,11 +44,52 @@
|
||||
- debug
|
||||
- never
|
||||
|
||||
- name: Debug copy directory contents.
|
||||
ansible.builtin.debug:
|
||||
var: unsafe_copy_directory_on_setup
|
||||
tags:
|
||||
- debug
|
||||
- never
|
||||
|
||||
- name: Check if project has been previously setup.
|
||||
ansible.builtin.stat:
|
||||
path: "{{ project_dir }}/.setup"
|
||||
register: setup_file
|
||||
|
||||
- name: Debug setup file stat.
|
||||
ansible.builtin.debug:
|
||||
var: setup_file.exists
|
||||
tags:
|
||||
- debug
|
||||
- never
|
||||
|
||||
- name: Copy directory contents to project directory.
|
||||
ansible.builtin.command: |
|
||||
cp -r "{{ template_dir }}/{{ item.src | default(item) }}/." \
|
||||
"{{ item.dest | default(project_dir) }}"
|
||||
with_items: "{{ copy_directory_on_setup }}"
|
||||
when: setup_file.stat.exists is false
|
||||
register: copy_directory_stat
|
||||
|
||||
- name: Debug copy directory stat.
|
||||
ansible.builtin.debug:
|
||||
var: copy_directory_stat
|
||||
tags:
|
||||
- debug
|
||||
- never
|
||||
|
||||
- name: Copy project files.
|
||||
ansible.builtin.include_tasks:
|
||||
file: "copy_if_not_exists.yml"
|
||||
vars:
|
||||
source: "{{ template.path }}/{{ item.src | default(item) }}"
|
||||
source: "{{ template_dir }}/{{ item.src | default(item) }}"
|
||||
destination: "{{ project_dir }}/{{ item.dest | default(item) }}"
|
||||
mode: "{{ item.mode | default('0600') }}"
|
||||
loop: "{{ copy_on_setup }}"
|
||||
|
||||
- name: Create setup file.
|
||||
ansible.builtin.template:
|
||||
src: "templates/setup.txt"
|
||||
dest: "{{ project_dir }}/.setup"
|
||||
mode: '0600'
|
||||
when: not setup_file.stat.exists
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
---
|
||||
- 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
|
||||
7
roles/setup-project/templates/setup.txt
Normal file
7
roles/setup-project/templates/setup.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
This file is managed by the ansible-hpa-playbook. It is an indication
|
||||
that the project using the template.
|
||||
|
||||
{{ template.repo.url | default(template_dir) }}
|
||||
|
||||
Has already called setup. This file should not be removed or subsequent calls
|
||||
to setup may overwrite existing data.
|
||||
Reference in New Issue
Block a user