diff --git a/.gitea/workflows/check-connectivity.yaml b/.gitea/workflows/check-connectivity.yaml new file mode 100644 index 0000000..96e4af9 --- /dev/null +++ b/.gitea/workflows/check-connectivity.yaml @@ -0,0 +1,18 @@ +name: Check Connectivity + +on: + workflow_dispatch: + +jobs: + check-connectivity: + name: Check Connectivity + runs-on: ansible + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Show Ansible Version + run: ansible-playbook --version + + - name: Run Connectivity Playbook + run: ansible-playbook playbooks/check-connectivity.yml diff --git a/CLAUDE.md b/CLAUDE.md index 3aeae1e..b92f1d5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -9,7 +9,7 @@ Ansible automation for a Proxmox homelab. It deploys Docker stacks and single sc ## Layout (planned) -`inventory/hosts.yml`, `group_vars/`, `roles/{docker_stack,script,lxc_base}`, `stacks//{docker-compose.yml,env.j2}`, `scripts/`, `playbooks/`, `.gitea/workflows/`. +`inventory/{hosts.yml,group_vars/}`, `roles/{docker_stack,script,lxc_base}`, `stacks//{docker-compose.yml,env.j2}`, `scripts/`, `playbooks/`, `.gitea/workflows/`. ## Deployment flow diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..e862c5d --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,9 @@ +[defaults] +inventory = inventory/hosts.yml +roles_path = roles +host_key_checking = True +interpreter_python = auto_silent +retry_files_enabled = False + +[ssh_connection] +pipelining = True diff --git a/inventory/group_vars/docker_hosts.yml b/inventory/group_vars/docker_hosts.yml new file mode 100644 index 0000000..390d932 --- /dev/null +++ b/inventory/group_vars/docker_hosts.yml @@ -0,0 +1,3 @@ +--- +# Compose derives each project name from its folder, so these paths must not change. +homelab_stacks_root: /home/pi/docker diff --git a/inventory/hosts.yml b/inventory/hosts.yml new file mode 100644 index 0000000..46bbaa4 --- /dev/null +++ b/inventory/hosts.yml @@ -0,0 +1,11 @@ +--- +# On the ansible LXC, ~/.ssh/config maps "docker" to its real address, user and key. +all: + children: + control: + hosts: + ansible: + ansible_connection: local + docker_hosts: + hosts: + docker: diff --git a/playbooks/check-connectivity.yml b/playbooks/check-connectivity.yml new file mode 100644 index 0000000..4cfd3d7 --- /dev/null +++ b/playbooks/check-connectivity.yml @@ -0,0 +1,35 @@ +--- +# Read-only: proves Ansible can reach each host. It changes nothing. +- name: Check that every host responds + hosts: all + gather_facts: false + tasks: + - name: Ping host + ansible.builtin.ping: + +- name: Check the Docker host + hosts: docker_hosts + gather_facts: false + tasks: + - name: Read Docker Compose version + ansible.builtin.command: docker compose version + register: check_connectivity_compose + changed_when: false + check_mode: false + + - name: Show Docker Compose version + ansible.builtin.debug: + msg: "{{ check_connectivity_compose.stdout }}" + + - name: Read stacks root + ansible.builtin.stat: + path: "{{ homelab_stacks_root }}" + register: check_connectivity_stacks_root + + - name: Require stacks root + ansible.builtin.assert: + that: + - check_connectivity_stacks_root.stat.isdir is defined + - check_connectivity_stacks_root.stat.isdir + fail_msg: "{{ homelab_stacks_root }} is missing or is not a directory" + quiet: true diff --git a/vault.example.yml b/vault.example.yml new file mode 100644 index 0000000..0e2d636 --- /dev/null +++ b/vault.example.yml @@ -0,0 +1,4 @@ +--- +# Template only. The real file is /etc/homelab-ansible/vault.yml on the ansible LXC, +# encrypted with ansible-vault and never committed. +vault_example_secret: CHANGE_ME