Files
infra-automation/roles/deploy_linux_vm/tasks/validate.yml
Infrastructure Team eec15a1cc2 Add deploy_linux_vm role with LVM and SSH hardening
Features:
- Multi-distribution support (Debian, Ubuntu, RHEL, AlmaLinux, Rocky, SUSE)
- LVM configuration with meaningful volume groups and logical volumes
- 8 LVs: lv_opt, lv_tmp, lv_home, lv_var, lv_var_log, lv_var_tmp, lv_var_audit, lv_swap
- Security mount options on sensitive directories

SSH Hardening:
- GSSAPI authentication disabled
- GSSAPI cleanup credentials disabled
- Root login disabled via SSH
- Password authentication disabled
- Key-based authentication only
- MaxAuthTries: 3, ClientAliveInterval: 300s

Security Features:
- SELinux enforcing (RHEL family)
- AppArmor enabled (Debian family)
- Firewall configuration (UFW/firewalld)
- Automatic security updates
- Audit daemon (auditd) enabled
- Time synchronization (chrony)
- Essential security packages (aide, auditd)

Role Structure:
- Modular task organization (validate, install, download, storage, deploy, lvm)
- Tag-based execution for selective deployment
- OS-family specific cloud-init templates
- Comprehensive variable defaults (100+ configurable options)
- Post-deployment validation tasks
2025-11-10 22:51:51 +01:00

83 lines
3.1 KiB
YAML

---
# =============================================================================
# Validation Tasks - Pre-flight Checks
# =============================================================================
- name: Validate distribution selection
assert:
that:
- deploy_linux_vm_os_distribution is defined
- deploy_linux_vm_os_distribution in deploy_linux_vm_cloud_images.keys()
fail_msg: |
Invalid distribution '{{ deploy_linux_vm_os_distribution }}'.
Supported distributions: {{ deploy_linux_vm_cloud_images.keys() | list | join(', ') }}
success_msg: "Distribution '{{ deploy_linux_vm_os_distribution }}' is valid"
tags: [validate, preflight]
- name: Set distribution facts
set_fact:
deploy_linux_vm_distro_config: "{{ deploy_linux_vm_cloud_images[deploy_linux_vm_os_distribution] }}"
deploy_linux_vm_image_cache_path: "{{ deploy_linux_vm_images_dir }}/{{ deploy_linux_vm_cloud_images[deploy_linux_vm_os_distribution].cache_name }}"
tags: [always]
- name: Display deployment information
debug:
msg:
- "=== VM Deployment Configuration ==="
- "VM Name: {{ deploy_linux_vm_name }}"
- "Distribution: {{ deploy_linux_vm_os_distribution }}"
- "OS Family: {{ deploy_linux_vm_distro_config.family }}"
- "Package Manager: {{ deploy_linux_vm_distro_config.package_manager }}"
- "vCPUs: {{ deploy_linux_vm_vcpus }}"
- "Memory: {{ deploy_linux_vm_memory_mb }} MB"
- "Disk: {{ deploy_linux_vm_disk_size_gb }} GB"
- "LVM Enabled: {{ deploy_linux_vm_use_lvm }}"
tags: [validate, preflight]
- name: Validate VM name
assert:
that:
- deploy_linux_vm_name is defined
- deploy_linux_vm_name | length > 0
- deploy_linux_vm_name is match('^[a-zA-Z0-9_-]+$')
fail_msg: "VM name must be defined and contain only alphanumeric characters, hyphens, or underscores"
success_msg: "VM name '{{ deploy_linux_vm_name }}' is valid"
tags: [validate, preflight]
- name: Check if VM already exists
command: virsh dominfo {{ deploy_linux_vm_name }}
register: deploy_linux_vm_exists_check
failed_when: false
changed_when: false
tags: [validate, preflight]
- name: Fail if VM already exists
fail:
msg: "VM '{{ deploy_linux_vm_name }}' already exists on hypervisor. Please choose a different name or destroy the existing VM."
when: deploy_linux_vm_exists_check.rc == 0
tags: [validate, preflight]
- name: Verify virtualization support
command: virt-host-validate qemu
register: deploy_linux_vm_virt_validation
failed_when: false
changed_when: false
tags: [validate, preflight]
- name: Display virtualization validation results
debug:
var: deploy_linux_vm_virt_validation.stdout_lines
tags: [validate, preflight]
- name: Validate LVM configuration
assert:
that:
- deploy_linux_vm_lvm_vg_name is defined
- deploy_linux_vm_lvm_pv_device is defined
- deploy_linux_vm_lvm_volumes is defined
- deploy_linux_vm_lvm_volumes | length > 0
fail_msg: "LVM is enabled but configuration is incomplete"
success_msg: "LVM configuration is valid"
when: deploy_linux_vm_use_lvm | bool
tags: [validate, preflight, lvm]