nstoik / infrastructure

Infrasctructure for my home lab and StechSolutions
GNU General Public License v3.0
0 stars 0 forks source link

Infrastructure

Infrasctructure for my home lab and StechSolutions powered by Ansible.

Installation and Setup

Setup and installation instructions for a new development environment to modify the infrastructure or an environment to execute the playbooks.

Pipx installation

Install Pipx

Go through the steps to add it to the path and enable autocomplete.

Ansible installation

Install Ansible via Pipx

pipx install ansible-core
pipx inject ansible-core jmespath
pipx install ansible-lint
pipx inject ansible-lint jmespath
pipx install yamllint

Ansible configuration and setup

Install the required collections from Ansible Galaxy

ansible-galaxy install -r requirements.yaml

Ansible vault

There is a pre-commit hook to make sure an unencrypted vault is not committed.

On new development environments set up the pre-commit hook.

chmod +x git-init.sh
./git-init.sh

To encrypt a file, run ansible-vault encrypt <file>

To decrypt a file, run ansible-vault decrypt <file>

vault_pass.txt is the password for the vault. It is not checked into git. The actuall password is stored in Bitwarden.and can be read from there.

ansible.cfg has an entry for vault_password_file to point to this file.

Environment variables

There is an example environment file in the root directory called .env.example. Copy this file to .env and fill in the required values. The required values are stored in the ansible vault file vault/vault.yaml and can be copied from there.

The environment variables should be set in the shell before running any of the playbooks. The easiest way to do this is to use the helper script setenv.sh which will read the values from the .env file and set them in the shell.

The script needs to be execuatable.

chmod +x setenv.sh
source setenv.sh

Usage

The main configuration is done in the inventory/group_vars/all.yaml and the vault/vault.yaml (this file is encrypted) files.

Playbooks

The playbooks directory contains the different playbooks that can be run.

The playbooks are:

Roles

The roles directory contains roles that are used by the playbooks.

The roles are:

Services

The services directory contains the subfolders and playbooks for the various services I run on my infrastructure.

The services are:

Files

The files directory contains files that are used by certain roles or hosts.

Ansible Tags

The following ansible tags are available to specify specific tasks to run.

Inventory

Inventory files are as follows in the inventory directory:

Testing and linting

Linting can be done with the following commands

yamllint .
ansible-lint
ansible-playbook site.yaml --syntax-check