Files
vmn-ansible/playbooks/deploy_vm_from_cloud_init.yaml
T

68 lines
2.1 KiB
YAML

---
- name: Deploy VM
hosts: localhost
remote_user: ansible
gather_facts: false
vars_files:
../inventory/group_vars/all/secrets.yaml
vars:
ansible_user_passwd_hash: "{{ ansible_password | password_hash('sha512', 's3edscrj45e6r') }}"
user_passwd_hash: "{{ user_password | password_hash('sha512', 's3ed6123jhgcr') }}"
pre_tasks:
- name: Include input and validation for hostname
ansible.builtin.include_tasks: ../tasks/hostname_validation.yaml
- name: Include input and validation for IP
ansible.builtin.include_tasks: ../tasks/ip_validation.yaml
- name: Include input and validation for human admin user creation
ansible.builtin.include_tasks: ../tasks/human_admin_user_validation.yaml
- name: Include input and validation for OS template
ansible.builtin.include_tasks: ../tasks/os_template_validation.yaml
- name: Include input and validation for become method
ansible.builtin.include_tasks: ../tasks/become_method_validation.yaml
roles:
- ../roles/deploy_vm_on_proxmox
tasks:
- name: Add the target host to the inventory
ansible.builtin.add_host:
name: "{{ guest_ip_address }}"
groups: new_host
ansible_user: ansible
ansible_become_password: "{{ ansible_become_passwd }}"
ansible_become_method: "{{ guest_become_method }}"
- name: Configure VM
hosts: new_host
remote_user: ansible
vars_files:
../inventory/group_vars/all/secrets.yaml
vars:
ansible_user_passwd_hash: "{{ ansible_password | password_hash('sha512', 's3edscrj45e6r') }}"
user_passwd_hash: "{{ user_password | password_hash('sha512', 's3ed6123jhgcr') }}"
roles:
- ../roles/configure_ansible_user
- ../roles/harden_ssh
- ../roles/base_system
tasks:
- name: Include human admin user role
ansible.builtin.include_role:
name: ../roles/human_admin_user
when: "hostvars['localhost']['create_human_admin_user'] | bool"
- name: Include update configs role
ansible.builtin.include_role:
name: ../roles/update_configs
when: "hostvars['localhost']['create_human_admin_user'] | bool"