78 lines
2.5 KiB
YAML
78 lines
2.5 KiB
YAML
---
|
|
- name: Execute protected production recovery transaction
|
|
hosts: production
|
|
gather_facts: false
|
|
any_errors_fatal: true
|
|
serial: 1
|
|
|
|
vars:
|
|
v1_release: "{{ lookup('ansible.builtin.file', playbook_dir + '/../recovery/releases/v1.yml') | from_yaml }}"
|
|
v2_release: "{{ lookup('ansible.builtin.file', playbook_dir + '/../recovery/releases/v2.yml') | from_yaml }}"
|
|
|
|
tasks:
|
|
- name: Require explicit recovery authorization
|
|
ansible.builtin.assert:
|
|
that:
|
|
- recovery_authorized | default(false) | bool
|
|
- not ansible_check_mode
|
|
- configuration_commit is defined
|
|
- configuration_commit is match('^[a-f0-9]{40}$')
|
|
|
|
- name: Generate unique recovery workspace
|
|
ansible.builtin.tempfile:
|
|
state: directory
|
|
path: /opt/secure-delivery
|
|
prefix: recovery-transaction-
|
|
register: workspace
|
|
|
|
- name: Protect recovery workspace
|
|
ansible.builtin.file:
|
|
path: "{{ workspace.path }}"
|
|
owner: root
|
|
group: root
|
|
mode: '0700'
|
|
|
|
- name: Install transaction script
|
|
ansible.builtin.copy:
|
|
src: ../recovery/production-transaction.py
|
|
dest: "{{ workspace.path }}/production-transaction.py"
|
|
owner: root
|
|
group: root
|
|
mode: '0700'
|
|
|
|
- name: Install immutable recovery configuration
|
|
ansible.builtin.copy:
|
|
content: "{{ {'v1': v1_release, 'v2': v2_release, 'configuration_commit': configuration_commit} | to_nice_json }}"
|
|
dest: "{{ workspace.path }}/releases.json"
|
|
owner: root
|
|
group: root
|
|
mode: '0600'
|
|
|
|
- name: Set unique systemd unit name
|
|
ansible.builtin.set_fact:
|
|
recovery_unit: "{{ workspace.path | basename }}"
|
|
|
|
- name: Report recovery execution identifiers
|
|
ansible.builtin.debug:
|
|
msg:
|
|
- "Workspace: {{ workspace.path }}"
|
|
- "Systemd unit: {{ recovery_unit }}"
|
|
- "Configuration commit: {{ configuration_commit }}"
|
|
|
|
- name: Start detached recovery transaction
|
|
ansible.builtin.command:
|
|
argv:
|
|
- /usr/bin/systemd-run
|
|
- "--unit={{ recovery_unit }}"
|
|
- --property=RemainAfterExit=yes
|
|
- --property=StandardOutput=journal
|
|
- --property=StandardError=journal
|
|
- /usr/bin/python3
|
|
- "{{ workspace.path }}/production-transaction.py"
|
|
- "{{ workspace.path }}/releases.json"
|
|
- AUTHORIZED
|
|
|
|
- name: Report journal retrieval command
|
|
ansible.builtin.debug:
|
|
msg: "journalctl -u {{ recovery_unit }} --no-pager -o short-iso-precise"
|