feat: Adds a copy if not exists task, so that setup doesn't overwrite files if they exist.
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
---
|
---
|
||||||
- name: Debug.
|
- name: Debug.
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: "Using {{ config.build_dir }}"
|
msg: "Using {{ build_dir }}"
|
||||||
tags:
|
tags:
|
||||||
- debug
|
- debug
|
||||||
|
|
||||||
- name: Ensure build directory exists.
|
- name: Ensure build directory exists.
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ config.build_dir }}"
|
path: "{{ build_dir }}"
|
||||||
state: "directory"
|
state: "directory"
|
||||||
mode: '0755'
|
mode: '0755'
|
||||||
tags:
|
tags:
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
- name: Copy Build Files.
|
- name: Copy Build Files.
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
src: "{{ item.src }}"
|
src: "{{ item.src }}"
|
||||||
dest: "{{ config.build_dir }}/{{ item.dest }}"
|
dest: "{{ build_dir }}/{{ item.dest }}"
|
||||||
mode: '0600'
|
mode: '0600'
|
||||||
with_items:
|
with_items:
|
||||||
- src: "{{ config.paths.definitions_path }}"
|
- src: "{{ config.paths.definitions_path }}"
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
- name: Build Templated Files
|
- name: Build Templated Files
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: "{{ item.src }}"
|
src: "{{ item.src }}"
|
||||||
dest: "{{ config.build_dir }}/{{ item.dest }}"
|
dest: "{{ build_dir }}/{{ item.dest }}"
|
||||||
mode: '0600'
|
mode: '0600'
|
||||||
with_items:
|
with_items:
|
||||||
- src: "{{ config.paths.report_path }}"
|
- src: "{{ config.paths.report_path }}"
|
||||||
|
|||||||
19
tasks/copy_if_not_exists.yml
Normal file
19
tasks/copy_if_not_exists.yml
Normal 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
|
||||||
103
tasks/setup.yml
103
tasks/setup.yml
@@ -1,90 +1,71 @@
|
|||||||
---
|
---
|
||||||
- name: Copy Report Template File
|
- name: Starting setup.
|
||||||
ansible.builtin.copy:
|
ansible.builtin.debug:
|
||||||
src: "{{ item.src }}"
|
msg: "Working Directory: {{ work_dir }}"
|
||||||
dest: "{{ config.work_dir }}/{{ item.dest }}"
|
tags:
|
||||||
mode: '0600'
|
- always
|
||||||
with_items:
|
|
||||||
- src: "templates/Report.md"
|
- name: Copy Report File if not exists.
|
||||||
dest: "Report.md"
|
ansible.builtin.include_tasks:
|
||||||
|
file: "copy_if_not_exists.yml"
|
||||||
|
vars:
|
||||||
|
source: "templates/Report.md"
|
||||||
|
destination: "{{ work_dir }}/Report.md"
|
||||||
tags:
|
tags:
|
||||||
- setup
|
- setup
|
||||||
- setup-all
|
- setup-all
|
||||||
- setup-all-with-vault
|
- setup-all-with-vault
|
||||||
- setup-with-vault
|
- setup-with-vault
|
||||||
|
|
||||||
- name: Copy Footer Template File
|
- name: "Copy footer if not exists."
|
||||||
ansible.builtin.copy:
|
ansible.builtin.include_tasks:
|
||||||
src: "{{ item.src }}"
|
file: "copy_if_not_exists.yml"
|
||||||
dest: "{{ config.work_dir }}/{{ item.dest }}"
|
vars:
|
||||||
mode: '0600'
|
source: "templates/footer.tex"
|
||||||
with_items:
|
destination: "{{ work_dir }}/footer.tex"
|
||||||
- src: "templates/footer.tex"
|
|
||||||
dest: "footer.tex"
|
|
||||||
tags:
|
tags:
|
||||||
- setup-footer
|
- setup-footer
|
||||||
- setup-all
|
- setup-all
|
||||||
- setup-all-with-vault
|
- setup-all-with-vault
|
||||||
|
|
||||||
- name: Copy Head File
|
- name: "Copy head if not exists."
|
||||||
ansible.builtin.copy:
|
ansible.builtin.include_tasks:
|
||||||
src: "{{ item.src }}"
|
file: "copy_if_not_exists.yml"
|
||||||
dest: "{{ config.work_dir }}/{{ item.dest }}"
|
vars:
|
||||||
mode: '0600'
|
source: "files/head.tex"
|
||||||
with_items:
|
destination: "{{ work_dir }}/head.tex"
|
||||||
- src: "files/head.tex"
|
|
||||||
dest: "head.tex"
|
|
||||||
tags:
|
tags:
|
||||||
- setup-head
|
- setup-head
|
||||||
- setup-all
|
- setup-all
|
||||||
- setup-all-with-vault
|
- setup-all-with-vault
|
||||||
|
|
||||||
- name: Copy Definitions File
|
- name: "Copy Definitions if not exists."
|
||||||
ansible.builtin.copy:
|
ansible.builtin.include_tasks:
|
||||||
src: "{{ item.src }}"
|
file: "copy_if_not_exists.yml"
|
||||||
dest: "{{ config.work_dir }}/{{ item.dest }}"
|
vars:
|
||||||
mode: '0600'
|
source: "files/Definitions.md"
|
||||||
with_items:
|
destination: "{{ work_dir }}/Definitions.md"
|
||||||
- src: "files/Definitions.md"
|
|
||||||
dest: "Definitions.md"
|
|
||||||
tags:
|
tags:
|
||||||
- setup-definitions
|
- setup-definitions
|
||||||
- setup-all
|
- setup-all
|
||||||
- setup-all-with-vault
|
- setup-all-with-vault
|
||||||
|
|
||||||
- name: Copy Vars File
|
- name: "Copy vars if not exists."
|
||||||
ansible.builtin.copy:
|
ansible.builtin.include_tasks:
|
||||||
src: "{{ item.src }}"
|
file: "copy_if_not_exists.yml"
|
||||||
dest: "{{ config.work_dir }}/{{ item.dest }}"
|
vars:
|
||||||
mode: '0600'
|
source: "defaults/main.yml"
|
||||||
with_items:
|
destination: "{{ work_dir }}/vars.yml"
|
||||||
- src: "files/vars.default.yml"
|
|
||||||
dest: "vars.yml"
|
|
||||||
tags:
|
tags:
|
||||||
- setup
|
- setup
|
||||||
- setup-all
|
- setup-all
|
||||||
|
|
||||||
- name: Copy Vars File
|
- name: "Copy vault if not exists."
|
||||||
ansible.builtin.copy:
|
ansible.builtin.include_tasks:
|
||||||
src: "{{ item.src }}"
|
file: "copy_if_not_exists.yml"
|
||||||
dest: "{{ config.work_dir }}/{{ item.dest }}"
|
vars:
|
||||||
mode: '0600'
|
source: "files/vault.default.yml"
|
||||||
with_items:
|
destination: "{{ work_dir }}/vault.yml"
|
||||||
- src: "files/vars.vault.yml"
|
|
||||||
dest: "vars.yml"
|
|
||||||
tags:
|
|
||||||
- setup-vault
|
|
||||||
- setup-with-vault
|
|
||||||
- setup-all-with-vault
|
|
||||||
|
|
||||||
- name: Copy Vault Vars File
|
|
||||||
ansible.builtin.copy:
|
|
||||||
src: "{{ item.src }}"
|
|
||||||
dest: "{{ config.work_dir }}/{{ item.dest }}"
|
|
||||||
mode: '0600'
|
|
||||||
with_items:
|
|
||||||
- src: "files/vault.default.yml"
|
|
||||||
dest: "vault.yml"
|
|
||||||
tags:
|
tags:
|
||||||
- setup-vault
|
- setup-vault
|
||||||
- setup-with-vault
|
- setup-with-vault
|
||||||
|
|||||||
@@ -31,12 +31,20 @@ home:
|
|||||||
cfm50: "3,000"
|
cfm50: "3,000"
|
||||||
lair: "1:1"
|
lair: "1:1"
|
||||||
|
|
||||||
config:
|
|
||||||
build_dir: "/tmp/hpa-role/.build"
|
|
||||||
work_dir: "/tmp/hpa-role"
|
|
||||||
|
|
||||||
|
# NOTE: These generally do not need changed, unless debugging.
|
||||||
|
#
|
||||||
|
build_dir_name: ".build"
|
||||||
|
work_dir: "{{ lookup('env', 'PWD') }}"
|
||||||
|
build_dir: "{{ work_dir }}/{{ build_dir_name }}"
|
||||||
|
|
||||||
|
# NOTE: These generally do not need changed, unless debugging.
|
||||||
|
config:
|
||||||
|
|
||||||
|
# NOTE: These generally do not need changed, unless debugging or customizing files.
|
||||||
|
# Such as you want to add new definitions or customize the latex footer.
|
||||||
paths:
|
paths:
|
||||||
report_path: "templates/Report.md"
|
report_path: "{{ work_dir }}/Report.md"
|
||||||
footer_path: "templates/footer.tex"
|
footer_path: "templates/footer.tex"
|
||||||
head_path: "files/head.tex"
|
head_path: "files/head.tex"
|
||||||
definitions_path: "files/Definitions.md"
|
definitions_path: "files/Definitions.md"
|
||||||
|
|||||||
Reference in New Issue
Block a user