Ansible-Bootstrap/roles/environment/tasks/main.yml

103 lines
3.2 KiB
YAML
Raw Normal View History

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}'"
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-07-11 22:20:45 +02:00
ansible.builtin.command: ip addr replace {{ ansible_host }}/24 dev {{ interface_name.stdout }}
changed_when: result.rc == 0
register: result
2024-03-19 23:02:50 +01:00
- name: Set Default Gateway
when: hypervisor == "vmware"
2024-07-11 22:20:45 +02:00
ansible.builtin.command: ip route replace default via {{ vm_gw }}
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
changed_when: result.rc == 0
register: result
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:
update_cache: true
force: true
name: "{{ item.name }}"
2024-03-19 23:02:50 +01:00
state: latest
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] }
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:
src: /dev/sr2
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
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
mode: '0644'