fix(pb): makes hostname validation strict enough

This commit was merged in pull request #37.
This commit is contained in:
2026-09-16 17:51:49 +04:00
parent e5e4aa1832
commit 4789bbd850
2 changed files with 17 additions and 5 deletions
@@ -43,8 +43,14 @@
ansible.builtin.fail:
msg: |
Invalid hostname: "{{ lxc_hostname }}"
Hostname may only contain letters (a-z, A-Z), numbers (0-9), and hyphens (-).
when: not lxc_hostname is regex('^[a-zA-Z0-9-]+$')
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
+9 -3
View File
@@ -40,9 +40,15 @@
- name: Validate hostname
ansible.builtin.fail:
msg: |
Invalid hostname: "{{ vm_hostname }}"
Hostname may only contain letters (a-z, A-Z), numbers (0-9), and hyphens (-).
when: not vm_hostname is regex('^[a-zA-Z0-9-]+$')
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