Compare commits
111 Commits
a3b772c543
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 378d9a88c2 | |||
| 905043baf3 | |||
| 9164815185 | |||
| 81f15fffb7 | |||
| d454c3cd82 | |||
| 9ffb2aa69f | |||
| 6d843ff409 | |||
| 775dbefa67 | |||
| 06823044dd | |||
| 919c44bb29 | |||
| 0d01f2afdc | |||
| e532dcac16 | |||
| 6cbecf2db0 | |||
| d612f9dabb | |||
| 00c3cd5180 | |||
| fef1f44a07 | |||
| e1464562f7 | |||
| 60c552be45 | |||
| c96fcf5e96 | |||
| 4e70ee2e3e | |||
| 81bbd2b22a | |||
| e65fbfd570 | |||
| 122bd5cdf4 | |||
| c8d3de3d8d | |||
| 4ed15e5ea8 | |||
| 518babe328 | |||
| 918e14051d | |||
| 3d18962160 | |||
| 457d558133 | |||
| e06a95fdbc | |||
| 7bae512560 | |||
| 3e91057689 | |||
| e9647571fc | |||
| c32769d831 | |||
| 7cfa4aee8d | |||
| a7e7f49d84 | |||
| cfcccbf512 | |||
| 75c4ba6b4c | |||
| b62066d675 | |||
| 53a2c27984 | |||
| bb82ff120b | |||
| 221d77b94d | |||
| d71ea511f9 | |||
| b3299781dc | |||
| 5e7a06b7db | |||
| d77f65ce05 | |||
| 39fc15d7d8 | |||
| b076968404 | |||
| 4f03ccbfcf | |||
| 5746be4561 | |||
| 39cc49a05b | |||
| 2d63ca9c5a | |||
| 9f56328890 | |||
| dc763bdc42 | |||
| 25deaab87d | |||
| 89f054e8fd | |||
| cbe238f4d5 | |||
| c6f1686db8 | |||
| c9a15dfccf | |||
| f83a9ebd67 | |||
| e16868a78d | |||
| 406db38296 | |||
| cb3f36a040 | |||
| d97f0cfff8 | |||
| e8f609dd03 | |||
| a599e26a63 | |||
| 3085ebc336 | |||
| f967ea1c3b | |||
| 2c4995ede8 | |||
| ccf3193c92 | |||
| d92944c345 | |||
| 3c94a33ae7 | |||
| af82baf1d8 | |||
| ec55701f00 | |||
| 2a1a47ecc1 | |||
| 4808ce4401 | |||
| db1fd13623 | |||
| e5660b0ba7 | |||
| 173ecd299b | |||
| 4d242ad987 | |||
| f8ac22cfab | |||
| 12a7549aaa | |||
| 6705411b2d | |||
| fe2b216fc7 | |||
| 26824ca6bb | |||
| c60fcca86d | |||
| cdd8062937 | |||
| ebedff1c4e | |||
| 04d05a4e8b | |||
| ee6e06a3fe | |||
| 527bc11d1d | |||
| d331e07536 | |||
| 287036bcb4 | |||
| ca5a3c8807 | |||
| c8dd89681b | |||
| 9d4af56976 | |||
| 3c55eaf4a1 | |||
| d905dce89e | |||
| 76f1382e3e | |||
| 04c27cd7d0 | |||
| 147430b36e | |||
| f8ba5c41db | |||
| 7a4fc24f32 | |||
| 7bf7c29291 | |||
| ccfce65673 | |||
| 528f2fc775 | |||
| 505110f580 | |||
| 1d1b2fff42 | |||
| 4cf4816be0 | |||
| e37b5a535b | |||
| 5312ec8cc6 |
36
README.md
36
README.md
@@ -3,27 +3,33 @@
|
|||||||
An Ansible playbook for automating system bootstrap processes in an Infrastructure-as-Code manner, utilizing ArchISO as the foundational tool.
|
An Ansible playbook for automating system bootstrap processes in an Infrastructure-as-Code manner, utilizing ArchISO as the foundational tool.
|
||||||
|
|
||||||
# Info
|
# Info
|
||||||
|
|
||||||
Most of the roles are adaptable for use with systems beyond ArchLinux, requiring only that the target system can install a necessary package manager, such as `dnf` for RHEL-based systems. Additionally, a replacement for the `arch-chroot` command may be required for these systems.
|
Most of the roles are adaptable for use with systems beyond ArchLinux, requiring only that the target system can install a necessary package manager, such as `dnf` for RHEL-based systems. Additionally, a replacement for the `arch-chroot` command may be required for these systems.
|
||||||
|
|
||||||
**NOTE**:
|
**NOTE**:
|
||||||
- RHEL Systems are not currently supported due to restricted access to their repositories.
|
|
||||||
A workaround could involve using an ISO as a local repository or setting up a proxy repository to facilitate access.
|
- For RHEL 8 and RHEL 9, repository access requires the `rhel_iso` variable. This variable specifies a local ISO or proxy repository.
|
||||||
|
- RHEL systems do not support `btrfs`. Use `ext4` or `xfs` as alternatives.
|
||||||
|
- For RHEL 8, `xfs` may cause installation issues; `ext4` is recommended.
|
||||||
|
|
||||||
# Supported Distributions
|
# Supported Distributions
|
||||||
|
|
||||||
This playbook supports multiple Linux distributions with specific versions tailored to each. Below is a list of supported distributions:
|
This playbook supports multiple Linux distributions with specific versions tailored to each. Below is a list of supported distributions:
|
||||||
|
|
||||||
| `os` | Distribution |
|
| `os` | Distribution |
|
||||||
|------------|------------------------------------|
|
| ---------- | ---------------------------------- |
|
||||||
| archlinux | ArchLinux (Latest rolling release) |
|
| archlinux | ArchLinux (Latest rolling release) |
|
||||||
| almalinux | AlmaLinux 9.x |
|
| almalinux | AlmaLinux 9.x |
|
||||||
| debian11 | Debian 11 (Bullseye) |
|
| debian11 | Debian 11 (Bullseye) |
|
||||||
| debian12 | Debian 12 (Bookworm) |
|
| debian12 | Debian 12 (Bookworm) |
|
||||||
| fedora | Fedora 40 |
|
| debian13 | Debian 13 (Trixie) |
|
||||||
|
| fedora | Fedora 42 |
|
||||||
|
| rhel8 | Red Hat Enterprise Linux 8 |
|
||||||
|
| rhel9 | Red Hat Enterprise Linux 9 |
|
||||||
|
| rhel10 | Red Hat Enterprise Linux 10 |
|
||||||
| rocky | Rocky Linux 9.x |
|
| rocky | Rocky Linux 9.x |
|
||||||
| ubuntu | Ubuntu 23.10 (Mantic Minotaur) |
|
| ubuntu | Ubuntu 25.04 (Plucky Puffin) |
|
||||||
| ubuntu-lts | Ubuntu 22.04 LTS (Jammy Jellyfish) |
|
| ubuntu-lts | Ubuntu 24.04 LTS (Noble Numbat) |
|
||||||
|
|
||||||
|
|
||||||
# Documentation
|
# Documentation
|
||||||
|
|
||||||
@@ -46,9 +52,12 @@ The playbook uses the ArchLinux ISO as a foundational tool to provides an effici
|
|||||||
Global variables apply across your Ansible project and are loaded from `vars.yml` by default. These variables define common settings such as hypervisor connection details and the boot ISO path. They can be overridden by inventory variables for specific hosts or VMs if needed.
|
Global variables apply across your Ansible project and are loaded from `vars.yml` by default. These variables define common settings such as hypervisor connection details and the boot ISO path. They can be overridden by inventory variables for specific hosts or VMs if needed.
|
||||||
|
|
||||||
| Variable | Description | Example Value |
|
| Variable | Description | Example Value |
|
||||||
|-----------------------|--------------------------------------------------------------------|-----------------------------------------|
|
| ----------------------- | ---------------------------------------------------------- | ----------------------------------------- |
|
||||||
| `boot_iso` | Path to the boot ISO image. | `local-btrfs:iso/archlinux-x86_64.iso` |
|
| `boot_iso` | Path to the boot ISO image. | `local-btrfs:iso/archlinux-x86_64.iso` |
|
||||||
|
| `rhel_iso` | Path to the RHEL ISO file, required for RHEL 8 and RHEL 9. | `local-btrfs:iso/rhel-9.4-x86_64-dvd.iso` |
|
||||||
| `hypervisor` | Type of hypervisor. | `libvirt`, `proxmox`, `vmware`, `none` |
|
| `hypervisor` | Type of hypervisor. | `libvirt`, `proxmox`, `vmware`, `none` |
|
||||||
|
| `vmware_ssh` | If Ansible should use SSH after base VM setup on VMware. | `true`, `false (default)` |
|
||||||
|
| `hypervisor_datacenter` | Name of the hypervisor datacenter. | `default-datacenter` |
|
||||||
| `hypervisor_cluster` | Name of the hypervisor cluster. | `default-cluster` |
|
| `hypervisor_cluster` | Name of the hypervisor cluster. | `default-cluster` |
|
||||||
| `hypervisor_node` | Hypervisor node name. | `node01` |
|
| `hypervisor_node` | Hypervisor node name. | `node01` |
|
||||||
| `hypervisor_password` | Password for hypervisor authentication. | `123456` |
|
| `hypervisor_password` | Password for hypervisor authentication. | `123456` |
|
||||||
@@ -59,25 +68,32 @@ Global variables apply across your Ansible project and are loaded from `vars.yml
|
|||||||
| `install_type` | Type of installation. | `virtual`, `physical` |
|
| `install_type` | Type of installation. | `virtual`, `physical` |
|
||||||
| `vlan_name` (optional) | VLAN for the VM's network interface. | `vlan100` |
|
| `vlan_name` (optional) | VLAN for the VM's network interface. | `vlan100` |
|
||||||
|
|
||||||
|
To protect sensitive information, such as passwords, API keys, and other confidential variables (e.g., `hypervisor_password`), **it is recommended to use Ansible Vault**.
|
||||||
|
|
||||||
## 3. Inventory Variables
|
## 3. Inventory Variables
|
||||||
|
|
||||||
Inventory variables are defined for individual hosts or VMs in the inventory file, allowing customization of settings such as the operating system, filesystem, and compliance with CIS benchmarks. These variables can be set globally and overridden for specific hosts or VMs.
|
Inventory variables are defined for individual hosts or VMs in the inventory file, allowing customization of settings such as the operating system, filesystem, and compliance with CIS benchmarks. These variables can be set globally and overridden for specific hosts or VMs.
|
||||||
|
|
||||||
| Variable | Description | Example Value |
|
| Variable | Description | Example Value |
|
||||||
|-------------------------|-----------------------------------------------------------------------------------|----------------------------------------------------|
|
| --------------------- | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `cis` (optional) | Adjusts the installation to be CIS level 3 conformant. | `true`, `false` |
|
| `cis` (optional) | Adjusts the installation to be CIS level 3 conformant. | `true`, `false` |
|
||||||
|
| `selinux` (optional) | Toggle SELinux, `false` means it should be disabled.` | `true`, `false` |
|
||||||
| `filesystem` | Filesystem type for the VM's primary storage. | `btrfs`, `ext4`, `xfs` |
|
| `filesystem` | Filesystem type for the VM's primary storage. | `btrfs`, `ext4`, `xfs` |
|
||||||
| `hostname` | The hostname assigned to the virtual machine or system. | `vm01` |
|
| `hostname` | The hostname assigned to the virtual machine or system. | `vm01` |
|
||||||
| `os` | Operating system to be installed on the VM. | `archlinux`, `almalinux`, `debian11`, `debian12`, `fedora`, `rocky`, `ubuntu`, `ubuntu-lts` |
|
| `os` | Operating system to be installed on the VM. | `archlinux`, `almalinux`, `debian11`, `debian12`, `fedora`, `rhel8`, `rhel9`, `rhel10`, `rocky`, `ubuntu`, `ubuntu-lts` |
|
||||||
| `root_password` | Root password for the VM or system, used for initial setup or secure access. | `SecurePass123` |
|
| `root_password` | Root password for the VM or system, used for initial setup or secure access. | `SecurePass123` |
|
||||||
| `user_name` | Username for a user account within the VM, often used with cloud-init. | `adminuser` |
|
| `user_name` | Username for a user account within the VM, often used with cloud-init. | `adminuser` |
|
||||||
| `user_password` | Password for the user account within the VM. | `UserPass123` |
|
| `user_password` | Password for the user account within the VM. | `UserPass123` |
|
||||||
|
| `user_public_key` | SSH Key for the user account within the VM. | `ssh-ed25519 AAAAC` |
|
||||||
| `vm_ballo` (optional) | Ballooning memory size for the VM, used to adjust memory allocation dynamically. | `2048` |
|
| `vm_ballo` (optional) | Ballooning memory size for the VM, used to adjust memory allocation dynamically. | `2048` |
|
||||||
| `vm_cpus` | Number of CPU cores assigned to the virtual machine. | `4` |
|
| `vm_cpus` | Number of CPU cores assigned to the virtual machine. | `4` |
|
||||||
| `vm_dns` | DNS server IP address(es) for the virtual machine's network configuration. | `1.0.0.1`, `1.1.1.1` |
|
| `vm_dns` | DNS server IP address(es) for the virtual machine's network configuration. | `1.0.0.1`, `1.1.1.1` |
|
||||||
|
| `vm_dns_search` | DNS search zone for the virtual machine's network configuration. | `example.com` |
|
||||||
| `vm_gw` | Default gateway IP address for the virtual machine's network configuration. | `192.168.0.1` |
|
| `vm_gw` | Default gateway IP address for the virtual machine's network configuration. | `192.168.0.1` |
|
||||||
| `vm_id` | Unique identifier for the virtual machine. | `101` |
|
| `vm_id` | Unique identifier for the virtual machine. | `101` |
|
||||||
| `vm_ip` | IP address assigned to the virtual machine. | `192.168.0.10` |
|
| `vm_ip` | IP address assigned to the virtual machine. | `192.168.0.10` |
|
||||||
|
| `vm_nm` (optional) | IP address netmask assigned to the virtual machine. | `255.255.255.0` |
|
||||||
|
| `vm_nms` (optional) | IP address netmask assigned to the virtual machine. | `24` |
|
||||||
| `vm_memory` | Amount of memory (in MB) allocated to the virtual machine. | `2048` |
|
| `vm_memory` | Amount of memory (in MB) allocated to the virtual machine. | `2048` |
|
||||||
| `vm_nif` | Network interface type or identifier for the VM's network connection. | `vmbr0` |
|
| `vm_nif` | Network interface type or identifier for the VM's network connection. | `vmbr0` |
|
||||||
| `vm_path (optional)` | Path or folder where the VM configuration or related files will be stored. | `/var/lib/libvirt/images/` |
|
| `vm_path (optional)` | Path or folder where the VM configuration or related files will be stored. | `/var/lib/libvirt/images/` |
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
[promox-kvm]
|
|
||||||
192.168.122.10
|
|
||||||
192.168.122.11
|
|
||||||
|
|
||||||
[promox-kvm:vars]
|
|
||||||
vm_gw=192.168.122.1
|
|
||||||
vm_dns=1.1.1.1
|
|
||||||
|
|
||||||
[192.168.122.10]
|
|
||||||
hostname=proxy
|
|
||||||
vm_id=300
|
|
||||||
os=archlinux
|
|
||||||
filesystem=btrfs
|
|
||||||
vm_memory=2048
|
|
||||||
vm_ballo=1024
|
|
||||||
vm_cpus=2
|
|
||||||
vm_size=5
|
|
||||||
vm_nif=vmbr1
|
|
||||||
|
|
||||||
[192.168.122.11]
|
|
||||||
hostname=database
|
|
||||||
vm_id=101
|
|
||||||
os=archlinux
|
|
||||||
filesystem=btrfs
|
|
||||||
vm_memory=6144
|
|
||||||
vm_ballo=3072
|
|
||||||
vm_cpus=4
|
|
||||||
vm_size=40
|
|
||||||
vm_nif=vmbr1
|
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
all:
|
all:
|
||||||
|
vars:
|
||||||
|
hypervisor: 'proxmox'
|
||||||
|
install_drive: '/dev/sda'
|
||||||
|
cis: true
|
||||||
|
boot_iso: "local-btrfs:iso/archlinux-x86_64.iso"
|
||||||
children:
|
children:
|
||||||
promox-kvm:
|
promox-kvm:
|
||||||
hosts:
|
hosts:
|
||||||
@@ -14,11 +19,12 @@ all:
|
|||||||
vm_nif: vmbr1
|
vm_nif: vmbr1
|
||||||
vm_gw: 192.168.122.1
|
vm_gw: 192.168.122.1
|
||||||
vm_dns: 1.1.1.1
|
vm_dns: 1.1.1.1
|
||||||
|
vm_dns_search: "example.com"
|
||||||
192.168.122.11:
|
192.168.122.11:
|
||||||
hostname: database
|
hostname: database
|
||||||
vm_id: 101
|
vm_id: 101
|
||||||
os: archlinux
|
os: rhel9
|
||||||
filesystem: btrfs
|
filesystem: xfs
|
||||||
vm_memory: "6144"
|
vm_memory: "6144"
|
||||||
vm_ballo: "3072"
|
vm_ballo: "3072"
|
||||||
vm_cpus: "4"
|
vm_cpus: "4"
|
||||||
@@ -26,3 +32,4 @@ all:
|
|||||||
vm_nif: vmbr1
|
vm_nif: vmbr1
|
||||||
vm_gw: 192.168.122.1
|
vm_gw: 192.168.122.1
|
||||||
vm_dns: 1.1.1.1
|
vm_dns: 1.1.1.1
|
||||||
|
rhel_iso: "local-btrfs:iso/rhel-9.4-x86_64-dvd.iso"
|
||||||
|
|||||||
61
main.yml
61
main.yml
@@ -10,6 +10,11 @@
|
|||||||
What is your username?
|
What is your username?
|
||||||
private: false
|
private: false
|
||||||
|
|
||||||
|
- name: user_public_key
|
||||||
|
prompt: |
|
||||||
|
What is your ssh key?
|
||||||
|
private: false
|
||||||
|
|
||||||
- name: user_password
|
- name: user_password
|
||||||
prompt: |
|
prompt: |
|
||||||
What is your password?
|
What is your password?
|
||||||
@@ -19,36 +24,36 @@
|
|||||||
prompt: |
|
prompt: |
|
||||||
What is your root password?
|
What is your root password?
|
||||||
confirm: true
|
confirm: true
|
||||||
|
|
||||||
- name: hypervisor
|
|
||||||
prompt: |
|
|
||||||
Select an Hypervisor:
|
|
||||||
- libvirt
|
|
||||||
- proxmox
|
|
||||||
- vmware
|
|
||||||
private: false
|
|
||||||
default: proxmox
|
|
||||||
|
|
||||||
- name: install_drive
|
|
||||||
prompt: |
|
|
||||||
"Enter the drive to install the system (default: /dev/sda)"
|
|
||||||
confirm: true
|
|
||||||
private: false
|
|
||||||
default: /dev/sda
|
|
||||||
vars_files: vars.yml
|
vars_files: vars.yml
|
||||||
pre_tasks:
|
pre_tasks:
|
||||||
- name: Set ansible_python_interpreter
|
- name: Set ansible_python_interpreter
|
||||||
when: os | lower in ["almalinux", "rhel9", "rhel8", "rocky"]
|
when: os | lower in ["almalinux", "rhel8", "rhel9", "rhel10", "rocky"]
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
ansible_python_interpreter: /usr/bin/python3
|
ansible_python_interpreter: /usr/bin/python3
|
||||||
|
|
||||||
|
- name: Set default variables
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
cis: false
|
||||||
|
|
||||||
|
- name: Set SSH Access
|
||||||
|
when: hypervisor != "vmware"
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
ansible_user: "{{ user_name }}"
|
||||||
|
ansible_password: "{{ user_password }}"
|
||||||
|
ansible_become_password: "{{ user_password }}"
|
||||||
|
ansible_ssh_extra_args: "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
|
||||||
|
|
||||||
- name: Validate variables
|
- name: Validate variables
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- hypervisor in ["libvirt", "proxmox", "vmware", "none"]
|
- hypervisor in ["libvirt", "proxmox", "vmware", "none"]
|
||||||
- filesystem in ["btrfs", "ext4", "xfs"]
|
- filesystem in ["btrfs", "ext4", "xfs"]
|
||||||
- os in ["archlinux", "almalinux", "debian11", "debian12", "fedora", "rocky", "ubuntu", "ubuntu-lts"]
|
- install_drive is defined
|
||||||
fail_msg: Invalid input specified, please try again
|
- os in ["archlinux", "almalinux", "debian11", "debian12", "debian13", "fedora", "rhel8", "rhel9", "rhel10", "rocky", "ubuntu", "ubuntu-lts"]
|
||||||
|
- os not in ["rhel8", "rhel9", "rhel10"] or rhel_iso is defined
|
||||||
|
- (filesystem == "btrfs" and (vm_size | int) >= 10) or (filesystem != "btrfs" and (vm_size | int) >= 20)
|
||||||
|
- (vm_size | float) >= ((vm_memory | float / 1024 >= 16.0) | ternary((vm_memory | float / 2048), [vm_memory | float / 1024, 4.0] | max) + 16)
|
||||||
|
fail_msg: Invalid input specified, please try again.
|
||||||
|
|
||||||
- name: Set connection
|
- name: Set connection
|
||||||
when: hypervisor == "vmware"
|
when: hypervisor == "vmware"
|
||||||
@@ -76,7 +81,7 @@
|
|||||||
- role: configuration
|
- role: configuration
|
||||||
|
|
||||||
- role: cis
|
- role: cis
|
||||||
when: cis == true
|
when: cis | bool
|
||||||
|
|
||||||
- role: cleanup
|
- role: cleanup
|
||||||
when: install_type == "virtual"
|
when: install_type == "virtual"
|
||||||
@@ -84,7 +89,15 @@
|
|||||||
ansible_connection: local
|
ansible_connection: local
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Reboot system
|
- name: Set final SSH Credentials
|
||||||
when: hypervisor != "libvirt"
|
when: hypervisor != 'vmware' or (hypervisor == 'vmware' and vmware_ssh | bool)
|
||||||
ansible.builtin.command: reboot
|
ansible.builtin.set_fact:
|
||||||
ignore_errors: true
|
ansible_user: "{{ user_name }}"
|
||||||
|
ansible_password: "{{ user_password }}"
|
||||||
|
ansible_become_password: "{{ user_password }}"
|
||||||
|
ansible_ssh_extra_args: "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
|
||||||
|
|
||||||
|
- name: Check if VM is back and running
|
||||||
|
when: not (hypervisor == 'vmware' and cis | bool)
|
||||||
|
ansible.builtin.wait_for_connection:
|
||||||
|
timeout: 300
|
||||||
|
|||||||
@@ -1,65 +1,101 @@
|
|||||||
---
|
---
|
||||||
- name: Include Packages
|
|
||||||
ansible.builtin.include_vars:
|
|
||||||
file: packages.yml
|
|
||||||
name: role_packages
|
|
||||||
|
|
||||||
- name: Run OS-specific bootstrap process
|
- name: Run OS-specific bootstrap process
|
||||||
block:
|
block:
|
||||||
- name: Bootstrap ArchLinux
|
- name: Bootstrap ArchLinux
|
||||||
when: os | lower == 'archlinux'
|
when: os | lower == 'archlinux'
|
||||||
ansible.builtin.command: pacstrap /mnt {{ role_packages.archlinux | join(' ') }} --asexplicit
|
ansible.builtin.command: pacstrap /mnt {{ archlinux | join(' ') }} --asexplicit
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Bootstrap Debian System
|
- name: Bootstrap Debian System
|
||||||
when: os | lower in ['debian11', 'debian12']
|
when: os | lower in ['debian11', 'debian12', 'debian13']
|
||||||
ansible.builtin.command: "{{ item }}"
|
ansible.builtin.command: "{{ item }}"
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
with_items:
|
with_items:
|
||||||
- |
|
- debootstrap --include={{ vars[os].base | join(',') }} {{ 'bullseye' if os == 'debian11' else 'bookworm' if os == 'debian12' else 'trixie' }}
|
||||||
debootstrap --include={{ role_packages[os].base | join(',') }} {{ 'bullseye' if os == 'debian11' else 'bookworm' }} \
|
|
||||||
/mnt http://deb.debian.org/debian/
|
/mnt http://deb.debian.org/debian/
|
||||||
- arch-chroot /mnt apt install -y {{ role_packages[os].extra | join(' ') }}
|
- arch-chroot /mnt apt install -y {{ vars[os].extra | join(' ') }}
|
||||||
- arch-chroot /mnt apt remove -y libcups2 libavahi-common3 libavahi-common-data
|
- arch-chroot /mnt apt remove -y libcups2 libavahi-common3 libavahi-common-data
|
||||||
|
|
||||||
- name: Bootstrap Ubuntu System
|
- name: Bootstrap Ubuntu System
|
||||||
when: os | lower in ['ubuntu', 'ubuntu-lts']
|
when: os | lower in ['ubuntu', 'ubuntu-lts']
|
||||||
ansible.builtin.command: "{{ item }}"
|
ansible.builtin.command: "{{ item }}"
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
with_items:
|
with_items:
|
||||||
- |
|
- debootstrap --include={{ vars[os].base | join(',') }} {{ 'plucky' if os == 'ubuntu' else 'noble' }}
|
||||||
debootstrap --include={{ role_packages[os].base | join(',') }} {{ 'mantic' if os == 'ubuntu' else 'jammy' }} \
|
|
||||||
/mnt http://archive.ubuntu.com/ubuntu/
|
/mnt http://archive.ubuntu.com/ubuntu/
|
||||||
|
- ln -sf /run/NetworkManager/resolv.conf /mnt/etc/resolv.conf
|
||||||
- arch-chroot /mnt sed -i '1s|$| universe|' /etc/apt/sources.list
|
- arch-chroot /mnt sed -i '1s|$| universe|' /etc/apt/sources.list
|
||||||
- arch-chroot /mnt apt update -y
|
- arch-chroot /mnt apt update -y
|
||||||
- arch-chroot /mnt apt install -y {{ role_packages[os].extra | join(' ') }}
|
- arch-chroot /mnt apt install -y {{ vars[os].extra | join(' ') }}
|
||||||
|
|
||||||
- name: Bootstrap AlmaLinux 9
|
- name: Bootstrap AlmaLinux 9
|
||||||
when: os | lower == 'almalinux'
|
when: os | lower == 'almalinux'
|
||||||
ansible.builtin.command: "{{ item }}"
|
ansible.builtin.command: "{{ item }}"
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
with_items:
|
with_items:
|
||||||
- dnf --releasever=9 --best --repo=alma-baseos --installroot=/mnt --setopt=install_weak_deps=False groupinstall -y base core
|
- dnf --releasever=9 --best --repo=alma-baseos --installroot=/mnt --setopt=install_weak_deps=False groupinstall -y base core
|
||||||
- echo "nameserver 1.0.0.1" > /mnt/etc/resolv.conf
|
- ln -sf /run/NetworkManager/resolv.conf /mnt/etc/resolv.conf
|
||||||
- arch-chroot /mnt dnf --releasever=9 --setopt=install_weak_deps=False install -y {{ role_packages.almalinux | join(' ') }}
|
- arch-chroot /mnt dnf --releasever=9 --setopt=install_weak_deps=False install -y {{ almalinux | join(' ') }}
|
||||||
|
|
||||||
- name: Bootstrap Fedora 40
|
- name: Bootstrap Fedora 42
|
||||||
when: os | lower == 'fedora'
|
when: os | lower == 'fedora'
|
||||||
ansible.builtin.command: "{{ item }}"
|
ansible.builtin.command: "{{ item }}"
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
with_items:
|
with_items:
|
||||||
- |
|
- dnf --releasever=42 --best --repo=fedora --repo=fedora-updates
|
||||||
dnf --releasever=40 --best --repo=fedora --repo=fedora-updates \
|
|
||||||
--installroot=/mnt --setopt=install_weak_deps=False groupinstall -y critical-path-base core
|
--installroot=/mnt --setopt=install_weak_deps=False groupinstall -y critical-path-base core
|
||||||
- arch-chroot /mnt dnf --releasever=40 --setopt=install_weak_deps=False install -y {{ role_packages.fedora | join(' ') }}
|
- ln -sf /run/NetworkManager/resolv.conf /mnt/etc/resolv.conf
|
||||||
|
- arch-chroot /mnt dnf --releasever=42 --setopt=install_weak_deps=False install -y {{ fedora | join(' ') }}
|
||||||
- arch-chroot /mnt dnf reinstall -y kernel-core
|
- arch-chroot /mnt dnf reinstall -y kernel-core
|
||||||
|
|
||||||
- name: Bootstrap RockyLinux 9
|
- name: Bootstrap RockyLinux 9
|
||||||
when: os | lower == 'rocky'
|
when: os | lower == 'rocky'
|
||||||
ansible.builtin.command: "{{ item }}"
|
ansible.builtin.command: "{{ item }}"
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
with_items:
|
with_items:
|
||||||
- dnf --releasever=9 --best --repo=rocky-baseos --installroot=/mnt --setopt=install_weak_deps=False groupinstall -y base core
|
- dnf --releasever=9 --best --repo=rocky-baseos --installroot=/mnt
|
||||||
- echo "nameserver 1.0.0.1" > /mnt/etc/resolv.conf
|
--setopt=install_weak_deps=False --setopt=optional_metadata_types=filelists
|
||||||
- arch-chroot /mnt dnf --releasever=9 --setopt=install_weak_deps=False install -y {{ role_packages.rocky | join(' ') }}
|
groupinstall -y base core
|
||||||
|
- ln -sf /run/NetworkManager/resolv.conf /mnt/etc/resolv.conf
|
||||||
|
- arch-chroot /mnt dnf --releasever=9 --setopt=install_weak_deps=False install -y {{ rocky | join(' ') }}
|
||||||
|
|
||||||
- name: Bootstrap RHEL System
|
- name: Bootstrap RHEL System
|
||||||
when: os | lower in ['rhel8', 'rhel9']
|
when: os | lower in ['rhel8', 'rhel9', 'rhel10']
|
||||||
ansible.builtin.command: "{{ item }}"
|
block:
|
||||||
with_items:
|
- name: Install base packages in chroot environment
|
||||||
- dnf --releasever={{ '8' if os == 'rhel8' else '9' }} --installroot=/mnt --setopt=install_weak_deps=False groupinstall -y base core
|
ansible.builtin.command: >-
|
||||||
- echo 'nameserver 1.0.0.1' > /mnt/etc/resolv.conf
|
dnf --releasever={{ os | lower | replace('rhel', '') }} --repo={{ os | lower }}-baseos
|
||||||
- arch-chroot /mnt dnf --releasever={{ '8' if os == 'rhel8' else '9' }} --setopt=install_weak_deps=False install -y {{ role_packages[os] | join(' ') }}
|
--installroot=/mnt
|
||||||
|
--setopt=install_weak_deps=False --setopt=optional_metadata_types=filelists
|
||||||
|
groupinstall -y core base standard
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Prepare chroot environment
|
||||||
|
ansible.builtin.shell: |
|
||||||
|
ln -sf /run/NetworkManager/resolv.conf /mnt/etc/resolv.conf
|
||||||
|
mkdir -p /mnt/usr/local/install/redhat/dvd
|
||||||
|
mount --bind /usr/local/install/redhat/dvd /mnt/usr/local/install/redhat/dvd
|
||||||
|
arch-chroot /mnt rpm --rebuilddb
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Copy RHEL repo file into chroot environment
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: /etc/yum.repos.d/{{ os | lower }}.repo
|
||||||
|
dest: /mnt/etc/yum.repos.d/redhat.repo
|
||||||
|
mode: "0644"
|
||||||
|
remote_src: true
|
||||||
|
|
||||||
|
- name: Install additional packages in chroot
|
||||||
|
ansible.builtin.command: >-
|
||||||
|
arch-chroot /mnt dnf --releasever={{ os | lower | replace('rhel', '') }}
|
||||||
|
--setopt=install_weak_deps=False install -y {{ vars[os] | join(' ') }}
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
---
|
|
||||||
almalinux:
|
almalinux:
|
||||||
- bind-utils
|
- bind-utils
|
||||||
- cloud-init
|
|
||||||
- dbus-daemon
|
- dbus-daemon
|
||||||
- dhcp-client
|
- dhcp-client
|
||||||
- efibootmgr
|
- efibootmgr
|
||||||
@@ -14,23 +12,26 @@ almalinux:
|
|||||||
- nc
|
- nc
|
||||||
- nfs-utils
|
- nfs-utils
|
||||||
- nfsv4-client-utils
|
- nfsv4-client-utils
|
||||||
|
- mtr
|
||||||
- open-vm-tools
|
- open-vm-tools
|
||||||
- ppp
|
- ppp
|
||||||
- shim
|
- shim
|
||||||
- telnet
|
- tmux
|
||||||
- vim
|
- vim
|
||||||
- wget
|
- wget
|
||||||
|
- zram-generator
|
||||||
- zstd
|
- zstd
|
||||||
|
|
||||||
archlinux:
|
archlinux:
|
||||||
- base
|
- base
|
||||||
- btrfs-progs
|
- btrfs-progs
|
||||||
- cloud-init
|
|
||||||
- cronie
|
- cronie
|
||||||
- dhcpcd
|
- dhcpcd
|
||||||
- efibootmgr
|
- efibootmgr
|
||||||
|
- fastfetch
|
||||||
- firewalld
|
- firewalld
|
||||||
- fish
|
- fish
|
||||||
|
- fzf
|
||||||
- grub
|
- grub
|
||||||
- htop
|
- htop
|
||||||
- libpwquality
|
- libpwquality
|
||||||
@@ -40,21 +41,22 @@ archlinux:
|
|||||||
- lsof
|
- lsof
|
||||||
- lvm2
|
- lvm2
|
||||||
- ncdu
|
- ncdu
|
||||||
- neofetch
|
|
||||||
- networkmanager
|
- networkmanager
|
||||||
- nfs-utils
|
- nfs-utils
|
||||||
- openssh
|
|
||||||
- open-vm-tools
|
- open-vm-tools
|
||||||
|
- openssh
|
||||||
- ppp
|
- ppp
|
||||||
- prometheus-node-exporter
|
- prometheus-node-exporter
|
||||||
- python-psycopg2
|
- python-psycopg2
|
||||||
- qemu-guest-agent
|
- qemu-guest-agent
|
||||||
- reflector
|
- reflector
|
||||||
- rsync
|
- rsync
|
||||||
- screen
|
|
||||||
- sudo
|
- sudo
|
||||||
|
- tldr
|
||||||
|
- tmux
|
||||||
- vim
|
- vim
|
||||||
- wireguard-tools
|
- wireguard-tools
|
||||||
|
- zram-generator
|
||||||
|
|
||||||
debian11:
|
debian11:
|
||||||
base:
|
base:
|
||||||
@@ -77,23 +79,29 @@ debian11:
|
|||||||
- xfsprogs
|
- xfsprogs
|
||||||
|
|
||||||
extra:
|
extra:
|
||||||
- cloud-init
|
- bat
|
||||||
- curl
|
- curl
|
||||||
|
- entr
|
||||||
- firewalld
|
- firewalld
|
||||||
- fish
|
- fish
|
||||||
|
- fzf
|
||||||
- htop
|
- htop
|
||||||
|
- jq
|
||||||
- libpam-pwquality
|
- libpam-pwquality
|
||||||
- lrzsz
|
- lrzsz
|
||||||
|
- mtr
|
||||||
- ncdu
|
- ncdu
|
||||||
- neofetch
|
- neofetch
|
||||||
- network-manager
|
- network-manager
|
||||||
- open-vm-tools
|
- open-vm-tools
|
||||||
- python-is-python3
|
- python-is-python3
|
||||||
|
- ripgrep
|
||||||
- rsync
|
- rsync
|
||||||
- screen
|
- screen
|
||||||
- software-properties-common
|
- software-properties-common
|
||||||
- syslog-ng
|
- syslog-ng
|
||||||
- tcpd
|
- tcpd
|
||||||
|
- tldr
|
||||||
- vim
|
- vim
|
||||||
- wget
|
- wget
|
||||||
- zstd
|
- zstd
|
||||||
@@ -114,15 +122,20 @@ debian12:
|
|||||||
|
|
||||||
extra:
|
extra:
|
||||||
- apparmor-utils
|
- apparmor-utils
|
||||||
|
- bat
|
||||||
- chrony
|
- chrony
|
||||||
- cloud-init
|
|
||||||
- curl
|
- curl
|
||||||
|
- duf
|
||||||
|
- entr
|
||||||
- firewalld
|
- firewalld
|
||||||
- fish
|
- fish
|
||||||
|
- fzf
|
||||||
- htop
|
- htop
|
||||||
|
- jq
|
||||||
- libpam-pwquality
|
- libpam-pwquality
|
||||||
- logrotate
|
- logrotate
|
||||||
- lrzsz
|
- lrzsz
|
||||||
|
- mtr
|
||||||
- ncdu
|
- ncdu
|
||||||
- neofetch
|
- neofetch
|
||||||
- net-tools
|
- net-tools
|
||||||
@@ -131,27 +144,85 @@ debian12:
|
|||||||
- openssh-server
|
- openssh-server
|
||||||
- python-is-python3
|
- python-is-python3
|
||||||
- python3
|
- python3
|
||||||
|
- ripgrep
|
||||||
- rsync
|
- rsync
|
||||||
- screen
|
- screen
|
||||||
- software-properties-common
|
- software-properties-common
|
||||||
- sudo
|
- sudo
|
||||||
- syslog-ng
|
- syslog-ng
|
||||||
|
- systemd-zram-generator
|
||||||
|
- tcpd
|
||||||
|
- tldr
|
||||||
|
- vim
|
||||||
|
- wget
|
||||||
|
- zstd
|
||||||
|
|
||||||
|
debian13:
|
||||||
|
base:
|
||||||
|
- btrfs-progs
|
||||||
|
- cron
|
||||||
|
- gnupg
|
||||||
|
- grub-efi
|
||||||
|
- grub-efi-amd64-signed
|
||||||
|
- grub2-common
|
||||||
|
- linux-image-amd64
|
||||||
|
- locales
|
||||||
|
- logrotate
|
||||||
|
- lvm2
|
||||||
|
- xfsprogs
|
||||||
|
|
||||||
|
extra:
|
||||||
|
- apparmor-utils
|
||||||
|
- bat
|
||||||
|
- chrony
|
||||||
|
- curl
|
||||||
|
- duf
|
||||||
|
- entr
|
||||||
|
- fastfetch
|
||||||
|
- firewalld
|
||||||
|
- fish
|
||||||
|
- fzf
|
||||||
|
- htop
|
||||||
|
- jq
|
||||||
|
- libpam-pwquality
|
||||||
|
- logrotate
|
||||||
|
- lrzsz
|
||||||
|
- mtr
|
||||||
|
- ncdu
|
||||||
|
- net-tools
|
||||||
|
- network-manager
|
||||||
|
- open-vm-tools
|
||||||
|
- openssh-server
|
||||||
|
- python-is-python3
|
||||||
|
- python3
|
||||||
|
- ripgrep
|
||||||
|
- rsync
|
||||||
|
- screen
|
||||||
|
- sudo
|
||||||
|
- syslog-ng
|
||||||
|
- systemd-zram-generator
|
||||||
- tcpd
|
- tcpd
|
||||||
- vim
|
- vim
|
||||||
- wget
|
- wget
|
||||||
- zstd
|
- zstd
|
||||||
|
|
||||||
fedora:
|
fedora:
|
||||||
|
- bat
|
||||||
- bind-utils
|
- bind-utils
|
||||||
- btrfs-progs
|
- btrfs-progs
|
||||||
- cloud-init
|
|
||||||
- cronie
|
- cronie
|
||||||
- dhcp-client
|
- dhcp-client
|
||||||
|
- duf
|
||||||
- efibootmgr
|
- efibootmgr
|
||||||
|
- entr
|
||||||
|
- fish
|
||||||
|
- fzf
|
||||||
- glibc-langpack-de
|
- glibc-langpack-de
|
||||||
- glibc-langpack-en
|
- glibc-langpack-en
|
||||||
- grub2
|
- grub2
|
||||||
- grub2-efi
|
- grub2-efi
|
||||||
|
- htop
|
||||||
|
- iperf3
|
||||||
- logrotate
|
- logrotate
|
||||||
- lrzsz
|
- lrzsz
|
||||||
- lvm2
|
- lvm2
|
||||||
@@ -161,43 +232,84 @@ fedora:
|
|||||||
- open-vm-tools
|
- open-vm-tools
|
||||||
- polkit
|
- polkit
|
||||||
- ppp
|
- ppp
|
||||||
|
- ripgrep
|
||||||
- shim
|
- shim
|
||||||
- telnet
|
- tmux
|
||||||
- vim-default-editor
|
- vim-default-editor
|
||||||
- wget
|
- wget
|
||||||
|
- zoxide
|
||||||
|
- zram-generator
|
||||||
- zstd
|
- zstd
|
||||||
|
|
||||||
rhel8:
|
rhel8:
|
||||||
- cloud-init
|
- bind-utils
|
||||||
- dhcp-client
|
- dhcp-client
|
||||||
- efibootmgr
|
- efibootmgr
|
||||||
|
- glibc-langpack-de
|
||||||
|
- glibc-langpack-en
|
||||||
- grub2
|
- grub2
|
||||||
- grub2-efi
|
- grub2-efi-x64
|
||||||
|
- grub2-tools-extra
|
||||||
- lrzsz
|
- lrzsz
|
||||||
- lvm2
|
- lvm2
|
||||||
|
- mtr
|
||||||
|
- ncurses-term
|
||||||
- nfs-utils
|
- nfs-utils
|
||||||
- open-vm-tools
|
- open-vm-tools
|
||||||
|
- policycoreutils-python-utils
|
||||||
|
- python39
|
||||||
- shim
|
- shim
|
||||||
- telnet
|
- tmux
|
||||||
|
- vim
|
||||||
- zstd
|
- zstd
|
||||||
|
|
||||||
rhel9:
|
rhel9:
|
||||||
- cloud-init
|
- bind-utils
|
||||||
- dhcp-client
|
- dhcp-client
|
||||||
- efibootmgr
|
- efibootmgr
|
||||||
|
- glibc-langpack-de
|
||||||
|
- glibc-langpack-en
|
||||||
- grub2
|
- grub2
|
||||||
- grub2-efi
|
- grub2-efi
|
||||||
|
- grub2-tools-extra
|
||||||
- lrzsz
|
- lrzsz
|
||||||
- lvm2
|
- lvm2
|
||||||
|
- mtr
|
||||||
|
- ncurses-term
|
||||||
- nfs-utils
|
- nfs-utils
|
||||||
- open-vm-tools
|
- open-vm-tools
|
||||||
|
- policycoreutils-python-utils
|
||||||
|
- python
|
||||||
- shim
|
- shim
|
||||||
- telnet
|
- tmux
|
||||||
|
- vim
|
||||||
|
- zram-generator
|
||||||
|
- zstd
|
||||||
|
|
||||||
|
rhel10:
|
||||||
|
- bind-utils
|
||||||
|
- efibootmgr
|
||||||
|
- glibc-langpack-de
|
||||||
|
- glibc-langpack-en
|
||||||
|
- grub2
|
||||||
|
- grub2-efi
|
||||||
|
- kernel
|
||||||
|
- lrzsz
|
||||||
|
- lvm2
|
||||||
|
- mtr
|
||||||
|
- ncurses-term
|
||||||
|
- nfs-utils
|
||||||
|
- open-vm-tools
|
||||||
|
- policycoreutils-python-utils
|
||||||
|
- python
|
||||||
|
- shim
|
||||||
|
- tmux
|
||||||
|
- vim
|
||||||
|
- zram-generator
|
||||||
- zstd
|
- zstd
|
||||||
|
|
||||||
rocky:
|
rocky:
|
||||||
- bind-utils
|
- bind-utils
|
||||||
- cloud-init
|
|
||||||
- dbus-daemon
|
- dbus-daemon
|
||||||
- dhcp-client
|
- dhcp-client
|
||||||
- efibootmgr
|
- efibootmgr
|
||||||
@@ -207,6 +319,7 @@ rocky:
|
|||||||
- grub2-efi
|
- grub2-efi
|
||||||
- lrzsz
|
- lrzsz
|
||||||
- lvm2
|
- lvm2
|
||||||
|
- mtr
|
||||||
- nc
|
- nc
|
||||||
- nfs-utils
|
- nfs-utils
|
||||||
- nfsv4-client-utils
|
- nfsv4-client-utils
|
||||||
@@ -214,9 +327,11 @@ rocky:
|
|||||||
- ppp
|
- ppp
|
||||||
- shim
|
- shim
|
||||||
- telnet
|
- telnet
|
||||||
|
- tmux
|
||||||
- util-linux-core
|
- util-linux-core
|
||||||
- vim
|
- vim
|
||||||
- wget
|
- wget
|
||||||
|
- zram-generator
|
||||||
- zstd
|
- zstd
|
||||||
|
|
||||||
ubuntu:
|
ubuntu:
|
||||||
@@ -236,31 +351,47 @@ ubuntu:
|
|||||||
extra:
|
extra:
|
||||||
- apparmor-utils
|
- apparmor-utils
|
||||||
- bash-completion
|
- bash-completion
|
||||||
|
- bat
|
||||||
- chrony
|
- chrony
|
||||||
- cloud-init
|
|
||||||
- curl
|
- curl
|
||||||
- dnsutils
|
- dnsutils
|
||||||
|
- duf
|
||||||
|
- entr
|
||||||
|
- eza
|
||||||
|
- fdupes
|
||||||
|
- fio
|
||||||
- firewalld
|
- firewalld
|
||||||
- fish
|
- fish
|
||||||
- htop
|
- htop
|
||||||
|
- jq
|
||||||
- libpam-pwquality
|
- libpam-pwquality
|
||||||
- logrotate
|
- logrotate
|
||||||
- lrzsz
|
- lrzsz
|
||||||
|
- mtr
|
||||||
- ncdu
|
- ncdu
|
||||||
|
- ncurses-term
|
||||||
- net-tools
|
- net-tools
|
||||||
- network-manager
|
- network-manager
|
||||||
- open-vm-tools
|
- open-vm-tools
|
||||||
- openssh-server
|
- openssh-server
|
||||||
- python-is-python3
|
- python-is-python3
|
||||||
- python3
|
- python3
|
||||||
|
- ripgrep
|
||||||
- rsync
|
- rsync
|
||||||
- screen
|
- screen
|
||||||
- software-properties-common
|
- software-properties-common
|
||||||
- sudo
|
- sudo
|
||||||
- syslog-ng
|
- syslog-ng
|
||||||
|
- systemd-zram-generator
|
||||||
- tcpd
|
- tcpd
|
||||||
|
- tldr
|
||||||
|
- tmux
|
||||||
|
- traceroute
|
||||||
|
- util-linux-extra
|
||||||
- vim
|
- vim
|
||||||
- wget
|
- wget
|
||||||
|
- yq
|
||||||
|
- zoxide
|
||||||
- zstd
|
- zstd
|
||||||
|
|
||||||
ubuntu-lts:
|
ubuntu-lts:
|
||||||
@@ -280,29 +411,45 @@ ubuntu-lts:
|
|||||||
extra:
|
extra:
|
||||||
- apparmor-utils
|
- apparmor-utils
|
||||||
- bash-completion
|
- bash-completion
|
||||||
|
- bat
|
||||||
- chrony
|
- chrony
|
||||||
- cloud-init
|
|
||||||
- curl
|
- curl
|
||||||
- dnsutils
|
- dnsutils
|
||||||
|
- duf
|
||||||
|
- entr
|
||||||
|
- eza
|
||||||
|
- fdupes
|
||||||
|
- fio
|
||||||
- firewalld
|
- firewalld
|
||||||
- fish
|
- fish
|
||||||
- htop
|
- htop
|
||||||
|
- jq
|
||||||
- libpam-pwquality
|
- libpam-pwquality
|
||||||
- logrotate
|
- logrotate
|
||||||
- lrzsz
|
- lrzsz
|
||||||
|
- mtr
|
||||||
- ncdu
|
- ncdu
|
||||||
|
- ncurses-term
|
||||||
- net-tools
|
- net-tools
|
||||||
- network-manager
|
- network-manager
|
||||||
- open-vm-tools
|
- open-vm-tools
|
||||||
- openssh-server
|
- openssh-server
|
||||||
- python-is-python3
|
- python-is-python3
|
||||||
- python3
|
- python3
|
||||||
|
- ripgrep
|
||||||
- rsync
|
- rsync
|
||||||
- screen
|
- screen
|
||||||
- software-properties-common
|
- software-properties-common
|
||||||
- sudo
|
- sudo
|
||||||
- syslog-ng
|
- syslog-ng
|
||||||
|
- systemd-zram-generator
|
||||||
- tcpd
|
- tcpd
|
||||||
|
- tldr
|
||||||
|
- tmux
|
||||||
|
- traceroute
|
||||||
|
- util-linux-extra
|
||||||
- vim
|
- vim
|
||||||
- wget
|
- wget
|
||||||
|
- yq
|
||||||
|
- zoxide
|
||||||
- zstd
|
- zstd
|
||||||
@@ -4,26 +4,27 @@
|
|||||||
- name: Disable Kernel Modules
|
- name: Disable Kernel Modules
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
dest: /mnt/etc/modprobe.d/cis.conf
|
dest: /mnt/etc/modprobe.d/cis.conf
|
||||||
mode: '0644'
|
mode: "0644"
|
||||||
content: |
|
content: |
|
||||||
CIS LVL 3 Restrictions
|
CIS LVL 3 Restrictions
|
||||||
install freevxfs /bin/true
|
install freevxfs /bin/false
|
||||||
install jffs2 /bin/true
|
install jffs2 /bin/false
|
||||||
install hfs /bin/true
|
install hfs /bin/false
|
||||||
install hfsplus /bin/true
|
install hfsplus /bin/false
|
||||||
install squashfs /bin/true
|
install cramfs /bin/false
|
||||||
install udf /bin/true
|
install squashfs /bin/false
|
||||||
install usb-storage /bin/true
|
install udf /bin/false
|
||||||
|
install usb-storage /bin/false
|
||||||
|
|
||||||
install dccp /bin/true
|
install dccp /bin/false
|
||||||
install sctp /bin/true
|
install sctp /bin/false
|
||||||
install rds /bin/true
|
install rds /bin/false
|
||||||
install tipc /bin/true
|
install tipc /bin/false
|
||||||
|
|
||||||
- name: Create USB Rules
|
- name: Create USB Rules
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
dest: /mnt/etc/udev/rules.d/10-cis_usb_devices.sh
|
dest: /mnt/etc/udev/rules.d/10-cis_usb_devices.sh
|
||||||
mode: '0644'
|
mode: "0644"
|
||||||
content: |
|
content: |
|
||||||
By default, disable all.
|
By default, disable all.
|
||||||
ACTION=="add", SUBSYSTEMS=="usb", TEST=="authorized_default", ATTR{authorized_default}="0"
|
ACTION=="add", SUBSYSTEMS=="usb", TEST=="authorized_default", ATTR{authorized_default}="0"
|
||||||
@@ -40,14 +41,23 @@
|
|||||||
- name: Create a consolidated sysctl configuration file
|
- name: Create a consolidated sysctl configuration file
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
dest: /mnt/etc/sysctl.d/10-cis.conf
|
dest: /mnt/etc/sysctl.d/10-cis.conf
|
||||||
mode: '0644'
|
mode: "0644"
|
||||||
content: |
|
content: |
|
||||||
## CIS Sysctl configurations
|
## CIS Sysctl configurations
|
||||||
|
kernel.yama.ptrace_scope=1
|
||||||
|
kernel.randomize_va_space=2
|
||||||
|
|
||||||
|
# Network
|
||||||
|
net.ipv4.ip_forward=0
|
||||||
|
net.ipv4.tcp_syncookies=1
|
||||||
|
net.ipv4.icmp_echo_ignore_broadcasts=1
|
||||||
|
net.ipv4.icmp_ignore_bogus_error_responses=1
|
||||||
net.ipv4.conf.all.log_martians = 1
|
net.ipv4.conf.all.log_martians = 1
|
||||||
net.ipv4.conf.all.rp_filter = 1
|
net.ipv4.conf.all.rp_filter = 1
|
||||||
net.ipv4.conf.all.secure_redirects = 0
|
net.ipv4.conf.all.secure_redirects = 0
|
||||||
net.ipv4.conf.all.send_redirects = 0
|
net.ipv4.conf.all.send_redirects = 0
|
||||||
net.ipv4.conf.all.accept_redirects = 0
|
net.ipv4.conf.all.accept_redirects = 0
|
||||||
|
net.ipv4.conf.all.accept_source_route=0
|
||||||
net.ipv4.conf.default.log_martians = 1
|
net.ipv4.conf.default.log_martians = 1
|
||||||
net.ipv4.conf.default.rp_filter = 1
|
net.ipv4.conf.default.rp_filter = 1
|
||||||
net.ipv4.conf.default.secure_redirects = 0
|
net.ipv4.conf.default.secure_redirects = 0
|
||||||
@@ -69,6 +79,32 @@
|
|||||||
# - { regexp: '^PASS_MIN_DAYS.*', replace: 'PASS_MIN_DAYS 7' }
|
# - { regexp: '^PASS_MIN_DAYS.*', replace: 'PASS_MIN_DAYS 7' }
|
||||||
# - { regexp: '^UMASK.*', replace: 'UMASK 027' }
|
# - { regexp: '^UMASK.*', replace: 'UMASK 027' }
|
||||||
|
|
||||||
|
- name: Ensure the Default UMASK is Set Correctly
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: "/mnt/etc/profile"
|
||||||
|
regexp: "^(\\s*)umask\\s+\\d+"
|
||||||
|
line: "umask 027"
|
||||||
|
|
||||||
|
- name: Prevent Login to Accounts With Empty Password
|
||||||
|
ansible.builtin.replace:
|
||||||
|
dest: "{{ item }}"
|
||||||
|
regexp: "nullok"
|
||||||
|
loop:
|
||||||
|
- /mnt/etc/pam.d/system-auth
|
||||||
|
- /mnt/etc/pam.d/password-auth
|
||||||
|
|
||||||
|
- name: Configure System Cryptography Policy
|
||||||
|
when: os in ["almalinux", "rhel9", "rhel10", "rocky"]
|
||||||
|
ansible.builtin.command: arch-chroot /mnt /usr/bin/update-crypto-policies --set DEFAULT:NO-SHA1
|
||||||
|
register: crypto_policy_result
|
||||||
|
changed_when: "'Setting system-wide crypto-policies to' in crypto_policy_result.stdout"
|
||||||
|
|
||||||
|
- name: Mask Systemd Services
|
||||||
|
ansible.builtin.command: >
|
||||||
|
arch-chroot /mnt systemctl mask nftables bluetooth rpcbind
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Ensure files exist
|
- name: Ensure files exist
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ item }}"
|
path: "{{ item }}"
|
||||||
@@ -80,6 +116,15 @@
|
|||||||
- /mnt/etc/hosts.allow
|
- /mnt/etc/hosts.allow
|
||||||
- /mnt/etc/hosts.deny
|
- /mnt/etc/hosts.deny
|
||||||
|
|
||||||
|
- name: Ensure files do not exist
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ item }}"
|
||||||
|
state: touch
|
||||||
|
mode: "0600"
|
||||||
|
loop:
|
||||||
|
- /mnt/etc/at.deny
|
||||||
|
- /mnt/etc/cron.deny
|
||||||
|
|
||||||
- name: Add Security related lines into config files
|
- name: Add Security related lines into config files
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: "{{ item.path }}"
|
path: "{{ item.path }}"
|
||||||
@@ -91,18 +136,39 @@
|
|||||||
- { path: /mnt/etc/security/pwquality.conf, content: ucredit = -1 }
|
- { path: /mnt/etc/security/pwquality.conf, content: ucredit = -1 }
|
||||||
- { path: /mnt/etc/security/pwquality.conf, content: ocredit = -1 }
|
- { path: /mnt/etc/security/pwquality.conf, content: ocredit = -1 }
|
||||||
- { path: /mnt/etc/security/pwquality.conf, content: lcredit = -1 }
|
- { path: /mnt/etc/security/pwquality.conf, content: lcredit = -1 }
|
||||||
- { path: '/mnt/etc/{{ "bashrc" if os in ["almalinux", "fedora", "rocky"] else "bash.bashrc" }}', content: umask 077 }
|
- {
|
||||||
- { path: '/mnt/etc/{{ "bashrc" if os in ["almalinux", "fedora", "rocky"] else "bash.bashrc" }}', content: export TMOUT=3000 }
|
path: '/mnt/etc/{{ "bashrc" if os in ["almalinux", "fedora", "rhel8", "rhel9", "rhel10", "rocky"] else "bash.bashrc" }}',
|
||||||
- { path: '/mnt/{{ "usr/lib/systemd/journald.conf" if os == "fedora" else "etc/systemd/journald.conf" }}', content: Storage=persistent }
|
content: umask 077,
|
||||||
- { path: /mnt/etc/sudoers, content: Defaults logfile="/var/log/sudo.log" }
|
}
|
||||||
|
- {
|
||||||
|
path: '/mnt/etc/{{ "bashrc" if os in ["almalinux", "fedora", "rhel8", "rhel9", "rhel10", "rocky"] else "bash.bashrc" }}',
|
||||||
|
content: export TMOUT=3000,
|
||||||
|
}
|
||||||
|
- {
|
||||||
|
path: '/mnt/{{ "usr/lib/systemd/journald.conf" if os == "fedora" else "etc/systemd/journald.conf" }}',
|
||||||
|
content: Storage=persistent,
|
||||||
|
}
|
||||||
|
- {
|
||||||
|
path: /mnt/etc/sudoers,
|
||||||
|
content: Defaults logfile="/var/log/sudo.log",
|
||||||
|
}
|
||||||
- { path: /mnt/etc/pam.d/su, content: auth required pam_wheel.so }
|
- { path: /mnt/etc/pam.d/su, content: auth required pam_wheel.so }
|
||||||
- { path: '/mnt/etc/{{ "pam.d/common-auth" if os in ["debian11", "debian12", "ubuntu", "ubuntu-lts"]
|
- {
|
||||||
|
path:
|
||||||
|
'/mnt/etc/{{ "pam.d/common-auth" if os in ["debian11", "debian12", "ubuntu", "ubuntu-lts"]
|
||||||
else "authselect/system-auth" if os == "fedora" else "pam.d/system-auth" }}',
|
else "authselect/system-auth" if os == "fedora" else "pam.d/system-auth" }}',
|
||||||
content: auth required pam_faillock.so onerr=fail audit silent deny=5 unlock_time=900 }
|
content: auth required pam_faillock.so onerr=fail audit silent deny=5 unlock_time=900,
|
||||||
- { path: '/mnt/etc/{{ "pam.d/common-account" if os in ["debian11", "debian12", "ubuntu", "ubuntu-lts"] else "authselect/system-auth"
|
}
|
||||||
if os == "fedora" else "pam.d/system-auth" }}', content: account required pam_faillock.so }
|
- {
|
||||||
- { path: '/mnt/etc/pam.d/{{ "common-password" if os in ["debian11", "debian12", "ubuntu", "ubuntu-lts"] else "passwd" }}',
|
path:
|
||||||
content: "password [success=1 default=ignore] pam_unix.so obscure sha512 remember=5" }
|
'/mnt/etc/{{ "pam.d/common-account" if os in ["debian11", "debian12", "ubuntu", "ubuntu-lts"] else "authselect/system-auth"
|
||||||
|
if os == "fedora" else "pam.d/system-auth" }}',
|
||||||
|
content: account required pam_faillock.so,
|
||||||
|
}
|
||||||
|
- {
|
||||||
|
path: '/mnt/etc/pam.d/{{ "common-password" if os in ["debian11", "debian12", "ubuntu", "ubuntu-lts"] else "passwd" }}',
|
||||||
|
content: "password [success=1 default=ignore] pam_unix.so obscure sha512 remember=5",
|
||||||
|
}
|
||||||
- { path: /mnt/etc/hosts.deny, content: "ALL: ALL" }
|
- { path: /mnt/etc/hosts.deny, content: "ALL: ALL" }
|
||||||
- { path: /mnt/etc/hosts.allow, content: "sshd: ALL" }
|
- { path: /mnt/etc/hosts.allow, content: "sshd: ALL" }
|
||||||
|
|
||||||
@@ -112,18 +178,21 @@
|
|||||||
owner: "{{ item.owner | default(omit) }}"
|
owner: "{{ item.owner | default(omit) }}"
|
||||||
group: "{{ item.group | default(omit) }}"
|
group: "{{ item.group | default(omit) }}"
|
||||||
mode: "{{ item.mode }}"
|
mode: "{{ item.mode }}"
|
||||||
loop:
|
loop: >
|
||||||
- { path: /mnt/etc/ssh/sshd_config, mode: "0600" }
|
{{ [
|
||||||
- { path: /mnt/etc/cron.hourly, mode: "0700" }
|
{ "path": "/mnt/etc/ssh/sshd_config", "mode": "0600" },
|
||||||
- { path: /mnt/etc/cron.daily, mode: "0700" }
|
{ "path": "/mnt/etc/cron.hourly", "mode": "0700" },
|
||||||
- { path: /mnt/etc/cron.weekly, mode: "0700" }
|
{ "path": "/mnt/etc/cron.daily", "mode": "0700" },
|
||||||
- { path: /mnt/etc/cron.monthly, mode: "0700" }
|
{ "path": "/mnt/etc/cron.weekly", "mode": "0700" },
|
||||||
- { path: /mnt/etc/cron.d, mode: "0700" }
|
{ "path": "/mnt/etc/cron.monthly", "mode": "0700" },
|
||||||
- { path: /mnt/etc/crontab, mode: "0600" }
|
{ "path": "/mnt/etc/cron.d", "mode": "0700" },
|
||||||
- { path: /mnt/etc/logrotate.conf, mode: "0644" }
|
{ "path": "/mnt/etc/crontab", "mode": "0600" },
|
||||||
- { path: /mnt/usr/sbin/pppd, mode: "754" }
|
{ "path": "/mnt/etc/logrotate.conf", "mode": "0644" },
|
||||||
- { path: '/mnt/usr/bin/{{ "fusermount3" if os in ["archlinux", "debian12", "fedora"] else "fusermount" }}', mode: "755" }
|
{ "path": "/mnt/usr/sbin/pppd", "mode": "0754" } if os not in ["rhel8", "rhel9", "rhel10"] else None,
|
||||||
- { path: '/mnt/usr/bin/{{ "write.ul" if os == "debian11" else "write" }}', mode: "755" }
|
{ "path": "/mnt/usr/bin/" + ("fusermount3" if os in ["almalinux", "archlinux", "debian12", "fedora", "rhel9", "rhel10", "rocky"]
|
||||||
|
else "fusermount"), "mode": "755" },
|
||||||
|
{ "path": "/mnt/usr/bin/" + ("write.ul" if os == "debian11" else "write"), "mode": "755" }
|
||||||
|
] | reject("none") }}
|
||||||
|
|
||||||
- name: Adjust SSHD config
|
- name: Adjust SSHD config
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
@@ -145,7 +214,6 @@
|
|||||||
- { option: PermitEmptyPasswords, value: "no" }
|
- { option: PermitEmptyPasswords, value: "no" }
|
||||||
- { option: KerberosAuthentication, value: "no" }
|
- { option: KerberosAuthentication, value: "no" }
|
||||||
- { option: GSSAPIAuthentication, value: "no" }
|
- { option: GSSAPIAuthentication, value: "no" }
|
||||||
- { option: GSSAPIKeyExchange, value: "no" }
|
|
||||||
- { option: AllowAgentForwarding, value: "no" }
|
- { option: AllowAgentForwarding, value: "no" }
|
||||||
- { option: AllowTcpForwarding, value: "no" }
|
- { option: AllowTcpForwarding, value: "no" }
|
||||||
- { option: ChallengeResponseAuthentication, value: "no" }
|
- { option: ChallengeResponseAuthentication, value: "no" }
|
||||||
@@ -153,7 +221,7 @@
|
|||||||
- { option: X11Forwarding, value: "no" }
|
- { option: X11Forwarding, value: "no" }
|
||||||
- { option: PermitUserEnvironment, value: "no" }
|
- { option: PermitUserEnvironment, value: "no" }
|
||||||
- { option: ClientAliveInterval, value: "300" }
|
- { option: ClientAliveInterval, value: "300" }
|
||||||
- { option: ClientAliveCountMax, value: "0" }
|
- { option: ClientAliveCountMax, value: "1" }
|
||||||
- { option: PermitTunnel, value: "no" }
|
- { option: PermitTunnel, value: "no" }
|
||||||
- { option: Banner, value: /etc/issue.net }
|
- { option: Banner, value: /etc/issue.net }
|
||||||
|
|
||||||
@@ -167,14 +235,10 @@
|
|||||||
|
|
||||||
### Ciphers and keying ###
|
### Ciphers and keying ###
|
||||||
RekeyLimit 512M 6h
|
RekeyLimit 512M 6h
|
||||||
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,
|
KexAlgorithms mlkem768x25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256
|
||||||
diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,
|
Ciphers aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
|
||||||
diffie-hellman-group18-sha512,ecdh-sha2-nistp521,ecdh-sha2-nistp384,
|
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com
|
||||||
ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256
|
|
||||||
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,
|
|
||||||
aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
|
|
||||||
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,
|
|
||||||
hmac-sha2-512,hmac-sha2-256
|
|
||||||
###########################
|
###########################
|
||||||
|
|
||||||
AllowStreamLocalForwarding no
|
AllowStreamLocalForwarding no
|
||||||
|
|||||||
@@ -1,4 +1,33 @@
|
|||||||
---
|
---
|
||||||
|
- name: Unmount Disks
|
||||||
|
vars:
|
||||||
|
ansible_connection: ssh
|
||||||
|
block:
|
||||||
|
- name: Disable Swap
|
||||||
|
ansible.builtin.command: swapoff -a
|
||||||
|
register: swapoff_result
|
||||||
|
changed_when: swapoff_result.rc == 0
|
||||||
|
|
||||||
|
- name: Unmount /mnt if mounted
|
||||||
|
ansible.builtin.command: umount -R /mnt
|
||||||
|
register: unmount_result
|
||||||
|
changed_when: unmount_result.rc == 0
|
||||||
|
|
||||||
|
- name: Verify /mnt is no longer mounted
|
||||||
|
ansible.builtin.command: grep ' /mnt ' /proc/mounts
|
||||||
|
register: verify_unmount
|
||||||
|
retries: 5
|
||||||
|
delay: 5
|
||||||
|
until: verify_unmount.rc != 0
|
||||||
|
when: unmount_result.rc == 0
|
||||||
|
changed_when: false
|
||||||
|
failed_when: verify_unmount.rc not in [0, 1]
|
||||||
|
|
||||||
|
- name: Shutdown the VM
|
||||||
|
community.general.shutdown:
|
||||||
|
vars:
|
||||||
|
ansible_connection: ssh
|
||||||
|
|
||||||
- name: Setup Cleanup
|
- name: Setup Cleanup
|
||||||
when: hypervisor == "proxmox"
|
when: hypervisor == "proxmox"
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
@@ -15,12 +44,25 @@
|
|||||||
state: absent
|
state: absent
|
||||||
loop:
|
loop:
|
||||||
- ide0
|
- ide0
|
||||||
- ide1
|
- ide2
|
||||||
|
|
||||||
- name: Remove CD-ROM from VM in vCenter
|
- name: Start the VM
|
||||||
|
community.general.proxmox_kvm:
|
||||||
|
api_host: "{{ hypervisor_url }}"
|
||||||
|
api_user: "{{ hypervisor_username }}"
|
||||||
|
api_password: "{{ hypervisor_password }}"
|
||||||
|
node: "{{ hypervisor_node }}"
|
||||||
|
vmid: "{{ vm_id }}"
|
||||||
|
state: restarted
|
||||||
|
|
||||||
|
- name: Clean vCenter VM
|
||||||
when: hypervisor == "vmware"
|
when: hypervisor == "vmware"
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
ignore_errors: true
|
become: false
|
||||||
|
block:
|
||||||
|
- name: Remove CD-ROM from VM in vCenter
|
||||||
|
when: hypervisor == "vmware"
|
||||||
|
failed_when: false
|
||||||
community.vmware.vmware_guest:
|
community.vmware.vmware_guest:
|
||||||
hostname: "{{ hypervisor_url }}"
|
hostname: "{{ hypervisor_url }}"
|
||||||
username: "{{ hypervisor_username }}"
|
username: "{{ hypervisor_username }}"
|
||||||
@@ -35,17 +77,29 @@
|
|||||||
type: iso
|
type: iso
|
||||||
iso_path: "{{ boot_iso }}"
|
iso_path: "{{ boot_iso }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
- controller_number: 0
|
||||||
|
unit_number: 1
|
||||||
|
controller_type: sata
|
||||||
|
type: iso
|
||||||
|
iso_path: "{{ rhel_iso | default(omit) }}"
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: Start VM in vCenter
|
||||||
|
when: hypervisor == "vmware"
|
||||||
|
community.vmware.vmware_guest_powerstate:
|
||||||
|
hostname: "{{ hypervisor_url }}"
|
||||||
|
username: "{{ hypervisor_username }}"
|
||||||
|
password: "{{ hypervisor_password }}"
|
||||||
|
validate_certs: false
|
||||||
|
datacenter: "{{ hypervisor_cluster }}"
|
||||||
|
name: "{{ hostname }}"
|
||||||
|
state: powered-on
|
||||||
|
|
||||||
- name: Remove Archiso and cloud-init disks
|
- name: Remove Archiso and cloud-init disks
|
||||||
when: hypervisor == "libvirt"
|
when: hypervisor == "libvirt"
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
become: false
|
become: false
|
||||||
block:
|
block:
|
||||||
- name: Stop the VM
|
|
||||||
community.libvirt.virt:
|
|
||||||
name: "{{ hostname }}"
|
|
||||||
state: shutdown
|
|
||||||
|
|
||||||
- name: Remove cloud-init disk
|
- name: Remove cloud-init disk
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ vm_path | default('/var/lib/libvirt/images/') }}{{ hostname }}-cloudinit.iso"
|
path: "{{ vm_path | default('/var/lib/libvirt/images/') }}{{ hostname }}-cloudinit.iso"
|
||||||
@@ -63,7 +117,9 @@
|
|||||||
- name: Remove CD-ROM devices
|
- name: Remove CD-ROM devices
|
||||||
when: cdrom_devices.stdout_lines | length > 0
|
when: cdrom_devices.stdout_lines | length > 0
|
||||||
ansible.builtin.command: virsh --connect qemu:///system detach-disk {{ hostname }} {{ item }} --persistent
|
ansible.builtin.command: virsh --connect qemu:///system detach-disk {{ hostname }} {{ item }} --persistent
|
||||||
with_items: "{{ cdrom_devices.stdout_lines }}"
|
with_items: "{{ cdrom_devices.stdout_lines | select('ne', 'sdc') | list }}"
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Start the VM
|
- name: Start the VM
|
||||||
community.libvirt.virt:
|
community.libvirt.virt:
|
||||||
|
|||||||
@@ -3,6 +3,33 @@
|
|||||||
block:
|
block:
|
||||||
- name: Generate fstab
|
- name: Generate fstab
|
||||||
ansible.builtin.shell: genfstab -LU /mnt > /mnt/etc/fstab
|
ansible.builtin.shell: genfstab -LU /mnt > /mnt/etc/fstab
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Remove depricated attr2 and disable large extent
|
||||||
|
when: os in ["almalinux", "rhel8", "rhel9", "rhel10", "rocky"] and filesystem == "xfs"
|
||||||
|
ansible.builtin.replace:
|
||||||
|
path: /mnt/etc/fstab
|
||||||
|
regexp: "(xfs.*?)(attr2)"
|
||||||
|
replace: '\1allocsize=64m'
|
||||||
|
|
||||||
|
- name: Replace ISO UUID entry with /dev/sr0 in fstab
|
||||||
|
when: os in ["rhel8", "rhel9", "rhel10"]
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: /mnt/etc/fstab
|
||||||
|
regexp: '^.*\/dvd.*$'
|
||||||
|
line:
|
||||||
|
"{{ '/usr/local/install/redhat/rhel.iso /usr/local/install/redhat/dvd iso9660 loop,nofail 0 0' if hypervisor == 'vmware'
|
||||||
|
else '/dev/sr0 /usr/local/install/redhat/dvd iso9660 ro,relatime,nojoliet,check=s,map=n,nofail 0 0' }}"
|
||||||
|
state: present
|
||||||
|
backrefs: true
|
||||||
|
|
||||||
|
- name: Write image from RHEL ISO to the target machine
|
||||||
|
when: os in ["rhel8", "rhel9", "rhel10"] and hypervisor == 'vmware'
|
||||||
|
ansible.builtin.command: dd if=/dev/sr1 of=/mnt/usr/local/install/redhat/rhel.iso bs=4M
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Append TempFS to fstab
|
- name: Append TempFS to fstab
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /mnt/etc/fstab
|
path: /mnt/etc/fstab
|
||||||
@@ -13,10 +40,12 @@
|
|||||||
- "# TempFS"
|
- "# TempFS"
|
||||||
- tmpfs /tmp tmpfs defaults,nosuid,nodev,noexec 0 0
|
- tmpfs /tmp tmpfs defaults,nosuid,nodev,noexec 0 0
|
||||||
- tmpfs /var/tmp tmpfs defaults,nosuid,nodev,noexec 0 0
|
- tmpfs /var/tmp tmpfs defaults,nosuid,nodev,noexec 0 0
|
||||||
- tmpfs /dev/shm tmpfs defaults,noexec 0 0
|
- tmpfs /dev/shm tmpfs defaults,nosuid,nodev,noexec 0 0
|
||||||
|
|
||||||
- name: Set local timezone
|
- name: Set local timezone
|
||||||
ansible.builtin.command: "{{ item }}"
|
ansible.builtin.command: "{{ item }}"
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
with_items:
|
with_items:
|
||||||
- systemctl daemon-reload
|
- systemctl daemon-reload
|
||||||
- arch-chroot /mnt ln -sf /usr/share/zoneinfo/Europe/Vienna /etc/localtime
|
- arch-chroot /mnt ln -sf /usr/share/zoneinfo/Europe/Vienna /etc/localtime
|
||||||
@@ -24,7 +53,7 @@
|
|||||||
- name: Setup locales
|
- name: Setup locales
|
||||||
block:
|
block:
|
||||||
- name: Configure locale.gen
|
- name: Configure locale.gen
|
||||||
when: os | lower not in ['almalinux', 'fedora', 'rhel8', 'rhel9', 'rocky']
|
when: os | lower not in ['almalinux', 'fedora', 'rhel8', 'rhel9', 'rhel10', 'rocky']
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
dest: /mnt/etc/locale.gen
|
dest: /mnt/etc/locale.gen
|
||||||
regexp: "{{ item.regex }}"
|
regexp: "{{ item.regex }}"
|
||||||
@@ -32,32 +61,35 @@
|
|||||||
loop:
|
loop:
|
||||||
- { regex: en_US\.UTF-8 UTF-8, line: en_US.UTF-8 UTF-8 }
|
- { regex: en_US\.UTF-8 UTF-8, line: en_US.UTF-8 UTF-8 }
|
||||||
|
|
||||||
- name: Generate locales\
|
- name: Generate locales
|
||||||
when: os | lower not in ['almalinux', 'fedora', 'rhel8', 'rhel9', 'rocky']
|
when: os | lower not in ['almalinux', 'fedora', 'rhel8', 'rhel9', 'rhel10', 'rocky']
|
||||||
ansible.builtin.command: arch-chroot /mnt /usr/sbin/locale-gen
|
ansible.builtin.command: arch-chroot /mnt /usr/sbin/locale-gen
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Set hostname
|
- name: Set hostname
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
content: "{{ hostname }}"
|
content: "{{ hostname }}{% if vm_dns_search is defined and vm_dns_search | length %}.{{ vm_dns_search }}{% endif %}"
|
||||||
dest: /mnt/etc/hostname
|
dest: /mnt/etc/hostname
|
||||||
mode: '0644'
|
mode: "0644"
|
||||||
|
|
||||||
- name: Add host entry to /etc/hosts
|
- name: Add host entry to /etc/hosts
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /mnt/etc/hosts
|
path: /mnt/etc/hosts
|
||||||
line: "{{ ansible_host }} {{ hostname }}"
|
line: "{{ ansible_host }} {{ hostname }}{% if vm_dns_search is defined and vm_dns_search | length %} {{ hostname }}.{{ vm_dns_search }}{% endif %}"
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Create vconsole.conf
|
- name: Create vconsole.conf
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
content: KEYMAP=us
|
content: KEYMAP=us
|
||||||
dest: /mnt/etc/vconsole.conf
|
dest: /mnt/etc/vconsole.conf
|
||||||
mode: '0644'
|
mode: "0644"
|
||||||
|
|
||||||
- name: Create locale.conf
|
- name: Create locale.conf
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
content: LANG=en_US.UTF-8
|
content: LANG=en_US.UTF-8
|
||||||
dest: /mnt/etc/locale.conf
|
dest: /mnt/etc/locale.conf
|
||||||
mode: '0644'
|
mode: "0644"
|
||||||
|
|
||||||
- name: SSH permit Password
|
- name: SSH permit Password
|
||||||
ansible.builtin.replace:
|
ansible.builtin.replace:
|
||||||
@@ -65,13 +97,28 @@
|
|||||||
regexp: "#PasswordAuthentication yes"
|
regexp: "#PasswordAuthentication yes"
|
||||||
replace: PasswordAuthentication yes
|
replace: PasswordAuthentication yes
|
||||||
|
|
||||||
|
- name: SSH permit root login
|
||||||
|
ansible.builtin.replace:
|
||||||
|
path: /mnt/etc/ssh/sshd_config
|
||||||
|
regexp: "^#?PermitRootLogin.*"
|
||||||
|
replace: "PermitRootLogin yes"
|
||||||
|
|
||||||
- name: Enable Systemd Services
|
- name: Enable Systemd Services
|
||||||
block:
|
ansible.builtin.command: >
|
||||||
- name: Enable sshd
|
arch-chroot /mnt systemctl enable NetworkManager
|
||||||
when: os | lower == "archlinux"
|
{{
|
||||||
ansible.builtin.command: arch-chroot /mnt systemctl enable sshd logrotate systemd-resolved systemd-timesyncd NetworkManager
|
' ssh' if os | lower in ['ubuntu', 'ubuntu-lts'] else
|
||||||
|
(' sshd' if os | lower not in ['debian11', 'debian12', 'debian13'] else '')
|
||||||
|
}}
|
||||||
|
{{
|
||||||
|
'logrotate systemd-resolved systemd-timesyncd systemd-networkd'
|
||||||
|
if os | lower == 'archlinux' else ''
|
||||||
|
}}
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Configure grub
|
- name: Configure grub
|
||||||
when: os | lower not in ['almalinux', 'fedora', 'rhel8', 'rhel9', 'rocky']
|
when: os | lower not in ['almalinux', 'fedora', 'rhel8', 'rhel9', 'rhel10', 'rocky']
|
||||||
block:
|
block:
|
||||||
- name: Add commandline information to grub config
|
- name: Add commandline information to grub config
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
@@ -89,78 +136,156 @@
|
|||||||
block:
|
block:
|
||||||
- name: Install Bootloader
|
- name: Install Bootloader
|
||||||
ansible.builtin.command: arch-chroot /mnt
|
ansible.builtin.command: arch-chroot /mnt
|
||||||
{% if os | lower not in ["archlinux", "debian11", "debian12", "ubuntu", "ubuntu-lts"] %} /usr/sbin/efibootmgr
|
{% if os | lower not in ["archlinux", "debian11", "debian12", "debian13", "ubuntu", "ubuntu-lts"] %} /usr/sbin/efibootmgr
|
||||||
-c -L '{{ os }}' -d "{{ install_drive }}" -p 1 -l '\efi\EFI\{{ os }}\shimx64.efi'
|
-c -L '{{ os }}' -d "{{ install_drive }}" -p 1
|
||||||
|
-l '\efi\EFI\{% if os | lower in ["rhel8", "rhel9", "rhel10"] %}redhat{% else %}{{ os | lower }}{% endif %}\shimx64.efi'
|
||||||
{% else %}/usr/sbin/grub-install --target=x86_64-efi --efi-directory={{ "/boot/efi" if os | lower in ["ubuntu", "ubuntu-lts"] else "/boot" }}
|
{% else %}/usr/sbin/grub-install --target=x86_64-efi --efi-directory={{ "/boot/efi" if os | lower in ["ubuntu", "ubuntu-lts"] else "/boot" }}
|
||||||
--bootloader-id={{ "ubuntu" if os | lower in ["ubuntu", "ubuntu-lts"] else os }}
|
--bootloader-id={{ "ubuntu" if os | lower in ["ubuntu", "ubuntu-lts"] else os }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
- name: Generate grub config
|
changed_when: result.rc == 0
|
||||||
ansible.builtin.command: arch-chroot /mnt
|
register: result
|
||||||
{% if os | lower not in ["archlinux", "debian11", "debian12", "ubuntu", "ubuntu-lts"] %} /usr/sbin/grub2-mkconfig
|
|
||||||
-o /boot/efi/EFI/{{ os }}/grub.cfg
|
- name: Ensure lvm2 for non btrfs filesystems
|
||||||
{% else %}/usr/sbin/grub-mkconfig -o
|
when: os | lower == "archlinux" and filesystem != "btrfs"
|
||||||
{{ "/boot/efi/EFI/ubuntu/grub.cfg" if os | lower in ["ubuntu", "ubuntu-lts"] else "/boot/grub/grub.cfg" }}
|
ansible.builtin.lineinfile:
|
||||||
{% endif %}
|
path: /mnt/etc/mkinitcpio.conf
|
||||||
|
regexp: "^(HOOKS=.*block)(?!.*lvm2)(.*)"
|
||||||
|
line: '\1 lvm2\2'
|
||||||
|
backrefs: true
|
||||||
|
|
||||||
- name: Regenerate initramfs
|
- name: Regenerate initramfs
|
||||||
when: os | lower not in ["debian11", "debian12", "ubuntu", "ubuntu-lts"]
|
when: os | lower not in ["debian11", "debian12", "debian13", "ubuntu", "ubuntu-lts"]
|
||||||
ansible.builtin.command: arch-chroot /mnt
|
ansible.builtin.command: arch-chroot /mnt
|
||||||
{% if os | lower == "archlinux" %} /usr/sbin/mkinitcpio -P
|
{% if os | lower == "archlinux" %} /usr/sbin/mkinitcpio -P
|
||||||
{% elif os | lower not in ["debian11", "debian12", "ubuntu", "ubuntu-lts", "archlinux"] %} /usr/bin/dracut --regenerate-all --force
|
{% else %} /usr/bin/dracut --regenerate-all --force
|
||||||
{% else %} echo "Skipping initramfs regeneration"
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Generate grub config
|
||||||
|
ansible.builtin.command: arch-chroot /mnt
|
||||||
|
{% if os | lower not in ["archlinux", "debian11", "debian12", "debian13", "ubuntu", "ubuntu-lts"] %}
|
||||||
|
/usr/sbin/grub2-mkconfig -o /boot/efi/EFI/{% if os | lower in ["rhel8", "rhel9", "rhel10"] %}redhat{% else %}{{ os | lower }}{% endif %}/grub.cfg
|
||||||
|
{% else %}
|
||||||
|
/usr/sbin/grub-mkconfig -o {{ "/boot/efi/EFI/ubuntu/grub.cfg" if os | lower in ["ubuntu", "ubuntu-lts"] else "/boot/grub/grub.cfg" }}
|
||||||
|
{% endif %}
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Extra Configuration
|
- name: Extra Configuration
|
||||||
block:
|
block:
|
||||||
- name: Append lines to vimrc
|
- name: Append vim configurations to vimrc
|
||||||
ignore_errors: true
|
failed_when: false
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.blockinfile:
|
||||||
path: "{{ '/mnt/etc/vim/vimrc' if os | lower in ['debian11', 'debian12', 'ubuntu', 'ubuntu-lts'] else '/mnt/etc/vimrc' }}"
|
path:
|
||||||
line: "{{ item }}"
|
"{{ '/mnt/etc/vim/vimrc' if os | lower in ['debian11', 'debian12', 'debian13', 'ubuntu', 'ubuntu-lts']
|
||||||
|
else '/mnt/etc/vimrc' }}"
|
||||||
|
block: |
|
||||||
|
set encoding=utf-8
|
||||||
|
set number
|
||||||
|
set autoindent
|
||||||
|
set smartindent
|
||||||
|
set mouse=a
|
||||||
insertafter: EOF
|
insertafter: EOF
|
||||||
with_items:
|
marker: ""
|
||||||
- set encoding=utf-8
|
|
||||||
- set number
|
|
||||||
- set autoindent
|
|
||||||
- set smartindent
|
|
||||||
- set mouse=a
|
|
||||||
|
|
||||||
- name: Copy FirstRun Script
|
- name: Add memory tuning parameters
|
||||||
when: os | lower != "archlinux"
|
ansible.builtin.blockinfile:
|
||||||
ansible.builtin.template:
|
path: /mnt/etc/sysctl.d/90-memory.conf
|
||||||
src: firstrun.sh.j2
|
create: true
|
||||||
dest: /mnt/root/firstrun.sh
|
block: |
|
||||||
mode: "0755"
|
vm.swappiness=10
|
||||||
|
vm.vfs_cache_pressure=50
|
||||||
|
vm.dirty_background_ratio=1
|
||||||
|
vm.dirty_ratio=10
|
||||||
|
vm.page-cluster=10
|
||||||
|
marker: ""
|
||||||
|
mode: "0644"
|
||||||
|
|
||||||
|
- name: Create zram config
|
||||||
|
when: os not in ['debian11', 'rhel8']
|
||||||
|
ansible.builtin.copy:
|
||||||
|
dest: /mnt/etc/systemd/zram-generator.conf
|
||||||
|
content: |
|
||||||
|
[zram0]
|
||||||
|
zram-size = ram / 2
|
||||||
|
compression-algorithm = zstd
|
||||||
|
swap-priority = 100
|
||||||
|
fs-type = swap
|
||||||
|
mode: "0644"
|
||||||
|
|
||||||
- name: Copy Custom Shell config
|
- name: Copy Custom Shell config
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: custom.sh.j2
|
src: custom.sh.j2
|
||||||
dest: /mnt/etc/profile.d/custom.sh
|
dest: /mnt/etc/profile.d/custom.sh
|
||||||
mode: '0644'
|
mode: "0644"
|
||||||
|
|
||||||
|
- name: Create login banner
|
||||||
|
ansible.builtin.copy:
|
||||||
|
dest: "{{ item }}"
|
||||||
|
content: |
|
||||||
|
**************************************************************
|
||||||
|
* WARNING: Unauthorized access to this system is prohibited. *
|
||||||
|
* All activities are monitored and logged. *
|
||||||
|
* Disconnect immediately if you are not an authorized user. *
|
||||||
|
**************************************************************
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
loop:
|
||||||
|
- /mnt/etc/issue
|
||||||
|
- /etc/issue.net
|
||||||
|
|
||||||
|
- name: Remove motd files
|
||||||
|
when: os | lower in ["rhel8", "rhel9", "rhel10"]
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ item }}"
|
||||||
|
state: absent
|
||||||
|
loop:
|
||||||
|
- /etc/motd.d/cockpit
|
||||||
|
- /etc/motd.d/insights-client
|
||||||
|
|
||||||
- name: Setup Network
|
- name: Setup Network
|
||||||
block:
|
block:
|
||||||
- name: Generate UUID for Network Profile
|
- name: Generate UUID for Network Profile
|
||||||
ansible.builtin.command: uuidgen
|
ansible.builtin.command: uuidgen
|
||||||
|
changed_when: net_uuid.rc == 0
|
||||||
register: net_uuid
|
register: net_uuid
|
||||||
|
|
||||||
- name: Retrieve Network Interface Name
|
- name: Retrieve Network Interface Name
|
||||||
ansible.builtin.shell: set -o pipefail && ip r | awk 'NR==1 {print $5}'
|
ansible.builtin.shell: set -o pipefail && ip r | awk 'NR==1 {print $5}'
|
||||||
|
changed_when: net_inf.rc == 0
|
||||||
register: net_inf
|
register: net_inf
|
||||||
|
|
||||||
|
- name: Register MAC Address of the Network Interface
|
||||||
|
ansible.builtin.shell: set -o pipefail && ip link show "{{ net_inf.stdout }}" | awk '/link\/ether/ {print $2}' | tr '[:lower:]' '[:upper:]'
|
||||||
|
register: net_mac
|
||||||
|
changed_when: net_mac.rc == 0
|
||||||
|
|
||||||
- name: Copy NetworkManager keyfile
|
- name: Copy NetworkManager keyfile
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: network.j2
|
src: network.j2
|
||||||
dest: /mnt/etc/NetworkManager/system-connections/LAN.nmconnection
|
dest: /mnt/etc/NetworkManager/system-connections/LAN.nmconnection
|
||||||
mode: "0600"
|
mode: "0600"
|
||||||
|
|
||||||
|
- name: Fix Ubuntu unmanaged devices
|
||||||
|
when: os | lower in ["ubuntu", "ubuntu-lts"]
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /mnt/etc/NetworkManager/conf.d/10-globally-managed-devices.conf
|
||||||
|
state: touch
|
||||||
|
mode: "0644"
|
||||||
|
|
||||||
- name: Setup user account
|
- name: Setup user account
|
||||||
block:
|
block:
|
||||||
- name: Create user account
|
- name: Create user account
|
||||||
ansible.builtin.command: "{{ item }}"
|
ansible.builtin.command: "{{ item }}"
|
||||||
with_items:
|
with_items:
|
||||||
- arch-chroot /mnt /usr/sbin/useradd --create-home --user-group --groups
|
- arch-chroot /mnt /usr/sbin/useradd --create-home --user-group --groups
|
||||||
{{ "sudo" if os | lower in ["debian11", "debian12", "ubuntu", "ubuntu-lts"] else "wheel" }}
|
{{ "sudo" if os | lower in ["debian11", "debian12", "debian13", "ubuntu", "ubuntu-lts"] else "wheel" }}
|
||||||
{{ user_name }} --password {{ user_password | password_hash('sha512') }} --shell /bin/bash
|
{{ user_name }} --password {{ user_password | password_hash('sha512') }} --shell /bin/bash
|
||||||
- arch-chroot /mnt /usr/sbin/usermod --password '{{ root_password | password_hash('sha512') }}' root --shell /bin/bash
|
- arch-chroot /mnt /usr/sbin/usermod --password '{{ root_password | password_hash('sha512') }}' root --shell /bin/bash
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Add SSH public key to authorized_keys
|
- name: Add SSH public key to authorized_keys
|
||||||
when: user_public_key is defined
|
when: user_public_key is defined
|
||||||
@@ -174,18 +299,25 @@
|
|||||||
|
|
||||||
- name: Give sudo access to wheel group
|
- name: Give sudo access to wheel group
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
content: "{{ '%sudo ALL=(ALL) ALL' if os | lower in ['debian11', 'debian12', 'ubuntu', 'ubuntu-lts'] else '%wheel ALL=(ALL) ALL' }}"
|
content: "{{ '%sudo ALL=(ALL) ALL' if os | lower in ['debian11', 'debian12', 'debian13', 'ubuntu', 'ubuntu-lts'] else '%wheel ALL=(ALL) ALL' }}"
|
||||||
dest: /mnt/etc/sudoers.d/01-wheel
|
dest: /mnt/etc/sudoers.d/01-wheel
|
||||||
mode: "0440"
|
mode: "0440"
|
||||||
validate: /usr/sbin/visudo --check --file=%s
|
validate: /usr/sbin/visudo --check --file=%s
|
||||||
|
|
||||||
- name: Fix SELinux
|
- name: Fix SELinux
|
||||||
|
when: os | lower in ['almalinux', 'fedora', 'rhel8', 'rhel9', 'rhel10', 'rocky']
|
||||||
block:
|
block:
|
||||||
- name: Relabel the filesystem
|
- name: Fix SELinux by pre-labeling the filesystem before first boot
|
||||||
when: os | lower in ['almalinux', 'rhel8', 'rhel9', 'rocky']
|
when: os | lower in ['almalinux', 'rhel8', 'rhel9', 'rhel10', 'rocky'] and (selinux | default(true) | bool)
|
||||||
ansible.builtin.command: touch /mnt/.autorelabel
|
ansible.builtin.command: >
|
||||||
|
arch-chroot /mnt /sbin/setfiles -v -F
|
||||||
|
-e /dev -e /proc -e /sys -e /run
|
||||||
|
/etc/selinux/targeted/contexts/files/file_contexts /
|
||||||
|
register: setfiles_result
|
||||||
|
changed_when: setfiles_result.rc == 0
|
||||||
|
|
||||||
- name: Disable SELinux
|
- name: Disable SELinux
|
||||||
when: os | lower == "fedora"
|
when: os | lower == "fedora" or not (selinux | default(true) | bool)
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /mnt/etc/selinux/config
|
path: /mnt/etc/selinux/config
|
||||||
regexp: ^SELINUX=
|
regexp: ^SELINUX=
|
||||||
|
|||||||
@@ -10,3 +10,6 @@ PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
|
|||||||
# History Size
|
# History Size
|
||||||
HISTFILESIZE=
|
HISTFILESIZE=
|
||||||
HISTSIZE=
|
HISTSIZE=
|
||||||
|
|
||||||
|
# Enable vi mode
|
||||||
|
set -o vi
|
||||||
|
|||||||
@@ -2,17 +2,20 @@
|
|||||||
id=LAN
|
id=LAN
|
||||||
uuid={{ net_uuid.stdout }}
|
uuid={{ net_uuid.stdout }}
|
||||||
type=ethernet
|
type=ethernet
|
||||||
interface-name={{ net_inf.stdout }}
|
|
||||||
|
|
||||||
[ethernet]
|
[ethernet]
|
||||||
|
mac-address={{ net_mac.stdout }}
|
||||||
|
|
||||||
[ipv4]
|
[ipv4]
|
||||||
address={{ vm_ip }},{{ vm_gw }}
|
address={{ vm_ip }}/{{ vm_nms | default (24) }},{{ vm_gw }}
|
||||||
dns={{ vm_dns }}
|
dns={{ vm_dns }}
|
||||||
|
{% if vm_dns_search is defined %}
|
||||||
|
dns-search={{ vm_dns_search }}
|
||||||
|
{% endif %}
|
||||||
method=manual
|
method=manual
|
||||||
|
|
||||||
[ipv6]
|
[ipv6]
|
||||||
addr-gen-mode=default
|
addr-gen-mode=stable-privacy
|
||||||
method=disabled
|
method=disabled
|
||||||
|
|
||||||
[proxy]
|
[proxy]
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
block:
|
block:
|
||||||
- name: Wait for connection
|
- name: Wait for connection
|
||||||
ansible.builtin.wait_for_connection:
|
ansible.builtin.wait_for_connection:
|
||||||
timeout: 300
|
timeout: 60
|
||||||
delay: 5
|
delay: 5
|
||||||
|
|
||||||
- name: Gather facts
|
- name: Gather facts
|
||||||
@@ -20,19 +20,57 @@
|
|||||||
msg: This host is not booted from the Arch install media!
|
msg: This host is not booted from the Arch install media!
|
||||||
when: not archiso_stat.stat.exists
|
when: not archiso_stat.stat.exists
|
||||||
|
|
||||||
- name: Setect Interface
|
- name: Register Network Interface
|
||||||
when: hypervisor == "vmware"
|
when: hypervisor == "vmware"
|
||||||
ansible.builtin.shell: "set -o pipefail && ip l | awk -F': ' '!/lo/{print $2; exit}'"
|
ansible.builtin.shell: "set -o pipefail && ip l | awk -F': ' '!/lo/{print $2; exit}'"
|
||||||
|
changed_when: interface_name.rc == 0
|
||||||
register: interface_name
|
register: interface_name
|
||||||
|
|
||||||
- name: Set IP-Address
|
- name: Set IP-Address
|
||||||
when: hypervisor == "vmware"
|
when: hypervisor == "vmware"
|
||||||
ansible.builtin.command: ip addr replace {{ ansible_host }}/24 dev {{ interface_name.stdout }}
|
ansible.builtin.command: "ip addr replace {{ ansible_host }}/{{ vm_nms | default(24) }} dev {{ interface_name.stdout }}"
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Set Default Gateway
|
- name: Set Default Gateway
|
||||||
when: hypervisor == "vmware"
|
when: hypervisor == "vmware"
|
||||||
ansible.builtin.command: ip route replace default via {{ vm_gw }}
|
ansible.builtin.command: "ip route replace default via {{ vm_gw }}"
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Synchronize clock via NTP
|
- name: Synchronize clock via NTP
|
||||||
ansible.builtin.command: timedatectl set-ntp true
|
ansible.builtin.command: timedatectl set-ntp true
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Configure SSH for root login
|
||||||
|
when: hypervisor == "vmware" and (vmware_ssh is defined and vmware_ssh | bool)
|
||||||
|
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"
|
||||||
|
|
||||||
- name: Speed-up Bootstrap process
|
- name: Speed-up Bootstrap process
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /etc/pacman.conf
|
path: /etc/pacman.conf
|
||||||
@@ -51,25 +89,42 @@
|
|||||||
state: latest
|
state: latest
|
||||||
loop:
|
loop:
|
||||||
- { name: glibc }
|
- { name: glibc }
|
||||||
- { name: dnf, os: [almalinux, fedora, rhel9, rhel8, rocky] }
|
- { name: dnf, os: [almalinux, fedora, rhel8, rhel9, rhel10, rocky] }
|
||||||
- { name: debootstrap, os: [debian11, debian12, ubuntu, ubuntu-lts] }
|
- { name: debootstrap, os: [debian11, debian12, debian13, ubuntu, ubuntu-lts] }
|
||||||
- { name: debian-archive-keyring, os: [debian11, debian12] }
|
- { name: debian-archive-keyring, os: [debian11, debian12, debian13] }
|
||||||
- { name: ubuntu-keyring, os: [ubuntu, ubuntu-lts] }
|
- { name: ubuntu-keyring, os: [ubuntu, ubuntu-lts] }
|
||||||
when: "'os' not in item or os in item.os"
|
when: "'os' not in item or os in item.os"
|
||||||
retries: 4
|
retries: 4
|
||||||
delay: 15
|
delay: 15
|
||||||
|
|
||||||
|
- name: Prepare /iso mount and repository for RHEL-based systems
|
||||||
|
when: os | lower in ["rhel8", "rhel9", "rhel10"]
|
||||||
|
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/sr1' if hypervisor == 'vmware' else '/dev/sr2' }}"
|
||||||
|
path: /usr/local/install/redhat/dvd
|
||||||
|
fstype: iso9660
|
||||||
|
opts: "ro,loop"
|
||||||
|
state: mounted
|
||||||
|
|
||||||
- name: Configure RHEL Repos for installation
|
- name: Configure RHEL Repos for installation
|
||||||
when: os | lower in ["almalinux", "fedora", "rocky"]
|
when: os | lower in ["almalinux", "fedora", "rhel8", "rhel9", "rhel10", "rocky"]
|
||||||
block:
|
block:
|
||||||
- name: Create directories for repository files and RPM GPG keys
|
- name: Create directories for repository files and RPM GPG keys
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: /etc/yum.repos.d
|
path: /etc/yum.repos.d
|
||||||
state: directory
|
state: directory
|
||||||
mode: '0755'
|
mode: "0755"
|
||||||
|
|
||||||
- name: Create RHEL repository file
|
- name: Create RHEL repository file
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: "{{ os | lower }}.repo.j2"
|
src: "{{ os | lower }}.repo.j2"
|
||||||
dest: /etc/yum.repos.d/{{ os | lower }}.repo
|
dest: /etc/yum.repos.d/{{ os | lower }}.repo
|
||||||
mode: '0644'
|
mode: "0644"
|
||||||
|
|||||||
@@ -17,23 +17,37 @@
|
|||||||
|
|
||||||
- name: Enable quotas on Btrfs filesystem
|
- name: Enable quotas on Btrfs filesystem
|
||||||
ansible.builtin.command: btrfs quota enable /mnt
|
ansible.builtin.command: btrfs quota enable /mnt
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Make root subvolumes
|
- name: Make root subvolumes
|
||||||
when: cis | bool or item.subvol not in ['var_log', 'var_log_audit']
|
when: cis | bool or item.subvol not in ['var_log_audit']
|
||||||
ansible.builtin.command: btrfs su cr /mnt/{{ '@' if item.subvol == 'root' else '@' + item.subvol }}
|
ansible.builtin.command: btrfs su cr /mnt/{{ '@' if item.subvol == 'root' else '@' + item.subvol }}
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
loop:
|
loop:
|
||||||
- { subvol: root }
|
- { subvol: root }
|
||||||
|
- { subvol: swap }
|
||||||
- { subvol: home }
|
- { subvol: home }
|
||||||
- { subvol: var }
|
- { subvol: var }
|
||||||
- { subvol: var_log }
|
- { subvol: var_log }
|
||||||
- { subvol: var_log_audit }
|
- { subvol: var_log_audit }
|
||||||
|
|
||||||
- name: Set quotas for subvolumes
|
- name: Set quotas for subvolumes
|
||||||
when: cis | bool or item.subvol not in ['var_log', 'var_log_audit']
|
when: cis | bool or item.subvol not in ['var_log_audit']
|
||||||
ansible.builtin.command: btrfs qgroup limit {{ item.quota }} /mnt/{{ '@' if item.subvol == 'root' else '@' + item.subvol }}
|
ansible.builtin.command: btrfs qgroup limit {{ item.quota }} /mnt/{{ '@' if item.subvol == 'root' else '@' + item.subvol }}
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
loop:
|
loop:
|
||||||
- { subvol: home, quota: 2G }
|
- { subvol: home, quota: 2G }
|
||||||
|
|
||||||
|
- name: Create a Btrfs swap file
|
||||||
|
ansible.builtin.command: >-
|
||||||
|
btrfs filesystem mkswapfile --size {{ ((vm_memory | float / 1024 >= 16.0) | ternary((vm_memory
|
||||||
|
| float / 2048) | int, [vm_memory | float / 1024, 4.0] | max) | int) }}g --uuid clear /mnt/@swap/swapfile
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Unmount Partition
|
- name: Unmount Partition
|
||||||
ansible.posix.mount:
|
ansible.posix.mount:
|
||||||
path: /mnt
|
path: /mnt
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
- name: Create and format ext4 logical volumes
|
- name: Create and format ext4 logical volumes
|
||||||
when: cis | bool or item.lv not in ['var_log', 'var_log_audit']
|
when: cis | bool or item.lv not in ['home', 'var', 'var_log', 'var_log_audit']
|
||||||
community.general.filesystem:
|
community.general.filesystem:
|
||||||
dev: /dev/sys/{{ item.lv }}
|
dev: /dev/sys/{{ item.lv }}
|
||||||
fstype: ext4
|
fstype: ext4
|
||||||
@@ -13,8 +13,10 @@
|
|||||||
- { lv: var_log_audit }
|
- { lv: var_log_audit }
|
||||||
|
|
||||||
- name: Remove Unsupported features for older Systems
|
- name: Remove Unsupported features for older Systems
|
||||||
when: (os | lower in ['almalinux', 'debian11', 'rhel8', 'rhel9', 'rocky', 'ubuntu-lts']) and (cis | bool or item.lv not in ['var_log', 'var_log_audit'])
|
when: (os | lower in ['almalinux', 'debian11', 'rhel8', 'rhel9', 'rocky']) and (cis | bool or item.lv not in ['home', 'var', 'var_log', 'var_log_audit'])
|
||||||
ansible.builtin.command: tune2fs -O "^orphan_file,^metadata_csum_seed" "/dev/sys/{{ item.lv }}"
|
ansible.builtin.command: tune2fs -O "^orphan_file,^metadata_csum_seed" "/dev/sys/{{ item.lv }}"
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
loop:
|
loop:
|
||||||
- { lv: root }
|
- { lv: root }
|
||||||
- { lv: home }
|
- { lv: home }
|
||||||
|
|||||||
@@ -2,12 +2,16 @@
|
|||||||
- name: Partition install drive
|
- name: Partition install drive
|
||||||
block:
|
block:
|
||||||
- name: Prepare partitions
|
- name: Prepare partitions
|
||||||
ignore_errors: true
|
failed_when: false
|
||||||
ansible.builtin.command: "{{ item.cmd }}"
|
ansible.builtin.command: "{{ item.cmd }}"
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
loop:
|
loop:
|
||||||
- { cmd: umount -l /mnt }
|
- { cmd: umount -l /mnt }
|
||||||
- { cmd: vgremove -f sys }
|
- { cmd: vgremove -f sys }
|
||||||
- { cmd: 'find /dev -wholename "{{ install_drive }}*" -exec wipefs --force --all {} \;' }
|
- {
|
||||||
|
cmd: 'find /dev -wholename "{{ install_drive }}*" -exec wipefs --force --all {} \;',
|
||||||
|
}
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ item.cmd }}"
|
label: "{{ item.cmd }}"
|
||||||
|
|
||||||
@@ -34,18 +38,34 @@
|
|||||||
pvs: "{{ install_drive }}{{ main_partition_suffix }}"
|
pvs: "{{ install_drive }}{{ main_partition_suffix }}"
|
||||||
|
|
||||||
- name: Create LVM logical volumes
|
- name: Create LVM logical volumes
|
||||||
when: cis or (not cis and item.lv != 'var_log' and item.lv != 'var_log_audit')
|
when: cis | bool or item.lv not in ['home', 'var', 'var_log', 'var_log_audit']
|
||||||
community.general.lvol:
|
community.general.lvol:
|
||||||
vg: sys
|
vg: sys
|
||||||
lv: "{{ item.lv }}"
|
lv: "{{ item.lv }}"
|
||||||
size: "{{ item.size }}"
|
size: "{{ item.size }}"
|
||||||
state: present
|
state: present
|
||||||
loop:
|
loop:
|
||||||
- { lv: root, size: 12G }
|
- lv: root
|
||||||
- { lv: home, size: 2G }
|
size: >-
|
||||||
- { lv: var, size: 2G }
|
{{ [(((((vm_size | float) - 0.5 - ((cis | bool) | ternary(7.5, 0)) - (((vm_memory | float / 1024) > 16.0)
|
||||||
- { lv: var_log, size: 2G }
|
| ternary(((vm_memory | float / 2048) | int), (vm_memory | float / 1024)))) < 4)
|
||||||
- { lv: var_log_audit, size: 1.5G }
|
| ternary(4,((((vm_size | float) - 0.5 - ((cis | bool) | ternary(7.5, 0)) -
|
||||||
|
(((vm_memory | float / 1024) > 16.0)| ternary(((vm_memory | float / 2048) | int), (vm_memory | float / 1024)))) > 12)
|
||||||
|
| ternary(((vm_size | float) * 0.4) | round(0, 'ceil'),((vm_size | float) - 0.5 - ((cis | bool)
|
||||||
|
| ternary(7.5, 0)) - (((vm_memory | float / 1024) > 16.0)
|
||||||
|
| ternary(((vm_memory | float / 2048) | int), (vm_memory | float / 1024))))))))), 4 ] | max | string + 'G' }}
|
||||||
|
- lv: swap
|
||||||
|
size: >-
|
||||||
|
{{ ((((vm_size | float) - 0.5 - ((cis | bool) | ternary(7.5, 0))) - (((vm_memory | float / 1024) > 16.0)
|
||||||
|
| ternary(((vm_memory | float / 2048) | int), (vm_memory | float / 1024)))) < 4)
|
||||||
|
| ternary((((vm_size | float) - 0.5 - ((cis | bool) | ternary(7.5, 0))) - 4), (((vm_memory | float / 1024) > 16.0)
|
||||||
|
| ternary(((vm_memory | float / 2048) | int), (vm_memory | float / 1024)))) | string + 'G' }}
|
||||||
|
- lv: home
|
||||||
|
size: "{{ ([([(((vm_size | float) - 20) * 0.1), 2] | max), 20] | min) | string + 'G' }}"
|
||||||
|
|
||||||
|
- { lv: var, size: "2G" }
|
||||||
|
- { lv: var_log, size: "2G" }
|
||||||
|
- { lv: var_log_audit, size: "1.5G" }
|
||||||
|
|
||||||
- name: Create filesystems
|
- name: Create filesystems
|
||||||
block:
|
block:
|
||||||
@@ -53,9 +73,15 @@
|
|||||||
community.general.filesystem:
|
community.general.filesystem:
|
||||||
dev: "{{ install_drive }}{{ boot_partition_suffix }}"
|
dev: "{{ install_drive }}{{ boot_partition_suffix }}"
|
||||||
fstype: vfat
|
fstype: vfat
|
||||||
opts: -F32
|
opts: -F32 -n BOOT
|
||||||
force: true
|
force: true
|
||||||
|
|
||||||
|
- name: Create swap filesystem
|
||||||
|
when: filesystem != 'btrfs'
|
||||||
|
community.general.filesystem:
|
||||||
|
fstype: swap
|
||||||
|
dev: /dev/sys/swap
|
||||||
|
|
||||||
- name: Create filesystem
|
- name: Create filesystem
|
||||||
ansible.builtin.include_tasks: "{{ filesystem }}.yml"
|
ansible.builtin.include_tasks: "{{ filesystem }}.yml"
|
||||||
|
|
||||||
@@ -70,30 +96,35 @@
|
|||||||
register: main_uuid
|
register: main_uuid
|
||||||
|
|
||||||
- name: Get UUIDs for LVM filesystems
|
- name: Get UUIDs for LVM filesystems
|
||||||
when: filesystem != 'btrfs' and (cis | bool or item not in ['var_log', 'var_log_audit'])
|
when: filesystem != 'btrfs' and (cis | bool or item not in ['home', 'var', 'var_log', 'var_log_audit'])
|
||||||
ansible.builtin.command: blkid -s UUID -o value /dev/sys/{{ item }}
|
ansible.builtin.command: blkid -s UUID -o value /dev/sys/{{ item }}
|
||||||
changed_when: false
|
changed_when: false
|
||||||
register: uuid_result
|
register: uuid_result
|
||||||
loop:
|
loop:
|
||||||
- root
|
- root
|
||||||
|
- swap
|
||||||
- home
|
- home
|
||||||
- var
|
- var
|
||||||
- var_log
|
- var_log
|
||||||
- var_log_audit
|
- var_log_audit
|
||||||
|
|
||||||
- name: Assign UUIDs to Variables
|
- name: Assign UUIDs to Variables
|
||||||
|
when: filesystem != 'btrfs'
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
uuid_root: "{{ uuid_result.results[0].stdout_lines }}"
|
uuid_root: "{{ uuid_result.results[0].stdout_lines }}"
|
||||||
uuid_home: "{{ uuid_result.results[1].stdout_lines }}"
|
uuid_swap: "{{ uuid_result.results[1].stdout_lines }}"
|
||||||
uuid_var: "{{ uuid_result.results[2].stdout_lines }}"
|
uuid_home: "{{ uuid_result.results[2].stdout_lines if cis | bool else '' }}"
|
||||||
uuid_var_log: "{{ uuid_result.results[3].stdout_lines if cis == true else '' }}"
|
uuid_var: "{{ uuid_result.results[3].stdout_lines if cis | bool else '' }}"
|
||||||
uuid_var_log_audit: "{{ uuid_result.results[4].stdout_lines if cis == true else '' }}"
|
uuid_var_log: "{{ uuid_result.results[4].stdout_lines if cis | bool else '' }}"
|
||||||
when: filesystem != 'btrfs'
|
uuid_var_log_audit: "{{ uuid_result.results[5].stdout_lines if cis | bool else '' }}"
|
||||||
|
|
||||||
- name: Mount filesystems
|
- name: Mount filesystems
|
||||||
block:
|
block:
|
||||||
- name: Mount filesystems and subvolumes
|
- name: Mount filesystems and subvolumes
|
||||||
when: cis | bool or (not cis and item.path != '/var/log' and item.path != '/var/log/audit')
|
when:
|
||||||
|
- cis | bool or (not cis and (item.path == '/var/log' and filesystem == 'btrfs')
|
||||||
|
or (item.path not in ['/home', '/var', '/var/log', '/var/log/audit']))
|
||||||
|
- not (item.path == '/swap' and filesystem != 'btrfs')
|
||||||
ansible.posix.mount:
|
ansible.posix.mount:
|
||||||
path: /mnt{{ item.path }}
|
path: /mnt{{ item.path }}
|
||||||
src: "{{ 'UUID=' + (main_uuid.stdout if filesystem == 'btrfs' else item.uuid) }}"
|
src: "{{ 'UUID=' + (main_uuid.stdout if filesystem == 'btrfs' else item.uuid) }}"
|
||||||
@@ -104,6 +135,8 @@
|
|||||||
- path: ""
|
- path: ""
|
||||||
uuid: "{{ uuid_root[0] | default(omit) }}"
|
uuid: "{{ uuid_root[0] | default(omit) }}"
|
||||||
opts: "{{ 'defaults' if filesystem != 'btrfs' else 'rw,relatime,compress=zstd:15,ssd,space_cache=v2,discard=async,subvol=@' }}"
|
opts: "{{ 'defaults' if filesystem != 'btrfs' else 'rw,relatime,compress=zstd:15,ssd,space_cache=v2,discard=async,subvol=@' }}"
|
||||||
|
- path: /swap
|
||||||
|
opts: "rw,nosuid,nodev,relatime,compress=zstd:15,ssd,space_cache=v2,discard=async,subvol=@swap"
|
||||||
- path: /home
|
- path: /home
|
||||||
uuid: "{{ uuid_home[0] | default(omit) }}"
|
uuid: "{{ uuid_home[0] | default(omit) }}"
|
||||||
opts: "{{ 'defaults,nosuid,nodev' if filesystem != 'btrfs'
|
opts: "{{ 'defaults,nosuid,nodev' if filesystem != 'btrfs'
|
||||||
@@ -134,7 +167,12 @@
|
|||||||
|
|
||||||
- name: Mount boot filesystem
|
- name: Mount boot filesystem
|
||||||
ansible.posix.mount:
|
ansible.posix.mount:
|
||||||
path: "{{ '/mnt/boot/efi' if os | lower in ['ubuntu', 'ubuntu-lts'] else '/mnt/boot' }}"
|
path: "{{ '/mnt/boot/efi' if os | lower in ['rhel8', 'ubuntu', 'ubuntu-lts'] else '/mnt/boot' }}"
|
||||||
src: UUID={{ boot_uuid.stdout }}
|
src: UUID={{ boot_uuid.stdout }}
|
||||||
fstype: vfat
|
fstype: vfat
|
||||||
state: mounted
|
state: mounted
|
||||||
|
|
||||||
|
- name: Activate swap
|
||||||
|
ansible.builtin.command: "{{ 'swapon /mnt/swap/swapfile' if filesystem == 'btrfs' else 'swapon -U ' + uuid_swap[0] }}"
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
- name: Create and format XFS logical volumes
|
- name: Create and format XFS logical volumes
|
||||||
when: cis | bool or item.lv not in ['var_log', 'var_log_audit']
|
when: cis | bool or item.lv not in ['home', 'var', 'var_log', 'var_log_audit']
|
||||||
community.general.filesystem:
|
community.general.filesystem:
|
||||||
dev: /dev/sys/{{ item.lv }}
|
dev: /dev/sys/{{ item.lv }}
|
||||||
fstype: xfs
|
fstype: xfs
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
when: not vm_disk_stat.stat.exists
|
when: not vm_disk_stat.stat.exists
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
ansible.builtin.command: qemu-img create -f qcow2 {{ vm_path | default('/var/lib/libvirt/images/') }}{{ hostname }}.qcow2 {{ vm_size }}G
|
ansible.builtin.command: qemu-img create -f qcow2 {{ vm_path | default('/var/lib/libvirt/images/') }}{{ hostname }}.qcow2 {{ vm_size }}G
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Generate Random MAC Address
|
- name: Generate Random MAC Address
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
@@ -28,10 +30,12 @@
|
|||||||
|
|
||||||
- name: Create cloud-init disk
|
- name: Create cloud-init disk
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
ansible.builtin.command: cloud-localds
|
ansible.builtin.command: >
|
||||||
{{ vm_path | default('/var/lib/libvirt/images/') }}
|
cloud-localds {{ vm_path | default('/var/lib/libvirt/images/') }}/{{ hostname }}-cloudinit.iso
|
||||||
{{ hostname }}-cloudinit.iso /tmp/cloud-user-data-{{ hostname }}.yml
|
/tmp/cloud-user-data-{{ hostname }}.yml
|
||||||
-N /tmp/cloud-network-config-{{ hostname }}.yml
|
-N /tmp/cloud-network-config-{{ hostname }}.yml
|
||||||
|
changed_when: result.rc == 0
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Create VM using libvirt
|
- name: Create VM using libvirt
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|||||||
@@ -7,20 +7,21 @@
|
|||||||
api_password: "{{ hypervisor_password }}"
|
api_password: "{{ hypervisor_password }}"
|
||||||
ciuser: "{{ user_name }}"
|
ciuser: "{{ user_name }}"
|
||||||
cipassword: "{{ user_password }}"
|
cipassword: "{{ user_password }}"
|
||||||
node: "{{ hypervisor_node }}" # Proxmox node name
|
ciupgrade: false
|
||||||
vmid: "{{ vm_id }}" # Unique ID for the VM
|
node: "{{ hypervisor_node }}"
|
||||||
name: "{{ hostname }}" # Name of the VM
|
vmid: "{{ vm_id }}"
|
||||||
|
name: "{{ hostname }}"
|
||||||
cpu: host
|
cpu: host
|
||||||
cores: "{{ vm_cpus }}" # Number of CPU cores
|
cores: "{{ vm_cpus }}"
|
||||||
memory: "{{ vm_memory }}" # Memory size in MB
|
memory: "{{ vm_memory }}"
|
||||||
balloon: "{{ vm_ballo | default(omit) }}" # Minimum Memory size in MB
|
balloon: "{{ vm_ballo | default(omit) }}"
|
||||||
numa_enabled: true
|
numa_enabled: true
|
||||||
hotplug: network,disk
|
hotplug: network,disk
|
||||||
bios: ovmf
|
bios: ovmf
|
||||||
boot: ac
|
boot: ac
|
||||||
scsihw: virtio-scsi-single
|
scsihw: virtio-scsi-single
|
||||||
scsi:
|
scsi:
|
||||||
scsi0: "{{ hypervisor_storage }}:{{ vm_size }}" # Disk configuration
|
scsi0: "{{ hypervisor_storage }}:{{ vm_size }}"
|
||||||
efidisk0:
|
efidisk0:
|
||||||
efitype: 4m
|
efitype: 4m
|
||||||
format: raw
|
format: raw
|
||||||
@@ -28,14 +29,15 @@
|
|||||||
storage: "{{ hypervisor_storage }}"
|
storage: "{{ hypervisor_storage }}"
|
||||||
ide:
|
ide:
|
||||||
ide0: "{{ boot_iso }},media=cdrom"
|
ide0: "{{ boot_iso }},media=cdrom"
|
||||||
ide1: "{{ hypervisor_storage }}:cloudinit"
|
ide1: "{{ rhel_iso + ',media=cdrom' if rhel_iso is defined else omit }}"
|
||||||
|
ide2: "{{ hypervisor_storage }}:cloudinit"
|
||||||
net:
|
net:
|
||||||
net0: virtio,bridge={{ vm_nif }}{% if vlan_name is defined and vlan_name %},tag={{ vlan_name }}{% endif %}
|
net0: virtio,bridge={{ vm_nif }}{% if vlan_name is defined and vlan_name %},tag={{ vlan_name }}{% endif %}
|
||||||
ipconfig:
|
ipconfig:
|
||||||
ipconfig0: ip={{ vm_ip }},gw={{ vm_gw }}
|
ipconfig0: ip={{ vm_ip }}/{{ vm_nms | default(24) }},gw={{ vm_gw }}
|
||||||
nameservers: "{{ vm_dns }}"
|
nameservers: "{{ vm_dns }}"
|
||||||
onboot: true # Start the VM on boot
|
onboot: true
|
||||||
state: present # Ensure the VM is present
|
state: present
|
||||||
|
|
||||||
- name: Start VM on Proxmox
|
- name: Start VM on Proxmox
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
@@ -46,4 +48,4 @@
|
|||||||
node: "{{ hypervisor_node }}"
|
node: "{{ hypervisor_node }}"
|
||||||
name: "{{ hostname }}"
|
name: "{{ hostname }}"
|
||||||
vmid: "{{ vm_id }}"
|
vmid: "{{ vm_id }}"
|
||||||
state: started # Ensure the VM is present
|
state: started
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
---
|
|
||||||
- name: Create VM in vCenter
|
- name: Create VM in vCenter
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
community.vmware.vmware_guest:
|
community.vmware.vmware_guest:
|
||||||
@@ -6,11 +5,13 @@
|
|||||||
username: "{{ hypervisor_username }}"
|
username: "{{ hypervisor_username }}"
|
||||||
password: "{{ hypervisor_password }}"
|
password: "{{ hypervisor_password }}"
|
||||||
validate_certs: false
|
validate_certs: false
|
||||||
datacenter: "{{ hypervisor_cluster }}"
|
datacenter: "{{ hypervisor_datacenter }}"
|
||||||
cluster: "{{ hypervisor_node }}"
|
cluster: "{{ hypervisor_cluster }}"
|
||||||
folder: "{{ vm_path }}"
|
folder: "{{ vm_path }}"
|
||||||
name: "{{ hostname }}"
|
name: "{{ hostname }}"
|
||||||
guest_id: otherGuest64
|
guest_id: otherLinux64Guest
|
||||||
|
annotation: |
|
||||||
|
{{ note | default('') }}
|
||||||
state: poweredon
|
state: poweredon
|
||||||
disk:
|
disk:
|
||||||
- size_gb: "{{ vm_size }}"
|
- size_gb: "{{ vm_size }}"
|
||||||
@@ -21,19 +22,33 @@
|
|||||||
num_cpus: "{{ vm_cpus }}"
|
num_cpus: "{{ vm_cpus }}"
|
||||||
boot_firmware: efi
|
boot_firmware: efi
|
||||||
secure_boot: false
|
secure_boot: false
|
||||||
cdrom:
|
cdrom: >-
|
||||||
- controller_number: 0
|
{{
|
||||||
unit_number: 0
|
[ {
|
||||||
controller_type: sata
|
"controller_number": 0,
|
||||||
state: present
|
"unit_number": 0,
|
||||||
type: iso
|
"controller_type": "sata",
|
||||||
iso_path: "{{ boot_iso }}"
|
"state": "present",
|
||||||
|
"type": "iso",
|
||||||
|
"iso_path": boot_iso
|
||||||
|
} ]
|
||||||
|
+
|
||||||
|
( [ {
|
||||||
|
"controller_number": 0,
|
||||||
|
"unit_number": 1,
|
||||||
|
"controller_type": "sata",
|
||||||
|
"state": "present",
|
||||||
|
"type": "iso",
|
||||||
|
"iso_path": rhel_iso
|
||||||
|
} ] if rhel_iso is defined and rhel_iso|length > 0 else [] )
|
||||||
|
}}
|
||||||
networks:
|
networks:
|
||||||
- vlan: "{{ vlan_name }}"
|
- name: "{{ vm_nif }}"
|
||||||
type: dhcp
|
type: dhcp
|
||||||
|
vlan: "{{ vlan_name | default(omit) }}"
|
||||||
register: vmware_guest_result
|
register: vmware_guest_result
|
||||||
failed_when:
|
failed_when:
|
||||||
- vmware_guest_result.failed
|
- vmware_guest_result.failed is defined and vmware_guest_result.failed
|
||||||
- "'error' in vmware_guest_result"
|
- "'error' in vmware_guest_result"
|
||||||
- "'failed' in vmware_guest_result"
|
- "'failed' in vmware_guest_result"
|
||||||
- vmware_guest_result.rc is defined and vmware_guest_result.rc != 0
|
- vmware_guest_result.rc is defined and vmware_guest_result.rc != 0
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#cloud-config
|
#cloud-config
|
||||||
hostname: "archiso"
|
hostname: "archiso"
|
||||||
ssh_pwauth: true
|
ssh_pwauth: true
|
||||||
|
package_update: false
|
||||||
|
package_upgrade: false
|
||||||
users:
|
users:
|
||||||
- name: "{{ user_name }}"
|
- name: "{{ user_name }}"
|
||||||
primary_group: "{{ user_name }}"
|
primary_group: "{{ user_name }}"
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
<bootmenu enable='no'/>
|
<bootmenu enable='no'/>
|
||||||
<boot dev='hd'/>
|
<boot dev='hd'/>
|
||||||
<boot dev='cdrom'/>
|
<boot dev='cdrom'/>
|
||||||
<loader readonly="yes" type="pflash">/usr/share/edk2/x64/OVMF_CODE.secboot.fd</loader>
|
<loader readonly="yes" type="pflash">/usr/share/edk2/x64/OVMF_CODE.secboot.4m.fd</loader>
|
||||||
<nvram template="/usr/share/edk2/x64/OVMF_VARS.fd"/>
|
<nvram template="/usr/share/edk2/x64/OVMF_VARS.4m.fd"/>
|
||||||
</os>
|
</os>
|
||||||
<features>
|
<features>
|
||||||
<acpi/>
|
<acpi/>
|
||||||
@@ -37,6 +37,13 @@
|
|||||||
<source file="{{ vm_path | default('/var/lib/libvirt/images/') }}{{ hostname }}-cloudinit.iso"/>
|
<source file="{{ vm_path | default('/var/lib/libvirt/images/') }}{{ hostname }}-cloudinit.iso"/>
|
||||||
<target dev="sdb" bus="sata"/>
|
<target dev="sdb" bus="sata"/>
|
||||||
</disk>
|
</disk>
|
||||||
|
{% if rhel_iso is defined %}
|
||||||
|
<disk type="file" device="cdrom">
|
||||||
|
<driver name="qemu" type="raw"/>
|
||||||
|
<source file="{{ rhel_iso }}"/>
|
||||||
|
<target dev="sdc" bus="sata"/>
|
||||||
|
</disk>
|
||||||
|
{% endif %}
|
||||||
<interface type='network'>
|
<interface type='network'>
|
||||||
<mac address="{{ mac_address_output.stdout }}"/>
|
<mac address="{{ mac_address_output.stdout }}"/>
|
||||||
<source network='default'/>
|
<source network='default'/>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ metadata_expire=86400
|
|||||||
repo_gpgcheck=0
|
repo_gpgcheck=0
|
||||||
type=rpm
|
type=rpm
|
||||||
gpgcheck=1
|
gpgcheck=1
|
||||||
gpgkey=https://getfedora.org/static/fedora.gpg
|
gpgkey=https://fedoraproject.org/fedora.gpg
|
||||||
skip_if_unavailable=False
|
skip_if_unavailable=False
|
||||||
|
|
||||||
[fedora-updates]
|
[fedora-updates]
|
||||||
@@ -21,5 +21,5 @@ repo_gpgcheck=0
|
|||||||
type=rpm
|
type=rpm
|
||||||
gpgcheck=1
|
gpgcheck=1
|
||||||
metadata_expire=86400
|
metadata_expire=86400
|
||||||
gpgkey=https://getfedora.org/static/fedora.gpg
|
gpgkey=https://fedoraproject.org/fedora.gpg
|
||||||
skip_if_unavailable=False
|
skip_if_unavailable=False
|
||||||
13
templates/rhel10.repo.j2
Normal file
13
templates/rhel10.repo.j2
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[rhel10-baseos]
|
||||||
|
name=RHEL 10 BaseOS
|
||||||
|
baseurl=file:///usr/local/install/redhat/dvd/BaseOS
|
||||||
|
enabled=1
|
||||||
|
gpgcheck=0
|
||||||
|
gpgkey=file:///usr/local/install/redhat/dvd/RPM-GPG-KEY-redhat-release
|
||||||
|
|
||||||
|
[rhel10-appstream]
|
||||||
|
name=RHEL 10 AppStream
|
||||||
|
baseurl=file:///usr/local/install/redhat/dvd/AppStream
|
||||||
|
enabled=1
|
||||||
|
gpgcheck=0
|
||||||
|
gpgkey=file:///usr/local/install/redhat/dvd/RPM-GPG-KEY-redhat-release
|
||||||
13
templates/rhel8.repo.j2
Normal file
13
templates/rhel8.repo.j2
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[rhel8-baseos]
|
||||||
|
name=RHEL 8 BaseOS
|
||||||
|
baseurl=file:///usr/local/install/redhat/dvd/BaseOS
|
||||||
|
enabled=1
|
||||||
|
gpgcheck=0
|
||||||
|
gpgkey=file:///usr/local/install/redhat/dvd/RPM-GPG-KEY-redhat-release
|
||||||
|
|
||||||
|
[rhel8-appstream]
|
||||||
|
name=RHEL 8 AppStream
|
||||||
|
baseurl=file:///usr/local/install/redhat/dvd/AppStream
|
||||||
|
enabled=1
|
||||||
|
gpgcheck=0
|
||||||
|
gpgkey=file:///usr/local/install/redhat/dvd/RPM-GPG-KEY-redhat-release
|
||||||
13
templates/rhel9.repo.j2
Normal file
13
templates/rhel9.repo.j2
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[rhel9-baseos]
|
||||||
|
name=RHEL 9 BaseOS
|
||||||
|
baseurl=file:///usr/local/install/redhat/dvd/BaseOS
|
||||||
|
enabled=1
|
||||||
|
gpgcheck=0
|
||||||
|
gpgkey=file:///usr/local/install/redhat/dvd/RPM-GPG-KEY-redhat-release
|
||||||
|
|
||||||
|
[rhel9-appstream]
|
||||||
|
name=RHEL 9 AppStream
|
||||||
|
baseurl=file:///usr/local/install/redhat/dvd/AppStream
|
||||||
|
enabled=1
|
||||||
|
gpgcheck=0
|
||||||
|
gpgkey=file:///usr/local/install/redhat/dvd/RPM-GPG-KEY-redhat-release
|
||||||
@@ -1,15 +1,18 @@
|
|||||||
ansible_user: "{{ user_name }}"
|
vm_ip: "{{ inventory_hostname }}"
|
||||||
ansible_password: "{{ user_password }}"
|
|
||||||
ansible_become_password: "{{ user_password }}"
|
|
||||||
ansible_ssh_extra_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
|
|
||||||
|
|
||||||
vm_ip: "{{ inventory_hostname }}/24"
|
|
||||||
install_type: "virtual"
|
install_type: "virtual"
|
||||||
cis: false
|
|
||||||
|
|
||||||
hypervisor_url: "192.168.0.2"
|
hypervisor_url: "192.168.0.2"
|
||||||
hypervisor_username: "root@pam"
|
hypervisor_username: "root@pam"
|
||||||
hypervisor_password: "SomePassword"
|
hypervisor_password: "SomePassword"
|
||||||
hypervisor_node: "NodeName"
|
hypervisor_node: "NodeName"
|
||||||
hypervisor_storage: "local-btrfs"
|
hypervisor_storage: "local-btrfs"
|
||||||
boot_iso: "local-btrfs:iso/archlinux-x86_64.iso"
|
|
||||||
|
# For VMware-Tools
|
||||||
|
ansible_vmware_host: "{{ hypervisor_url }}"
|
||||||
|
ansible_vmware_user: "{{ hypervisor_username }}"
|
||||||
|
ansible_vmware_password: "{{ hypervisor_password }}"
|
||||||
|
ansible_vmware_guest_path: "/{{ hypervisor_cluster }}/vm{{ vm_path }}/{{ hostname }}"
|
||||||
|
ansible_vmware_validate_certs: no
|
||||||
|
ansible_vmware_tools_user: "root"
|
||||||
|
ansible_vmware_tools_password: ""
|
||||||
|
vmware_ssh: true
|
||||||
|
|||||||
Reference in New Issue
Block a user