100 lines
2.6 KiB
YAML
100 lines
2.6 KiB
YAML
---
|
|
- name: Create and configure VMs
|
|
hosts: all
|
|
strategy: free
|
|
gather_facts: false
|
|
become: true
|
|
vars_prompt:
|
|
- name: user_name
|
|
prompt: |
|
|
What is your username?
|
|
private: false
|
|
|
|
- name: user_password
|
|
prompt: |
|
|
What is your password?
|
|
confirm: true
|
|
|
|
- name: root_password
|
|
prompt: |
|
|
What is your root password?
|
|
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:
|
|
ansible_user: "{{ user_name }}"
|
|
ansible_password: "{{ user_password }}"
|
|
ansible_become_password: "{{ user_password }}"
|
|
ansible_ssh_extra_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
|
|
pre_tasks:
|
|
- name: Set ansible_python_interpreter
|
|
when: os | lower in ["almalinux", "rhel9", "rhel8", "rocky"]
|
|
ansible.builtin.set_fact:
|
|
ansible_python_interpreter: /usr/bin/python3
|
|
|
|
- name: Validate variables
|
|
ansible.builtin.assert:
|
|
that:
|
|
- hypervisor in ["libvirt", "proxmox", "vmware", "none"]
|
|
- filesystem in ["btrfs", "ext4", "xfs"]
|
|
- os in ["archlinux", "almalinux", "debian11", "debian12", "fedora", "rhel8", "rhel9", "rocky", "ubuntu", "ubuntu-lts"]
|
|
- os not in ["rhel8", "rhel9"] or rhel_iso is defined
|
|
- (filesystem == "btrfs" and (vm_size | int) >= 10) or (filesystem != "btrfs" and (vm_size | int) >= 20)
|
|
fail_msg: Invalid input specified, please try again.
|
|
|
|
- name: Set connection
|
|
when: hypervisor == "vmware"
|
|
ansible.builtin.set_fact:
|
|
ansible_connection: vmware_tools
|
|
|
|
roles:
|
|
- role: virtualization
|
|
when: install_type == "virtual"
|
|
become: false
|
|
vars:
|
|
ansible_connection: local
|
|
|
|
- role: environment
|
|
vars:
|
|
ansible_connection: "{{ 'vmware_tools' if hypervisor == 'vmware' else 'ssh' }}"
|
|
|
|
- role: partitioning
|
|
vars:
|
|
boot_partition_suffix: 1
|
|
main_partition_suffix: 2
|
|
|
|
- role: bootstrap
|
|
|
|
- role: configuration
|
|
|
|
- role: cis
|
|
when: cis == true
|
|
|
|
- role: cleanup
|
|
when: install_type == "virtual"
|
|
vars:
|
|
ansible_connection: local
|
|
|
|
tasks:
|
|
- name: Reboot system
|
|
when: hypervisor != "libvirt"
|
|
ansible.builtin.command: reboot
|
|
failed_when: false
|
|
changed_when: result.rc == 0
|
|
register: result
|