feat(pb,task): moves input validation into separated tasks files. Play fails immediately if a validation fails
This commit is contained in:
@@ -10,65 +10,27 @@
|
||||
ansible_user_passwd_hash: "{{ ansible_password | password_hash('sha512', 's3edscrj45e6r') }}"
|
||||
user_passwd_hash: "{{ user_password | password_hash('sha512', 's3ed6123jhgcr') }}"
|
||||
|
||||
vars_prompt:
|
||||
- name: lxc_hostname
|
||||
prompt: "Hostname for the container (may only contain letters (a-z, A-Z), numbers (0-9), and hyphens)"
|
||||
default: "new-lxc-test"
|
||||
private: false
|
||||
pre_tasks:
|
||||
- name: Include input and validation for hostname
|
||||
ansible.builtin.include_tasks: ../tasks/hostname_validation.yaml
|
||||
|
||||
- name: Include input and validation for password
|
||||
ansible.builtin.include_tasks: ../tasks/password_validation.yaml
|
||||
|
||||
- name: lxc_root_password
|
||||
prompt: "Root password"
|
||||
default: "new-lxc-test"
|
||||
private: true
|
||||
confirm: true
|
||||
encrypt: sha512_crypt
|
||||
- name: Include input and validation for IP
|
||||
ansible.builtin.include_tasks: ../tasks/ip_validation.yaml
|
||||
|
||||
- name: lxc_ip_address
|
||||
prompt: "IP address for the container (in x.x.x.x/x formant)"
|
||||
default: "192.168.0.90/24"
|
||||
private: false
|
||||
- name: Include input and validation for LXC privilege
|
||||
ansible.builtin.include_tasks: ../tasks/lxc_privileged_validation.yaml
|
||||
|
||||
- name: lxc_is_privileged
|
||||
prompt: "Unprivileged LXC (true/false)?"
|
||||
default: true
|
||||
private: false
|
||||
- name: Include input and validation for human admin user creation
|
||||
ansible.builtin.include_tasks: ../tasks/human_admin_user_validation.yaml
|
||||
|
||||
- name: lxc_create_human_admin_user
|
||||
prompt: "Create human admin user? (true/false)?"
|
||||
default: true
|
||||
private: false
|
||||
|
||||
pre_tasks:
|
||||
- name: Validate hostname
|
||||
ansible.builtin.fail:
|
||||
msg: |
|
||||
Invalid hostname: "{{ lxc_hostname }}"
|
||||
Hostname must:
|
||||
- contain only letters (a-z, A-Z), digits (0-9), hyphens (-), and dots (.)
|
||||
- not start or end with a hyphen or dot
|
||||
- have each label between 1 and 63 characters
|
||||
- not exceed 253 characters in total
|
||||
when: >
|
||||
lxc_hostname | length > 253 or
|
||||
lxc_hostname is not regex('^[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$')
|
||||
run_once: true
|
||||
|
||||
- name: Validate IP address
|
||||
ansible.builtin.fail:
|
||||
msg: |
|
||||
Invalid IP address: "{{ lxc_ip_address }}"
|
||||
IP address must be in x.x.x.x/x format (e.g., 192.168.0.90/24).
|
||||
when: not lxc_ip_address is regex('^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)(\\/(3[0-2]|[12]?\\d))?$')
|
||||
run_once: true
|
||||
|
||||
roles:
|
||||
- ../roles/deploy_lxc_on_proxmox
|
||||
|
||||
tasks:
|
||||
- name: Make the prompted hostname available to the whole playbook
|
||||
ansible.builtin.set_fact:
|
||||
fact_lxc_hostname: "{{ lxc_hostname }}"
|
||||
|
||||
- name: Make the prompted IP available to the whole playbook
|
||||
ansible.builtin.set_fact:
|
||||
fact_lxc_ip_address: "{{ lxc_ip_address.split('/') | first }}"
|
||||
|
||||
Reference in New Issue
Block a user