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.
|
||||
ansible.builtin.debug:
|
||||
msg: "Using {{ config.build_dir }}"
|
||||
msg: "Using {{ build_dir }}"
|
||||
tags:
|
||||
- debug
|
||||
|
||||
- name: Ensure build directory exists.
|
||||
ansible.builtin.file:
|
||||
path: "{{ config.build_dir }}"
|
||||
path: "{{ build_dir }}"
|
||||
state: "directory"
|
||||
mode: '0755'
|
||||
tags:
|
||||
@@ -16,7 +16,7 @@
|
||||
- name: Copy Build Files.
|
||||
ansible.builtin.copy:
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ config.build_dir }}/{{ item.dest }}"
|
||||
dest: "{{ build_dir }}/{{ item.dest }}"
|
||||
mode: '0600'
|
||||
with_items:
|
||||
- src: "{{ config.paths.definitions_path }}"
|
||||
@@ -29,7 +29,7 @@
|
||||
- name: Build Templated Files
|
||||
ansible.builtin.template:
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ config.build_dir }}/{{ item.dest }}"
|
||||
dest: "{{ build_dir }}/{{ item.dest }}"
|
||||
mode: '0600'
|
||||
with_items:
|
||||
- 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
|
||||
ansible.builtin.copy:
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ config.work_dir }}/{{ item.dest }}"
|
||||
mode: '0600'
|
||||
with_items:
|
||||
- src: "templates/Report.md"
|
||||
dest: "Report.md"
|
||||
- name: Starting setup.
|
||||
ansible.builtin.debug:
|
||||
msg: "Working Directory: {{ work_dir }}"
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Copy Report File if not exists.
|
||||
ansible.builtin.include_tasks:
|
||||
file: "copy_if_not_exists.yml"
|
||||
vars:
|
||||
source: "templates/Report.md"
|
||||
destination: "{{ work_dir }}/Report.md"
|
||||
tags:
|
||||
- setup
|
||||
- setup-all
|
||||
- setup-all-with-vault
|
||||
- setup-with-vault
|
||||
|
||||
- name: Copy Footer Template File
|
||||
ansible.builtin.copy:
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ config.work_dir }}/{{ item.dest }}"
|
||||
mode: '0600'
|
||||
with_items:
|
||||
- src: "templates/footer.tex"
|
||||
dest: "footer.tex"
|
||||
- name: "Copy footer if not exists."
|
||||
ansible.builtin.include_tasks:
|
||||
file: "copy_if_not_exists.yml"
|
||||
vars:
|
||||
source: "templates/footer.tex"
|
||||
destination: "{{ work_dir }}/footer.tex"
|
||||
tags:
|
||||
- setup-footer
|
||||
- setup-all
|
||||
- setup-all-with-vault
|
||||
|
||||
- name: Copy Head File
|
||||
ansible.builtin.copy:
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ config.work_dir }}/{{ item.dest }}"
|
||||
mode: '0600'
|
||||
with_items:
|
||||
- src: "files/head.tex"
|
||||
dest: "head.tex"
|
||||
- name: "Copy head if not exists."
|
||||
ansible.builtin.include_tasks:
|
||||
file: "copy_if_not_exists.yml"
|
||||
vars:
|
||||
source: "files/head.tex"
|
||||
destination: "{{ work_dir }}/head.tex"
|
||||
tags:
|
||||
- setup-head
|
||||
- setup-all
|
||||
- setup-all-with-vault
|
||||
|
||||
- name: Copy Definitions File
|
||||
ansible.builtin.copy:
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ config.work_dir }}/{{ item.dest }}"
|
||||
mode: '0600'
|
||||
with_items:
|
||||
- src: "files/Definitions.md"
|
||||
dest: "Definitions.md"
|
||||
- name: "Copy Definitions if not exists."
|
||||
ansible.builtin.include_tasks:
|
||||
file: "copy_if_not_exists.yml"
|
||||
vars:
|
||||
source: "files/Definitions.md"
|
||||
destination: "{{ work_dir }}/Definitions.md"
|
||||
tags:
|
||||
- setup-definitions
|
||||
- setup-all
|
||||
- setup-all-with-vault
|
||||
|
||||
- name: Copy Vars File
|
||||
ansible.builtin.copy:
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ config.work_dir }}/{{ item.dest }}"
|
||||
mode: '0600'
|
||||
with_items:
|
||||
- src: "files/vars.default.yml"
|
||||
dest: "vars.yml"
|
||||
- name: "Copy vars if not exists."
|
||||
ansible.builtin.include_tasks:
|
||||
file: "copy_if_not_exists.yml"
|
||||
vars:
|
||||
source: "defaults/main.yml"
|
||||
destination: "{{ work_dir }}/vars.yml"
|
||||
tags:
|
||||
- setup
|
||||
- setup-all
|
||||
|
||||
- name: Copy Vars File
|
||||
ansible.builtin.copy:
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ config.work_dir }}/{{ item.dest }}"
|
||||
mode: '0600'
|
||||
with_items:
|
||||
- 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"
|
||||
- name: "Copy vault if not exists."
|
||||
ansible.builtin.include_tasks:
|
||||
file: "copy_if_not_exists.yml"
|
||||
vars:
|
||||
source: "files/vault.default.yml"
|
||||
destination: "{{ work_dir }}/vault.yml"
|
||||
tags:
|
||||
- setup-vault
|
||||
- setup-with-vault
|
||||
|
||||
@@ -31,12 +31,20 @@ home:
|
||||
cfm50: "3,000"
|
||||
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:
|
||||
report_path: "templates/Report.md"
|
||||
report_path: "{{ work_dir }}/Report.md"
|
||||
footer_path: "templates/footer.tex"
|
||||
head_path: "files/head.tex"
|
||||
definitions_path: "files/Definitions.md"
|
||||
|
||||
Reference in New Issue
Block a user