feat: Initial roles

This commit is contained in:
2024-11-26 14:26:58 -05:00
parent 3a4285a397
commit 916e62f6e6
19 changed files with 203 additions and 44 deletions

View File

@@ -1,11 +1,27 @@
---
template_repo:
repo: "https://example.com/repo.git"
version: "main"
dest: "/path/to/clone"
# template_dir:
# path: "/path/to/template/dir
# vars: "repo_vars"
# repo: (optional if using a repo as a template)
template_dir:
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 output directory to setup a project in.
output_dir: "{{ lookup('env', 'PWD') }}"
files_to_copy:
# Files that are copied from the template directory to the output
# directory.
copy_on_setup:
- "Report.md"
- "vars.yml"

View File

@@ -0,0 +1,19 @@
---
# NOTE: This is just an internal task that checks if a file exists
# before copying, to prevent changes from being overwritten.
#
- name: "Check if {{ destination | basename }} exists already."
ansible.builtin.stat:
path: "{{ destination }}"
register: filestat
tags:
- always
- name: "Copy {{ destination | basename }} file."
ansible.builtin.copy:
src: "{{ source }}"
dest: "{{ destination }}"
mode: "{{ mode | default('0600') }}"
when: not filestat.stat.exists
tags:
- always

View File

@@ -2,13 +2,41 @@
- name: Starting setup project.
ansible.builtin.debug:
msg: "Output dir: {{ output_dir }}"
tags:
- setup-project
- name: Ensure output directory exists.
ansible.builtin.file:
path: "{{ output_dir }}"
state: directory
- name: Ensure repo.
ansible.builtin.git:
repo: "{{ template_repo.repo }}"
dest: "{{ template_repo.dest }}"
version: "{{ template_repo.version }}"
repo: "{{ template_dir.repo.url }}"
dest: "{{ template_dir.path }}"
version: "{{ template_dir.repo.version | default('main') }}"
when: template_dir.repo.url is defined
- name: Check for repo vars directory.
ansible.builtin.stat:
path: "{{ template_dir.path }}/{{ template_dir.vars }}"
register: repo_vars
- name: Load repo vars if available.
ansible.builtin.include_vars:
dir: "{{ template_dir.path }}/{{ template_dir.vars }}"
when: repo_vars.stat.isdir is defined
- name: Debug on_setup.
ansible.builtin.debug:
msg: "On setup vars: {{ copy_on_setup }}"
tags:
- setup-project
- debug
- never
- name: Copy project files.
ansible.builtin.include_tasks:
file: "copy_if_not_exists.yml"
vars:
source: "{{ template_dir.path }}/{{ item }}"
destination: "{{ output_dir }}/{{ item }}"
mode: '0600'
with_items: "{{ copy_on_setup }}"