Ansible Build¶
The Mint System collection of Ansible playbooks and roles.
Requirements¶
- Setup uv
- bash/zsh alias
task='./task'with optional completion
Usage¶
Clone this repository.
See task help for details about the project commands.
Setup¶
Navigate into the project folder.
Generate an Ansible vault id and password.
Create an Ansible configuration from the template.
Install Ansible and Python dependencies.
Create an inventory folder and configure a role.
Ansbile Documentation > Build Your Inventory
Roles¶
All Ansible roles are separted into
- system: OS runtime (docker, network, internet-related)
- environment: OS config (motd, packages, timezone, locale, etc.)
- service: Middleware/supporting services
- application: End-user applications
See roles for details or list the roles with:
Targets¶
All Ansible roles can be deployed to a Linux Server via SSH.
flowchart TD
A[Host] -->|SSH| B[Server]
Ansible Vault¶
If you encrypt secrets with multiple vault identities, you can specificy the vault list in the ansible.cfg like this:
Or as an environment variable:
export ANSIBLE_VAULT_IDENTITY_LIST="mint_system@.vault_pass_mint_system, example@.vault_pass_example"
Alternatively you can configure the --vault-id parameter of the Ansible playbook command:
You can generate a secret with this command:
Deploy¶
Deploy the roles to the target hosts with the following commands.
List hosts in inventory.
Load virtualenv.
Test connection.
Deploy multiple inventories.
Deploy Odoo stack.
Deploy role only.
Deploy without dependencies.
Deploy role to specific host.
Deploy role to specific group with non-default user.
Cleanup Odoo stack.
task play -i inventories/mint_system plays/cleanup.yml -t odoo,odoo_volume,odoo_data,postgres,postgres_volume
Cleanup role only.
Cleanup dry run.
List all Odoo databases.
Development¶
This section is about developing the Ansible Build project.
New role¶
The easiest way to create a new role is to copy the postgres role. Then search and replace the variable prefix within the role folder and remove unecessary files.
cp -r postgres pgbouncer
cd pgbouncer
rm -r templates files
find . -type f -exec sed -i 's/postgres/pgbouncer/g' {} \;
mv tasks/postgres.yml tasks/pgbouncer.yml
Edit the role files manually and add the roles to the playbooks.
Quality assurance¶
Lint the project using Ansible lint.
Mapping environment variables¶
Whenever possible use env variables to configure the container.
Env Config
env:
POSTGRES_USER: "{{ postgres_user }}"
POSTGRES_PASSWORD: "{{ postgres_password }}"
POSTGRES_DB: "{{ postgres_db }}"
Data persistence¶
To persist data use Docker volumes.
Volume Mount
Mount the folder without subfolder.
For Ansible config files use file mounts.
Bind Mount
Role documentation¶
Every role folder must contain a README.md file.
Mark fix-me-comments with #FIXME: <your text>.
Naming conventions¶
Role names must be lower case and may contain an _.
Vars that are stored in vaults are prefixed with vault_.
Template for role vars:
# Url to Docker repsitory
rolename_image:
rolename_hostname:
rolename_port:
rolename_volume_name: "{{ rolename_hostname }}"
rolename_data_dir: "/usr/share/{{ rolename_hostname }}"
rolename_password: "{{ vault_rolename_password }}"
The reference roles are postgres and odoo.
Roles and tags¶
Roles can have multiple tags.
Example one tag
To define a Postgres role, you would:
- Create role
postges - Assign the tag
postgres - Create a task file
postgres.yml
Example multiple tags
To define a Nginx role with a config tag, you would:
- Create role
nginx - Assign the tags
nginxandnginx_config - Create the task files
nginx.ymlandnginx_config.yml
In the main.yml you would include the tasks as followed:
- name: "Include {{ role_name }} config tasks"
include_tasks: "{{ role_name }}-config.yml"
when: nginx_data_dir is defined
tags:
- nginx
- nginx_config
- name: "Include {{ role_name }} tasks"
include_tasks: "{{ role_name }}.yml"
when: nginx_image is defined
tags:
- nginx
Host aliases¶
Whenever a role is applied to the same host multiple times, you can create multiple aliases for the same host. Append a selected suffix to make a distinction between the aliases:
- main: Production environment.
- staging: Staging environment.
- dev: Development and test environment.
- upgrade: Upgrade environment.
Here is an example of an host with two aliases: