Ansible-Bootstrap/main.yml

91 lines
2.1 KiB
YAML
Raw Normal View History

2024-03-19 23:02:50 +01:00
---
- name: Create and configure VMs
hosts: all
strategy: free
gather_facts: false
become: true
vars_prompt:
2024-07-11 22:20:45 +02:00
- name: user_name
prompt: |
What is your username?
private: false
2024-03-19 23:02:50 +01:00
2024-07-11 22:20:45 +02:00
- name: user_password
prompt: |
What is your password?
confirm: true
2024-03-19 23:02:50 +01:00
2024-07-11 22:20:45 +02:00
- name: root_password
prompt: |
What is your root password?
confirm: true
2024-03-19 23:02:50 +01:00
2024-07-11 22:20:45 +02:00
- name: hypervisor
prompt: |
Select an Hypervisor:
- libvirt
- proxmox
- vmware
private: false
default: proxmox
2024-03-19 23:02:50 +01:00
2024-07-11 22:20:45 +02:00
- name: install_drive
prompt: |
"Enter the drive to install the system (default: /dev/sda)"
confirm: true
private: false
default: /dev/sda
2024-03-19 23:02:50 +01:00
vars_files: vars.yml
pre_tasks:
- name: Set ansible_python_interpreter
2024-04-16 01:14:05 +02:00
when: os | lower in ["almalinux", "rhel9", "rhel8", "rocky"]
2024-07-11 22:20:45 +02:00
ansible.builtin.set_fact:
2024-03-19 23:02:50 +01:00
ansible_python_interpreter: /usr/bin/python3
- name: Validate variables
2024-07-11 22:20:45 +02:00
ansible.builtin.assert:
2024-03-19 23:02:50 +01:00
that:
2024-04-15 21:23:32 +02:00
- hypervisor in ["libvirt", "proxmox", "vmware", "none"]
- filesystem in ["btrfs", "ext4", "xfs"]
2024-04-17 10:53:09 +02:00
- os in ["archlinux", "almalinux", "debian11", "debian12", "fedora", "rocky", "ubuntu", "ubuntu-lts"]
2024-07-11 22:20:45 +02:00
fail_msg: Invalid input specified, please try again
2024-03-19 23:02:50 +01:00
- name: Set connection
when: hypervisor == "vmware"
2024-07-11 22:20:45 +02:00
ansible.builtin.set_fact:
2024-03-19 23:02:50 +01:00
ansible_connection: vmware_tools
roles:
2024-07-11 22:20:45 +02:00
- role: virtualization
when: install_type == "virtual"
become: false
vars:
ansible_connection: local
2024-03-19 23:02:50 +01:00
2024-07-11 22:20:45 +02:00
- role: environment
vars:
ansible_connection: "{{ 'vmware_tools' if hypervisor == 'vmware' else 'ssh' }}"
2024-03-19 23:02:50 +01:00
2024-07-11 22:20:45 +02:00
- role: partitioning
vars:
boot_partition_suffix: 1
main_partition_suffix: 2
2024-03-19 23:02:50 +01:00
2024-07-11 22:20:45 +02:00
- role: bootstrap
2024-03-19 23:02:50 +01:00
2024-07-11 22:20:45 +02:00
- role: configuration
2024-03-19 23:02:50 +01:00
2024-07-11 22:20:45 +02:00
- role: cis
when: cis == true
2024-03-19 23:02:50 +01:00
2024-07-11 22:20:45 +02:00
- role: cleanup
when: install_type == "virtual"
vars:
ansible_connection: local
2024-03-19 23:02:50 +01:00
tasks:
- name: Reboot system
when: hypervisor != "libvirt"
2024-07-11 22:20:45 +02:00
ansible.builtin.command: reboot
ignore_errors: true