2024-07-11 22:20:45 +02:00
|
|
|
---
|
2024-03-19 23:02:50 +01:00
|
|
|
- name: Configre work environment
|
|
|
|
become: true
|
|
|
|
block:
|
|
|
|
- name: Wait for connection
|
2024-07-11 22:20:45 +02:00
|
|
|
ansible.builtin.wait_for_connection:
|
2024-10-30 16:48:23 +01:00
|
|
|
timeout: 30
|
2024-03-19 23:02:50 +01:00
|
|
|
delay: 5
|
|
|
|
|
|
|
|
- name: Gather facts
|
2024-07-11 22:20:45 +02:00
|
|
|
ansible.builtin.setup:
|
2024-03-19 23:02:50 +01:00
|
|
|
|
|
|
|
- name: Check if host is booted from the Arch install media
|
2024-07-11 22:20:45 +02:00
|
|
|
ansible.builtin.stat:
|
2024-03-19 23:02:50 +01:00
|
|
|
path: /run/archiso
|
|
|
|
register: archiso_stat
|
|
|
|
|
|
|
|
- name: Abort if the host is not booted from the Arch install media
|
2024-07-11 22:20:45 +02:00
|
|
|
ansible.builtin.fail:
|
|
|
|
msg: This host is not booted from the Arch install media!
|
2024-03-19 23:02:50 +01:00
|
|
|
when: not archiso_stat.stat.exists
|
|
|
|
|
|
|
|
- name: Setect Interface
|
|
|
|
when: hypervisor == "vmware"
|
2024-10-28 18:47:31 +01:00
|
|
|
ansible.builtin.shell: "set -o pipefail && ip l | awk -F': ' '!/lo/{print $2; exit}'"
|
2024-10-28 19:20:05 +01:00
|
|
|
changed_when: interface_name.rc == 0
|
2024-03-19 23:02:50 +01:00
|
|
|
register: interface_name
|
|
|
|
|
|
|
|
- name: Set IP-Address
|
|
|
|
when: hypervisor == "vmware"
|
2024-10-30 18:04:46 +01:00
|
|
|
ansible.builtin.command: "ip addr replace {{ ansible_host }}/{{ vm_nms | default(24) }} dev {{ interface_name.stdout }}"
|
2024-10-28 19:20:05 +01:00
|
|
|
changed_when: result.rc == 0
|
|
|
|
register: result
|
|
|
|
|
2024-03-19 23:02:50 +01:00
|
|
|
- name: Set Default Gateway
|
|
|
|
when: hypervisor == "vmware"
|
2024-10-30 18:04:46 +01:00
|
|
|
ansible.builtin.command: "ip route replace default via {{ vm_gw }}"
|
2024-10-28 19:20:05 +01:00
|
|
|
changed_when: result.rc == 0
|
|
|
|
register: result
|
|
|
|
|
2024-03-19 23:02:50 +01:00
|
|
|
- name: Synchronize clock via NTP
|
2024-07-11 22:20:45 +02:00
|
|
|
ansible.builtin.command: timedatectl set-ntp true
|
2024-10-28 19:20:05 +01:00
|
|
|
changed_when: result.rc == 0
|
|
|
|
register: result
|
|
|
|
|
2024-10-30 19:12:36 +01:00
|
|
|
- name: Configure SSH for root login
|
2024-10-30 18:59:32 +01:00
|
|
|
when: hypervisor == "vmware" and vmware_ssh | bool
|
2024-10-30 19:12:36 +01:00
|
|
|
block:
|
|
|
|
- name: Allow empty passwords temporarily
|
|
|
|
ansible.builtin.replace:
|
|
|
|
path: /etc/ssh/sshd_config
|
|
|
|
regexp: "^#?PermitEmptyPasswords.*"
|
|
|
|
replace: "PermitEmptyPasswords yes"
|
|
|
|
|
|
|
|
- name: Allow root login
|
|
|
|
ansible.builtin.replace:
|
|
|
|
path: /etc/ssh/sshd_config
|
|
|
|
regexp: "^#?PermitRootLogin.*"
|
|
|
|
replace: "PermitRootLogin yes"
|
|
|
|
|
|
|
|
- name: Reload SSH service to apply changes
|
|
|
|
ansible.builtin.service:
|
|
|
|
name: sshd
|
|
|
|
state: reloaded
|
|
|
|
|
|
|
|
- name: Set connection back to SSH
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
ansible_connection: ssh
|
|
|
|
ansible_user: "root"
|
|
|
|
ansible_password: ""
|
|
|
|
ansible_become_password: ""
|
|
|
|
ansible_ssh_extra_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
|
2024-10-30 18:59:32 +01:00
|
|
|
|
2024-03-19 23:02:50 +01:00
|
|
|
- name: Speed-up Bootstrap process
|
2024-07-11 22:20:45 +02:00
|
|
|
ansible.builtin.lineinfile:
|
2024-03-19 23:02:50 +01:00
|
|
|
path: /etc/pacman.conf
|
2024-07-11 22:20:45 +02:00
|
|
|
regexp: ^#ParallelDownloads =
|
|
|
|
line: ParallelDownloads = 20
|
2024-03-19 23:02:50 +01:00
|
|
|
|
|
|
|
- name: Wait for Pacman
|
2024-07-11 22:20:45 +02:00
|
|
|
ansible.builtin.wait_for:
|
2024-03-19 23:02:50 +01:00
|
|
|
timeout: 15
|
|
|
|
|
|
|
|
- name: Setup Pacman
|
2024-07-11 22:20:45 +02:00
|
|
|
community.general.pacman:
|
2024-03-20 00:07:10 +01:00
|
|
|
update_cache: true
|
|
|
|
force: true
|
2024-03-22 06:19:03 +01:00
|
|
|
name: "{{ item.name }}"
|
2024-03-19 23:02:50 +01:00
|
|
|
state: latest
|
2024-03-22 06:19:03 +01:00
|
|
|
loop:
|
2024-07-11 22:20:45 +02:00
|
|
|
- { name: glibc }
|
|
|
|
- { name: dnf, os: [almalinux, fedora, rhel9, rhel8, rocky] }
|
|
|
|
- { name: debootstrap, os: [debian11, debian12, ubuntu, ubuntu-lts] }
|
|
|
|
- { name: debian-archive-keyring, os: [debian11, debian12] }
|
|
|
|
- { name: ubuntu-keyring, os: [ubuntu, ubuntu-lts] }
|
2024-03-22 06:19:03 +01:00
|
|
|
when: "'os' not in item or os in item.os"
|
2024-03-22 05:59:39 +01:00
|
|
|
retries: 4
|
2024-03-19 23:02:50 +01:00
|
|
|
delay: 15
|
|
|
|
|
2024-10-30 00:29:46 +01:00
|
|
|
- name: Prepare /iso mount and repository for RHEL-based systems
|
|
|
|
when: os | lower in ["rhel8", "rhel9"]
|
|
|
|
block:
|
|
|
|
- name: Create /iso directory
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: /usr/local/install/redhat/dvd
|
|
|
|
state: directory
|
|
|
|
mode: '0755'
|
|
|
|
|
|
|
|
- name: Mount RHEL ISO
|
|
|
|
ansible.posix.mount:
|
2024-10-30 19:30:12 +01:00
|
|
|
src: "{{ '/dev/sr1' if hypervisor == 'vmware' else '/dev/sr2' }}"
|
2024-10-30 00:29:46 +01:00
|
|
|
path: /usr/local/install/redhat/dvd
|
|
|
|
fstype: iso9660
|
|
|
|
opts: "ro,loop"
|
|
|
|
state: mounted
|
|
|
|
|
2024-03-19 23:02:50 +01:00
|
|
|
- name: Configure RHEL Repos for installation
|
2024-10-30 00:29:46 +01:00
|
|
|
when: os | lower in ["almalinux", "fedora", "rhel8", "rhel9", "rocky"]
|
2024-03-19 23:02:50 +01:00
|
|
|
block:
|
2024-07-11 22:20:45 +02:00
|
|
|
- name: Create directories for repository files and RPM GPG keys
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: /etc/yum.repos.d
|
|
|
|
state: directory
|
2024-10-28 18:37:44 +01:00
|
|
|
mode: '0755'
|
2024-03-19 23:02:50 +01:00
|
|
|
|
2024-07-11 22:20:45 +02:00
|
|
|
- name: Create RHEL repository file
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: "{{ os | lower }}.repo.j2"
|
|
|
|
dest: /etc/yum.repos.d/{{ os | lower }}.repo
|
2024-10-28 18:37:44 +01:00
|
|
|
mode: '0644'
|