feat(pb,task): moves input validation into separated tasks files. Play fails immediately if a validation fails
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
---
|
||||
|
||||
- name: Set default hostname
|
||||
ansible.builtin.set_fact:
|
||||
lxc_hostname: "new-lxc-test"
|
||||
|
||||
- name: Prompt for hostname with immediate validation
|
||||
ansible.builtin.pause:
|
||||
prompt: "Enter hostname (letters, digits, hyphens, dots; max 253 chars) [new-lxc-test]"
|
||||
register: hostname_result
|
||||
until: >
|
||||
hostname_result.user_input | length == 0 or
|
||||
(
|
||||
hostname_result.user_input | length <= 253 and
|
||||
hostname_result.user_input is 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])?)*$')
|
||||
)
|
||||
retries: 2
|
||||
delay: 0
|
||||
|
||||
- name: Use user input only if provided, otherwise keep the default
|
||||
ansible.builtin.set_fact:
|
||||
lxc_hostname: "{{ hostname_result.user_input }}"
|
||||
when: hostname_result.user_input | length > 0
|
||||
Reference in New Issue
Block a user