Ansible-Bootstrap/main.yml

86 lines
2.3 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
vars:
2024-10-30 17:09:22 +01:00
hypervisor: "vmware"
install_drive: "/dev/sda"
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
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-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)
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
2024-10-28 18:56:00 +01:00
failed_when: false
changed_when: result.rc == 0
register: result