feat: Moves playbook into resources of cli-client.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
---
|
||||
# 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:
|
||||
|
||||
# The preject directory to setup in.
|
||||
project_dir: "{{ lookup('env', 'PWD') }}"
|
||||
|
||||
# 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.
|
||||
#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: []
|
||||
@@ -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
|
||||
@@ -0,0 +1,120 @@
|
||||
---
|
||||
- name: Starting setup project.
|
||||
ansible.builtin.debug:
|
||||
msg: "Project dir: {{ project_dir }}"
|
||||
tags:
|
||||
- setup-project
|
||||
- never
|
||||
|
||||
- name: Debug template vars pre parse.
|
||||
ansible.builtin.debug:
|
||||
var: template
|
||||
tags:
|
||||
- debug
|
||||
- never
|
||||
|
||||
- name: Debug build dir.
|
||||
ansible.builtin.debug:
|
||||
var: build_dir
|
||||
tags:
|
||||
- debug
|
||||
- never
|
||||
|
||||
- name: Parse template facts.
|
||||
ansible.builtin.include_role:
|
||||
name: "prepare-template-facts"
|
||||
tags:
|
||||
- setup-project
|
||||
- never
|
||||
|
||||
|
||||
- name: Debug template path post parse.
|
||||
ansible.builtin.debug:
|
||||
var: template_dir
|
||||
tags:
|
||||
- debug
|
||||
- never
|
||||
|
||||
- name: Ensure output directory exists.
|
||||
ansible.builtin.file:
|
||||
path: "{{ project_dir }}"
|
||||
state: directory
|
||||
tags:
|
||||
- setup-project
|
||||
- never
|
||||
|
||||
- name: Load template vars.
|
||||
ansible.builtin.include_role:
|
||||
name: "load-template-vars"
|
||||
tags:
|
||||
- setup-project
|
||||
- never
|
||||
|
||||
- name: Debug on_setup.
|
||||
ansible.builtin.debug:
|
||||
msg: "On setup vars: {{ copy_on_setup }}"
|
||||
tags:
|
||||
- debug
|
||||
- never
|
||||
|
||||
- name: Debug copy directory contents.
|
||||
ansible.builtin.debug:
|
||||
var: 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
|
||||
tags:
|
||||
- setup-project
|
||||
- never
|
||||
|
||||
- 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
|
||||
tags:
|
||||
- setup-project
|
||||
- never
|
||||
|
||||
- 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_dir }}/{{ item.src | default(item) }}"
|
||||
destination: "{{ project_dir }}/{{ item.dest | default(item) }}"
|
||||
mode: "{{ item.mode | default('0600') }}"
|
||||
loop: "{{ copy_on_setup }}"
|
||||
tags:
|
||||
- setup-project
|
||||
- never
|
||||
|
||||
- name: Create setup file.
|
||||
ansible.builtin.template:
|
||||
src: "templates/setup.txt"
|
||||
dest: "{{ project_dir }}/.setup"
|
||||
mode: '0600'
|
||||
when: not setup_file.stat.exists
|
||||
tags:
|
||||
- setup-project
|
||||
- never
|
||||
@@ -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