Ansible-Bootstrap/main.yml

94 lines
2.8 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
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: 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"
2024-03-19 23:02:50 +01:00
- 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-10-30 22:19:00 +01:00
- install_drive is defined
2024-10-30 00:29:46 +01:00
- os in ["archlinux", "almalinux", "debian11", "debian12", "fedora", "rhel8", "rhel9", "rocky", "ubuntu", "ubuntu-lts"]
- os not in ["rhel8", "rhel9"] or rhel_iso is defined
2024-10-30 00:44:19 +01:00
- (filesystem == "btrfs" and (vm_size | int) >= 10) or (filesystem != "btrfs" and (vm_size | int) >= 20)
2024-10-31 05:46:33 +01:00
- (vm_size | float) >= ((vm_memory | float / 1024 >= 16.0) | ternary((vm_memory | float / 2048), [vm_memory | float / 1024, 4.0] | max) + 16)
2024-10-30 00:44:19 +01: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
2024-10-30 22:19:00 +01:00
when: cis | bool
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
tasks:
- name: Set final SSH Credentials
when: hypervisor == 'vmware' and vmware_ssh | bool
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: Check if VM is back and running
ansible.builtin.wait_for_connection:
timeout: 300