refactor(environment): split main.yml into focused sub-task files
This commit is contained in:
76
roles/environment/tasks/_detect_live.yml
Normal file
76
roles/environment/tasks/_detect_live.yml
Normal file
@@ -0,0 +1,76 @@
|
||||
---
|
||||
- name: Wait for connection
|
||||
ansible.builtin.wait_for_connection:
|
||||
timeout: 180
|
||||
delay: 5
|
||||
|
||||
- name: Gather facts
|
||||
ansible.builtin.setup:
|
||||
|
||||
- name: Check for live environment markers
|
||||
ansible.builtin.stat:
|
||||
path: "{{ item }}"
|
||||
loop:
|
||||
- /run/archiso
|
||||
- /run/live
|
||||
- /run/initramfs
|
||||
- /run/initramfs/live
|
||||
register: environment_live_marker_stat
|
||||
changed_when: false
|
||||
|
||||
- name: Determine root filesystem type
|
||||
ansible.builtin.set_fact:
|
||||
environment_root_fstype: >-
|
||||
{{
|
||||
ansible_mounts
|
||||
| selectattr('mount', 'equalto', '/')
|
||||
| map(attribute='fstype')
|
||||
| list
|
||||
| first
|
||||
| default('')
|
||||
| lower
|
||||
}}
|
||||
environment_archiso_present: >-
|
||||
{{
|
||||
(
|
||||
environment_live_marker_stat.results
|
||||
| selectattr('item', 'equalto', '/run/archiso')
|
||||
| selectattr('stat.exists')
|
||||
| list
|
||||
| length
|
||||
) > 0
|
||||
}}
|
||||
|
||||
- name: Identify live environment indicators
|
||||
ansible.builtin.set_fact:
|
||||
environment_is_live_environment: >-
|
||||
{{
|
||||
(
|
||||
environment_live_marker_stat.results
|
||||
| selectattr('stat.exists')
|
||||
| list
|
||||
| length
|
||||
) > 0
|
||||
or environment_root_fstype in ['overlay', 'overlayfs', 'squashfs', 'aufs']
|
||||
or (ansible_hostname | default('') | lower is search('live'))
|
||||
}}
|
||||
|
||||
- name: Abort if target is not a live environment
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- environment_is_live_environment | bool
|
||||
fail_msg: |
|
||||
PRODUCTION SYSTEM DETECTED - ABORTING
|
||||
|
||||
The target system does not appear to be a live installer environment.
|
||||
This playbook must run from a live ISO to avoid wiping production data.
|
||||
|
||||
Boot from a live installer (Arch, Debian, Ubuntu, etc.) and retry.
|
||||
quiet: true
|
||||
|
||||
- name: Abort if the host is not booted from the Arch install media
|
||||
when:
|
||||
- not (custom_iso | bool)
|
||||
- not environment_archiso_present | bool
|
||||
ansible.builtin.fail:
|
||||
msg: This host is not booted from the Arch install media!
|
||||
Reference in New Issue
Block a user