Integrate Debian host readiness checks

This commit is contained in:
2026-10-01 08:59:03 +01:00
parent 3293472cad
commit 86e548f2fc
5 changed files with 123 additions and 5 deletions
+2 -2
View File
@@ -11,7 +11,7 @@ Required extra variables:
- `guestops_source_record`: controller path to the matching `.source.json`;
- `guestops_evidence_directory`: existing restricted controller directory for the fetched release record.
The target must already have Docker Engine with Compose, Python 3, and `/etc/guestops/guestops.env` owned by root with mode `0600`. The private environment file supplies MongoDB passwords, image references, provider-file paths and disabled-by-default feature flags. Provision it through Ansible Vault or the existing Futuresens secret process, never through this repository.
The target must already have Docker Engine with Compose, Nginx, Python 3, `ss`, a trusted certificate under `/etc/letsencrypt/live/sandbox-guestops.futuresens.co.uk`, and `/etc/guestops/guestops.env` owned by root with mode `0600`. The private environment file supplies MongoDB passwords, image references, provider-file paths and disabled-by-default feature flags. Provision it through Ansible Vault or the existing Futuresens secret process, never through this repository.
Example invocation from the central Ansible checkout:
@@ -26,6 +26,6 @@ ansible-playbook guestops.yml \
-e guestops_evidence_directory=/secure/evidence/guestops/0.2.1
```
The controller verifies the source package before transfer. The host independently checks the transferred archive checksum, extracts into a commit-specific directory, verifies the package again, selects the commit-tagged images and disabled send/FAQ defaults in the private environment, builds the API and worker images, records immutable image IDs, runs the offline preflight, validates Compose without printing expanded secrets, starts with `--no-build`, waits for readiness, and only then changes the `current` symlink. The source archive remains in the restricted controller store; the temporary host copy is removed after success.
The controller verifies the source package before transfer. The host independently checks the transferred archive checksum, extracts into a commit-specific directory, verifies the package again, selects the commit-tagged images and disabled send/FAQ defaults in the private environment, builds the API and worker images, records immutable image IDs, runs the offline preflight, validates Compose without printing expanded secrets, starts with `--no-build`, and waits for loopback readiness. It then enables Docker and Nginx at boot, validates and installs the reviewed proxy site, rejects public API or MongoDB listeners, and checks the public redirect and certificate-backed HTTPS readiness before changing the `current` symlink. The source archive remains in the restricted controller store; the temporary host copy is removed after success.
This playbook does not provision DNS, TLS, Nginx, firewall rules, backup keys, monitoring, or the private environment. Those remain explicit Milestone 10 and 11 acceptance activities.
+110
View File
@@ -7,6 +7,8 @@
vars:
guestops_root: /opt/guestops
guestops_config_root: /etc/guestops
guestops_public_hostname: sandbox-guestops.futuresens.co.uk
guestops_public_origin: "https://{{ guestops_public_hostname }}"
guestops_release_root: "{{ guestops_root }}/releases/{{ guestops_release_commit }}"
guestops_staging_archive: "/var/tmp/{{ guestops_archive | basename }}"
guestops_staging_record: "/var/tmp/{{ guestops_source_record | basename }}"
@@ -23,6 +25,8 @@
- guestops_archive | length > 0
- guestops_source_record | length > 0
- guestops_evidence_directory | length > 0
- guestops_public_hostname is match('^[A-Za-z0-9.-]+$')
- guestops_public_hostname == 'sandbox-guestops.futuresens.co.uk'
fail_msg: Release version, full commit, archive, SHA-256, source record and evidence directory are required.
- name: Verify source package on the Ansible controller
@@ -56,6 +60,28 @@
fail_msg: /etc/guestops/guestops.env must already exist with mode 0600.
tasks:
- name: Require supported Debian host
ansible.builtin.assert:
that:
- ansible_facts.system == 'Linux'
- ansible_facts.distribution == 'Debian'
- ansible_facts.distribution_major_version | int >= 12
- ansible_facts.processor_vcpus | default(0) | int >= 4
- ansible_facts.memtotal_mb | default(0) | int >= 7300
fail_msg: GuestOps requires Debian 12 or newer with at least 4 CPUs and 7.3 GiB RAM.
- name: Enable Docker at boot
ansible.builtin.service:
name: docker
enabled: true
state: started
- name: Enable Nginx at boot
ansible.builtin.service:
name: nginx
enabled: true
state: started
- name: Create release and evidence directories
ansible.builtin.file:
path: "{{ item.path }}"
@@ -264,6 +290,90 @@
delay: 2
until: guestops_readiness.status == 200
- name: Confirm TLS certificate files exist
ansible.builtin.stat:
path: "{{ item }}"
follow: true
loop:
- "/etc/letsencrypt/live/{{ guestops_public_hostname }}/fullchain.pem"
- "/etc/letsencrypt/live/{{ guestops_public_hostname }}/privkey.pem"
register: guestops_certificates
- name: Require the pre-provisioned TLS certificate
ansible.builtin.assert:
that:
- guestops_certificates.results | map(attribute='stat.exists') | min
- guestops_certificates.results | map(attribute='stat.isreg') | min
fail_msg: A valid pre-provisioned Let's Encrypt certificate is required before enabling Nginx.
- name: Install reviewed GuestOps Nginx site
ansible.builtin.copy:
src: "{{ playbook_dir }}/../nginx.conf"
dest: /etc/nginx/sites-available/guestops.conf
owner: root
group: root
mode: "0644"
register: guestops_nginx_site
- name: Enable GuestOps Nginx site
ansible.builtin.file:
src: /etc/nginx/sites-available/guestops.conf
dest: /etc/nginx/sites-enabled/guestops.conf
state: link
register: guestops_nginx_enabled
- name: Validate Nginx configuration
ansible.builtin.command:
argv: [nginx, -t]
changed_when: false
- name: Reload Nginx after reviewed configuration change
ansible.builtin.service:
name: nginx
enabled: true
state: reloaded
when: guestops_nginx_site.changed or guestops_nginx_enabled.changed
- name: Inspect host TCP listeners
ansible.builtin.command:
argv: [ss, -ltnH]
register: guestops_tcp_listeners
changed_when: false
- name: Reject public API or MongoDB listeners
ansible.builtin.assert:
that:
- guestops_tcp_listeners.stdout_lines | select('search', ':8080(\\s|$)') | reject('search', '127\\.0\\.0\\.1:8080(\\s|$)') | list | length == 0
- guestops_tcp_listeners.stdout_lines | select('search', ':27017(\\s|$)') | list | length == 0
fail_msg: API port 8080 must be loopback-only and MongoDB must have no host listener.
- name: Verify public HTTP redirects to HTTPS
ansible.builtin.uri:
url: "http://{{ guestops_public_hostname }}/health/ready"
method: GET
follow_redirects: none
status_code: [301, 302, 307, 308]
return_content: false
delegate_to: localhost
become: false
- name: Verify public HTTPS readiness and certificate trust
ansible.builtin.uri:
url: "{{ guestops_public_origin }}/health/ready"
method: GET
status_code: 200
return_content: true
validate_certs: true
register: guestops_public_readiness
retries: 10
delay: 3
until:
- guestops_public_readiness.status == 200
- guestops_public_readiness.json is defined
- guestops_public_readiness.json.status == 'ready'
delegate_to: localhost
become: false
- name: Select the current successful release
ansible.builtin.file:
src: "{{ guestops_release_root }}"