2026-02-03 20:17:24 -08:00
|
|
|
---
|
2026-02-07 21:44:57 -08:00
|
|
|
title: Add Ansible Role
|
2026-02-13 16:54:42 -08:00
|
|
|
modified: 2026-02-13
|
|
|
|
|
last-reviewed: 2026-02-13
|
2026-02-03 20:17:24 -08:00
|
|
|
tags:
|
|
|
|
|
- how-to
|
|
|
|
|
- ansible
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# Add an Ansible Role
|
|
|
|
|
|
|
|
|
|
Quick reference for adding a new Ansible role to provision services on [[indri]].
|
|
|
|
|
|
|
|
|
|
## Create Role Structure
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
ansible/roles/<role>/
|
|
|
|
|
├── defaults/main.yml # Default variables
|
|
|
|
|
├── tasks/main.yml # Task definitions
|
|
|
|
|
├── handlers/main.yml # Handlers (restarts, etc.)
|
|
|
|
|
├── templates/ # Jinja2 templates
|
|
|
|
|
└── files/ # Static files (optional)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Minimal Role Example
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
# ansible/roles/<role>/defaults/main.yml
|
|
|
|
|
---
|
|
|
|
|
role_data_dir: ~/Library/Application Support/<service>
|
|
|
|
|
role_port: 8080
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
# ansible/roles/<role>/tasks/main.yml
|
|
|
|
|
---
|
|
|
|
|
- name: Ensure data directory exists
|
|
|
|
|
ansible.builtin.file:
|
|
|
|
|
path: "{{ role_data_dir }}"
|
|
|
|
|
state: directory
|
|
|
|
|
mode: '0755'
|
|
|
|
|
|
|
|
|
|
- name: Deploy configuration
|
|
|
|
|
ansible.builtin.template:
|
|
|
|
|
src: config.j2
|
|
|
|
|
dest: "{{ role_data_dir }}/config"
|
|
|
|
|
mode: '0644'
|
2026-02-13 16:54:42 -08:00
|
|
|
notify: Restart <service>
|
2026-02-03 20:17:24 -08:00
|
|
|
|
|
|
|
|
- name: Deploy LaunchAgent plist
|
|
|
|
|
ansible.builtin.template:
|
|
|
|
|
src: launchagent.plist.j2
|
|
|
|
|
dest: ~/Library/LaunchAgents/mcquack.<service>.plist
|
|
|
|
|
mode: '0644'
|
2026-02-13 16:54:42 -08:00
|
|
|
notify: Restart <service>
|
2026-02-03 20:17:24 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
# ansible/roles/<role>/handlers/main.yml
|
|
|
|
|
---
|
2026-02-13 16:54:42 -08:00
|
|
|
- name: Restart <service>
|
2026-02-03 20:17:24 -08:00
|
|
|
ansible.builtin.shell: |
|
|
|
|
|
launchctl unload ~/Library/LaunchAgents/mcquack.<service>.plist 2>/dev/null || true
|
|
|
|
|
launchctl load ~/Library/LaunchAgents/mcquack.<service>.plist
|
2026-02-13 16:54:42 -08:00
|
|
|
changed_when: true
|
2026-02-03 20:17:24 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Add Role to Playbook
|
|
|
|
|
|
|
|
|
|
Edit `ansible/playbooks/indri.yml`:
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
roles:
|
|
|
|
|
# ... existing roles ...
|
|
|
|
|
- role: <role>
|
2026-02-13 16:54:42 -08:00
|
|
|
tags: <role>
|
2026-02-03 20:17:24 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Add Secrets (if needed)
|
|
|
|
|
|
|
|
|
|
If the role needs secrets from 1Password, add pre_tasks:
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
pre_tasks:
|
|
|
|
|
# ... existing pre_tasks ...
|
|
|
|
|
- name: Fetch <role> secret
|
|
|
|
|
ansible.builtin.command:
|
2026-02-13 16:54:42 -08:00
|
|
|
cmd: op read "op://vg6xf6vvfmoh5hqjjhlhbeoaie/<item-id>/<field>"
|
2026-02-03 20:17:24 -08:00
|
|
|
delegate_to: localhost
|
|
|
|
|
register: _role_secret
|
|
|
|
|
changed_when: false
|
|
|
|
|
no_log: true
|
|
|
|
|
check_mode: false
|
2026-02-13 16:54:42 -08:00
|
|
|
tags: <role>
|
2026-02-03 20:17:24 -08:00
|
|
|
|
|
|
|
|
- name: Set <role> secret fact
|
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
|
role_secret_var: "{{ _role_secret.stdout }}"
|
|
|
|
|
no_log: true
|
2026-02-13 16:54:42 -08:00
|
|
|
tags: <role>
|
2026-02-03 20:17:24 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Then use `role_secret_var` in your role with a guard:
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
# In role's tasks, fetch if not already set (allows running with --tags)
|
|
|
|
|
- name: Fetch secret if not set
|
|
|
|
|
ansible.builtin.command:
|
2026-02-13 16:54:42 -08:00
|
|
|
cmd: op read "op://vg6xf6vvfmoh5hqjjhlhbeoaie/<item-id>/<field>"
|
2026-02-03 20:17:24 -08:00
|
|
|
delegate_to: localhost
|
|
|
|
|
register: _role_secret
|
|
|
|
|
changed_when: false
|
|
|
|
|
no_log: true
|
|
|
|
|
check_mode: false
|
|
|
|
|
when: role_secret_var is not defined
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Test and Deploy
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# Dry run
|
|
|
|
|
mise run provision-indri -- --tags <role> --check --diff
|
|
|
|
|
|
|
|
|
|
# Apply
|
|
|
|
|
mise run provision-indri -- --tags <role>
|
|
|
|
|
|
|
|
|
|
# Verify
|
|
|
|
|
ssh indri 'launchctl list | grep <service>'
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Add Observability (optional)
|
|
|
|
|
|
|
|
|
|
For metrics collection, create a companion `<role>_metrics` role that:
|
|
|
|
|
1. Writes metrics to `/opt/homebrew/var/node_exporter/textfile/`
|
|
|
|
|
2. Runs via a LaunchAgent (cronjob-style)
|
|
|
|
|
|
|
|
|
|
See [[alloy]] for how metrics are collected from textfiles.
|
|
|
|
|
|
2026-02-16 17:02:56 -08:00
|
|
|
## Checklist
|
|
|
|
|
|
|
|
|
|
- [ ] Role created in `ansible/roles/<role>/`
|
|
|
|
|
- [ ] Role added to `ansible/playbooks/indri.yml` with tag
|
|
|
|
|
- [ ] Secrets wired via pre_tasks (if needed)
|
|
|
|
|
- [ ] Dry run passes: `mise run provision-indri -- --tags <role> --check --diff`
|
|
|
|
|
- [ ] Service added to `service-versions.yaml` for version tracking
|
|
|
|
|
|
2026-02-03 20:17:24 -08:00
|
|
|
## Related
|
|
|
|
|
|
Add reference/tools/ category with Dagger, ArgoCD CLI, Ansible, and Pulumi cards (#178)
## Summary
- Create `docs/reference/tools/` with four reference cards: Dagger (build engine), ArgoCD CLI (deployment workflows), Ansible (config management), and Pulumi (DNS/Tailscale IaC)
- Move `ansible/roles.md` → `tools/ansible.md`, broadened with CLI patterns and dry-run usage
- Update `reference.md` index: add "Tools" section, remove old "Ansible" section
- Update `update-documentation.md` to reflect Dagger build process (workflow steps, manual build recipe, runner environment)
- Update `adopt-dagger-ci.md` plan to note how-to articles were handled via reference card + existing how-to updates
- Fix all broken `[[roles]]` wiki-links across 5 files → `[[ansible]]`
## Verification
- `docs-check-links` ✓ — no broken wiki-links
- `docs-check-index` ✓ — all docs referenced in category index
- `docs-check-filenames` ✓ — no duplicate filenames
- All pre-commit hooks pass
Reviewed-on: https://forge.ops.eblu.me/eblume/blumeops/pulls/178
2026-02-12 19:18:46 -08:00
|
|
|
- [[ansible]] - Available roles reference
|
2026-02-03 20:17:24 -08:00
|
|
|
- [[indri]] - Target host
|
|
|
|
|
- [[observability]] - Metrics collection
|
2026-02-16 17:02:56 -08:00
|
|
|
- [[review-services]] - Periodic service version review
|