Ansible-Bootstrap/main.yml

81 lines
2.0 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-11-07 14:57:39 +01:00
when: os | lower in ["rhel9", "rhel8"]
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-11-07 14:57:39 +01:00
- filesystem in ["ext4", "xfs"]
2024-10-30 22:19:00 +01:00
- install_drive is defined
2024-11-07 14:57:39 +01:00
- os in ["rhel8", "rhel9"]
- (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
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
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:
2024-11-07 14:57:39 +01:00
ansible_connection: vmware
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
vars:
ansible_connection: local
tasks:
- name: Set final SSH Credentials
2024-11-07 14:57:39 +01:00
when: 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