From f9013dab960210f425ce489afe44969685e8f63f Mon Sep 17 00:00:00 2001 From: Corbin Date: Wed, 22 Jan 2025 18:53:32 -0500 Subject: [PATCH] Initial commit --- .gitignore | 1 + README.md | 3 +++ ansible.cfg | 4 ++++ files/pre-commit | 16 ++++++++++++++++ group_vars/all.yaml | 1 + host_vars/host.yaml | 1 + inventory.yaml | 1 + playbooks/localhost_setup.yaml | 17 +++++++++++++++++ roles/requirements.yaml | 1 + vars/vault.yaml | 1 + 10 files changed, 46 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 ansible.cfg create mode 100644 files/pre-commit create mode 100644 group_vars/all.yaml create mode 100644 host_vars/host.yaml create mode 100644 inventory.yaml create mode 100644 playbooks/localhost_setup.yaml create mode 100644 roles/requirements.yaml create mode 100644 vars/vault.yaml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f17288a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vault-password diff --git a/README.md b/README.md new file mode 100644 index 0000000..7ab5778 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# template-ansible-project + +This is a template repository for creating new Ansible projects. diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..7579897 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,4 @@ +[defaults] +retry_files_enabled = False +inventory = ./inventory.yaml +vault_password_file = ./.vault-password diff --git a/files/pre-commit b/files/pre-commit new file mode 100644 index 0000000..91953f4 --- /dev/null +++ b/files/pre-commit @@ -0,0 +1,16 @@ +# Pre-commit hook to ensure vault.yaml is encrypted +# +# Credit goes to Nick Busey from HomelabOS for this neat little trick +# https://gitlab.com/NickBusey/HomelabOS/-/issues/355 + +if ( git show :vars/vault.yaml | grep -q "$ANSIBLE_VAULT;" ); then +echo "\e[38;5;108mVault Encrypted. Safe to commit.\e[0m" +else +echo "\e[38;5;208mVault not encrypted! Run 'make encrypt' and try again.\e[0m" +exit 1 +fi + +command -v yamllint > /dev/null && echo "Running yamllint..." && yamllint . || exit 1 +command -v ansible-lint > /dev/null && echo "Running ansible-lint..." ansible-lint + +# vi: ft=sh diff --git a/group_vars/all.yaml b/group_vars/all.yaml new file mode 100644 index 0000000..e9fa5c1 --- /dev/null +++ b/group_vars/all.yaml @@ -0,0 +1 @@ +---\n diff --git a/host_vars/host.yaml b/host_vars/host.yaml new file mode 100644 index 0000000..e9fa5c1 --- /dev/null +++ b/host_vars/host.yaml @@ -0,0 +1 @@ +---\n diff --git a/inventory.yaml b/inventory.yaml new file mode 100644 index 0000000..e9fa5c1 --- /dev/null +++ b/inventory.yaml @@ -0,0 +1 @@ +---\n diff --git a/playbooks/localhost_setup.yaml b/playbooks/localhost_setup.yaml new file mode 100644 index 0000000..5bb5c83 --- /dev/null +++ b/playbooks/localhost_setup.yaml @@ -0,0 +1,17 @@ +--- +- name: Localhost setup + hosts: 127.0.0.1 + tasks: + - name: Install packages + ansible.builtin.package: + name: "{{ item }}" + state: present + with_items: + - yamllint + - ansible-lint + + - name: Set up git pre-commit hooks + ansible.builtin.copy: + src: ../files/pre-commit + dest: ../.git/hooks/pre-commit + mode: 0755 diff --git a/roles/requirements.yaml b/roles/requirements.yaml new file mode 100644 index 0000000..e9fa5c1 --- /dev/null +++ b/roles/requirements.yaml @@ -0,0 +1 @@ +---\n diff --git a/vars/vault.yaml b/vars/vault.yaml new file mode 100644 index 0000000..e9fa5c1 --- /dev/null +++ b/vars/vault.yaml @@ -0,0 +1 @@ +---\n