24 lines
787 B
YAML
24 lines
787 B
YAML
---
|
|
|
|
- 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
|