refactor(vars): add system/hypervisor dict inputs
This commit is contained in:
@@ -10,15 +10,73 @@
|
||||
- name: Gather facts
|
||||
ansible.builtin.setup:
|
||||
|
||||
- name: Check if host is booted from the Arch install media
|
||||
- name: Check for live environment markers
|
||||
ansible.builtin.stat:
|
||||
path: /run/archiso
|
||||
register: environment_archiso_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
|
||||
}}
|
||||
changed_when: false
|
||||
|
||||
- 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'))
|
||||
}}
|
||||
changed_when: false
|
||||
|
||||
- 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_stat.stat.exists
|
||||
- not environment_archiso_present | bool
|
||||
ansible.builtin.fail:
|
||||
msg: This host is not booted from the Arch install media!
|
||||
|
||||
@@ -40,9 +98,9 @@
|
||||
- name: Set IP-Address
|
||||
when:
|
||||
- hypervisor == "vmware"
|
||||
- vm_ip is defined and vm_ip | length > 0
|
||||
- system_cfg.ip is defined and system_cfg.ip | string | length > 0
|
||||
ansible.builtin.command: >-
|
||||
ip addr replace {{ vm_ip }}/{{ vm_nms }}
|
||||
ip addr replace {{ system_cfg.ip }}/{{ system_cfg.prefix }}
|
||||
dev {{ environment_interface_name }}
|
||||
register: environment_ip_result
|
||||
changed_when: environment_ip_result.rc == 0
|
||||
@@ -50,9 +108,9 @@
|
||||
- name: Set Default Gateway
|
||||
when:
|
||||
- hypervisor == "vmware"
|
||||
- vm_gw is defined and vm_gw | length > 0
|
||||
- vm_ip is defined and vm_ip | length > 0
|
||||
ansible.builtin.command: "ip route replace default via {{ vm_gw }}"
|
||||
- system_cfg.gateway is defined and system_cfg.gateway | string | length > 0
|
||||
- system_cfg.ip is defined and system_cfg.ip | string | length > 0
|
||||
ansible.builtin.command: "ip route replace default via {{ system_cfg.gateway }}"
|
||||
register: environment_gateway_result
|
||||
changed_when: environment_gateway_result.rc == 0
|
||||
|
||||
@@ -105,23 +163,23 @@
|
||||
- name: Setup Pacman
|
||||
when:
|
||||
- not (custom_iso | bool)
|
||||
- "'os' not in item or os in item.os"
|
||||
- item.os is not defined or (os_resolved | default(os)) in item.os
|
||||
community.general.pacman:
|
||||
update_cache: true
|
||||
force: true
|
||||
name: "{{ item.name }}"
|
||||
state: latest
|
||||
loop:
|
||||
- {name: glibc}
|
||||
- {name: dnf, os: [almalinux, fedora, rhel8, rhel9, rhel10, rocky]}
|
||||
- {name: debootstrap, os: [debian11, debian12, debian13, ubuntu, ubuntu-lts]}
|
||||
- {name: debian-archive-keyring, os: [debian11, debian12, debian13]}
|
||||
- {name: ubuntu-keyring, os: [ubuntu, ubuntu-lts]}
|
||||
- { name: glibc }
|
||||
- { name: dnf, os: [almalinux8, almalinux9, almalinux10, fedora40, fedora41, fedora42, fedora43, rhel8, rhel9, rhel10, rocky8, rocky9, rocky10] }
|
||||
- { name: debootstrap, os: [debian10, debian11, debian12, debian13, debianunstable, ubuntu, ubuntu-lts] }
|
||||
- { name: debian-archive-keyring, os: [debian10, debian11, debian12, debian13, debianunstable] }
|
||||
- { name: ubuntu-keyring, os: [ubuntu, ubuntu-lts] }
|
||||
retries: 4
|
||||
delay: 15
|
||||
|
||||
- name: Prepare /iso mount and repository for RHEL-based systems
|
||||
when: os | lower in ["rhel8", "rhel9", "rhel10"]
|
||||
when: os == "rhel"
|
||||
block:
|
||||
- name: Create /iso directory
|
||||
ansible.builtin.file:
|
||||
@@ -129,9 +187,19 @@
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
- name: Select RHEL ISO device
|
||||
ansible.builtin.set_fact:
|
||||
environment_rhel_iso_device: >-
|
||||
{{
|
||||
'/dev/sr2'
|
||||
if hypervisor == 'libvirt'
|
||||
else '/dev/sr1'
|
||||
}}
|
||||
changed_when: false
|
||||
|
||||
- name: Mount RHEL ISO
|
||||
ansible.posix.mount:
|
||||
src: "{{ '/dev/sr1' if hypervisor == 'vmware' else '/dev/sr2' }}"
|
||||
src: "{{ environment_rhel_iso_device }}"
|
||||
path: /usr/local/install/redhat/dvd
|
||||
fstype: iso9660
|
||||
opts: "ro,loop"
|
||||
@@ -140,6 +208,16 @@
|
||||
- name: Configure RHEL Repos for installation
|
||||
when: is_rhel | bool
|
||||
block:
|
||||
- name: Select repository template
|
||||
ansible.builtin.set_fact:
|
||||
environment_repo_template: >-
|
||||
{{
|
||||
(os_resolved | default(os)) | lower
|
||||
if os == 'rhel'
|
||||
else os | lower
|
||||
}}
|
||||
changed_when: false
|
||||
|
||||
- name: Create directories for repository files and RPM GPG keys
|
||||
ansible.builtin.file:
|
||||
path: /etc/yum.repos.d
|
||||
@@ -148,8 +226,8 @@
|
||||
|
||||
- name: Create RHEL repository file
|
||||
ansible.builtin.template:
|
||||
src: "{{ os | lower }}.repo.j2"
|
||||
dest: /etc/yum.repos.d/{{ os | lower }}.repo
|
||||
src: "{{ environment_repo_template }}.repo.j2"
|
||||
dest: /etc/yum.repos.d/{{ environment_repo_template }}.repo
|
||||
mode: "0644"
|
||||
|
||||
- name: Check for third-party preparation tasks
|
||||
|
||||
Reference in New Issue
Block a user