feat(pb,task): moves input validation into separated tasks files. Play fails immediately if a validation fails

This commit is contained in:
2026-09-17 10:16:05 +04:00
parent 4789bbd850
commit 0696218eb6
6 changed files with 137 additions and 50 deletions
+23
View File
@@ -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