feat: Updates for using pre-defined ansible role

This commit is contained in:
2024-11-24 20:11:24 -05:00
parent 39b5293736
commit 1a12b5340e
14 changed files with 57 additions and 202 deletions

View File

@@ -1 +0,0 @@
.ansible/group_vars/all

View File

@@ -1,33 +0,0 @@
---
author_name: "Testy McTestface Jr"
document_title: "Home Performance Report"
company:
website: "https://example.com"
phone: "555-555-5555"
url_display_title: "www.Example.com"
links:
images:
logo: "img/logo.png"
trueflow: "img/trueflow.png"
trueflow_forecast: "img/forecast.png"
documents:
loads_folder: "https://example.com/path/to/loads/folder"
trueflow_file: "https://example.com/path/to/trueflow/file"
trueflow_forecast_file: "https://example.com/path/to/trueflow/forecast/file"
document_folder: "https://example.com/path/to/document/folder"
customer:
name: "Testy McTestface Sr"
address:
street: "1234 Seasme Street"
city: "No Mans Land"
state: "Foo"
zip: "55555"
home:
square_feet: "3,000"
cfm50: "3,000"
lair: "1:1"
build_dir: "build"

View File

@@ -1,19 +0,0 @@
---
author_name: "{{ vault_author_name }}"
document_title: "Home Performance Report"
company: "{{ vault_company }}"
links:
images:
logo: "img/logo.png"
trueflow: "img/trueflow.png"
trueflow_forecast: "img/forecast.png"
documents: "{{ vault_document_links }}"
customer: "{{ vault_customer }}"
home:
square_feet: "3,000"
cfm50: "3,000"
lair: "1:1"
build_dir: "build"

View File

@@ -1,35 +0,0 @@
$ANSIBLE_VAULT;1.1;AES256
37616334353636316232656136313764353534613834383266646665396364393233343464306632
3834666636616134356661626238323731616438366539630a616565613030376235306233356266
34323930656134363964666130613434313262313461373735656434333634333238343430353331
3732373966383635310a303665663732343561303239356634393162306666323836643765313638
38363130366534353164376333313435336362313438643166346236623537616438383437643965
36343833393237336239633433326535616562316561666539343362636564633262303337383631
62336331663032333039643033626634663636643762373539623262326462323762666435646362
37633538346530646362383464363732663164303937313635363833366639623662323263633431
39653434386263353834373239353236636538623632663061323431303937643761373364663835
34303030383536383833363639623661363531643734303265386532326439346463376436613033
66396536323865623832633663643936623531663734646630373966393562643439343631363365
34303833303935313334663831616435343130376536666631643231373333656363386566363865
62303062306565363535663261623361646464383166366233396233663838363136663461663630
39316234653834393739386564663866613765323333393932616133613231333664373839643364
34386335363065336632376135336132633331306435383861303261386564346136323562346432
33343132636239396231653832313431623539616434353163333637653738656436646135633666
36353266343932666538373137623162316566353437653066346338613732346662313433326261
32343164613165383065333738633338653763366534303930656361393031353736643233366631
65313931613833633037663631393861663134663239303033323135356130623062333634643331
39613761613332613231616437303835333961646235386232306235613664336533666663613834
62353237643461316563626538333936333261623039303663613230643962643139353734656630
33636136303732376432363862363534646631303566666331373435643532653931376263376665
38333037643730613637363832663838383231373765613531316664373334643232326365336531
35656433313461633939383661323464373933623963653438323366343661656138653135636235
63646135646561663863353236353939636531666166363866656230383931343937343834633263
61313338616263616636633232633464643530313763323064343838643036316135353366373933
64343235343435313664383630613639633233383766386265383264386133303063396339353731
33373631336265303561633663656433643837346438353131383565333062383238633264646532
31313931656533313031313032663035356438326365643262313734323661396465393138633564
62383166313334376639343265366136396230643236303635303638313833333836636330663262
63623434313838376366303763303961373733396163613365376236363233313438393637343064
32623233633963623830356331383462666438656132303938386437323332366634656236383664
38626539346339663533373062363531393263613636636237616263316537376438653339623435
6238656639353432653566353865386562643830333831656336

View File

@@ -1,6 +0,0 @@
---
- name: Generate Report.
hosts: all
roles:
- role: hpa_role

View File

@@ -1,54 +0,0 @@
PDF_TITLE ?= "Report.pdf"
TEX_TITLE ?= "Report.tex"
HTML_TITLE ?= "report.html"
BUILD_DIR ?= "${PWD}/build"
PDF_TEST_TITLE ?= "Report.test.pdf"
ANSIBLE_DIR = ".ansible"
.PHONY: pdf
pdf: ansible
@./scripts/gen.sh "${BUILD_DIR}" "${PWD}/${PDF_TITLE}" \
&& open "${PDF_TITLE}" \
&& osascript ./scripts/notify.scpt
.PHONY: tex
tex: ansible
@./scripts/gen.sh "${BUILD_DIR}" "${BUILD_DIR}/${TEX_TITLE}"
.PHONY: html
html: ansible
@./scripts/gen.sh "${BUILD_DIR}" "${BUILD_DIR}/${HTML_TITLE}" \
&& open "${BUILD_DIR}/${HTML_TITLE}"
.PHONY: ansible
ansible:
@cd "${ANSIBLE_DIR}" && \
ansible-playbook playbook.yaml \
--extra-vars "build_dir=${BUILD_DIR}"
.PHONY: ansible-vault-example
ansible-vault-example:
@cd "${ANSIBLE_DIR}" && \
ansible-playbook playbook.yaml \
--ask-vault-password \
--extra-vars "build_dir=${BUILD_DIR}" \
--extra-vars "@group_vars/vault_example/vars.yaml" \
--extra-vars "@group_vars/vault_example/vault.yaml"
.PHONY: setup
setup:
@ln -sfv "${ANSIBLE_DIR}/roles/report/templates/Report.md"
@ln -sfv "${ANSIBLE_DIR}/group_vars/all" ./vars
.PHONY: clean
clean:
@rm -rf "${BUILD_DIR}"
.PHONY: install
install:
@brew install pandoc \
mactex-no-gui \
imagemagick \
gettext \
ansible \
just

View File

@@ -1,5 +1,7 @@
build_dir_name := ".build"
ansible_dir := ".ansible"
ansible_dir := "playbook"
vars_file := "vars.yml"
vault_file := "vault.yml"
[private]
default:
@@ -17,25 +19,22 @@ run_pandoc dir output_file: build
[private]
run_ansible build *ARGS:
@echo "Running ansible with build directory: {{build}}"
@cd {{ansible_dir}} && \
ansible-playbook playbook.yaml \
--extra-vars '{"config": { "work_dir": {{justfile_directory()}}, "build_dir": {{build}} }}' \
cd {{ansible_dir}} && \
ansible-playbook playbook.yml \
--inventory inventory.ini \
--extra-vars "work_dir={{justfile_directory()}}" \
--extra-vars "build_dir={{build}}" \
{{ARGS}}
alias ansible := build
# Run the playbook, using the vault example files.
[group("build")]
ansible-vault-example: (
run_ansible build_dir_name
"--extra-vars @group_vars/vault_example/vars.yaml"
"--extra-vars @group_vars/vault_example/vault.yaml"
"--ask-vault-password"
)
# Run the playbook, which generates files required to build a report.
[group("build")]
build: (run_ansible justfile_directory()/build_dir_name)
build *ARGS: (
run_ansible justfile_directory()/build_dir_name
"--tags build"
ARGS
)
# Build & generate an HTML report.
[group("generate")]
@@ -56,7 +55,7 @@ pdf title="Report.pdf" output_dir="${PWD}": (run_pandoc output_dir file_stem(tit
tex title="Report.tex" output_dir=".build": (run_pandoc output_dir file_stem(title) + ".tex")
@echo "Wrote to: " + {{output_dir}}/{{file_stem(title)}} + ".tex"
# Setup the working directory
# Setup the working directory, setup tags see: `https://git.housh.dev/michael/ansible-role-hpa#setup-tags`
[group("setup")]
setup tag='setup': (
run_ansible justfile_directory()/build_dir_name "--tags " + tag
@@ -64,7 +63,19 @@ setup tag='setup': (
# Setup the working directory with ansible-vault.
[group("setup")]
setup-vault: (setup "setup-with-vault")
setup-vault: (setup "setup-with-vault")(encrypt-vault)
# Encrypt the vault file, pass in --ask-vault-pass if no default password file is set.
[group("setup")]
[group("utlities")]
encrypt-vault *ARGS:
@ansible-vault encrypt {{vault_file}} {{ARGS}}
# Edit the vault file, pass in --ask-vault-pass if no default password file is set.
[group("utlities")]
edit-vault *ARGS:
@ansible-vault edit {{vault_file}} {{ARGS}}
# Removes build directory, useful when debugging.
[group("utilities")]
@@ -79,9 +90,12 @@ clean-all: clean-build-dir
@rm -f ./Report.{md,pdf}
@rm -f vars.{yml,yaml}
@rm -f vault.{yml,yaml}
@rm -f Definitions.md
@rm -f {footer,head}.tex
@rm -f {{ansible_dir}}/group_vars/all/{vars,vault}.{yml,yaml}
# Install the required ansible roles.
[group("utilities")]
install-requirements:
@ansible-galaxy install -r ./.ansible/requirements.yaml
@ansible-galaxy install -r {{ansible_dir}}/requirements.yml

View File

25
playbook/playbook.yml Normal file
View File

@@ -0,0 +1,25 @@
---
- name: Generate Report.
hosts: all
roles:
- role: hpa_role
tasks:
- name: Link vars file.
ansible.builtin.file:
src: "{{ work_dir }}/vars.yml"
dest: "{{ work_dir }}/playbook/group_vars/all/vars.yml"
state: link
tags:
- setup
- setup-all
- setup-all-with-vault
- setup-with-vault
- name: Link vault file.
ansible.builtin.file:
src: "{{ work_dir }}/vault.yml"
dest: "{{ work_dir }}/playbook/group_vars/all/vault.yml"
state: link
tags:
- setup-all-with-vault
- setup-with-vault

View File

@@ -1,3 +1,3 @@
- name: hpa_role
src: git+https://git.housh.dev/michael/ansible-role-hpa
version: v0.1.0
version: main

View File

@@ -1,21 +0,0 @@
---
vault_author_name: "Testy McTestface Jr"
vault_company:
website: "https://example.com"
phone: "555-555-5555"
url_display_title: "www.Example.com"
vault_document_links:
loads_folder: "https://example.com/path/to/loads/folder"
trueflow_file: "https://example.com/path/to/trueflow/file"
trueflow_forecast_file: "https://example.com/path/to/trueflow/forecast/file"
document_folder: "https://example.com/path/to/document/folder"
vault_customer:
name: "Testy McTestface Sr"
address:
street: "1234 Seasme Street"
city: "No Mans Land"
state: "Foo"
zip: "55555"

View File

@@ -1,15 +0,0 @@
#!/bin/zsh
local build_dir=${1:-"${PWD}/build"}
local output_file=${2:-"${PWD}/Report.md"}
echo "Starting with build dir: ${build_dir}"
pandoc --pdf-engine=xelatex \
-H "${build_dir}/head.tex" \
-H "${build_dir}/footer.tex" \
-o "${output_file}" \
"${build_dir}/Report.md" \
"${build_dir}/Definitions.md"
echo "Wrote report to: ${output_file}"