From 4789bbd85038095359b3f859073304691a2bc422 Mon Sep 17 00:00:00 2001 From: Maxim Vershinin Date: Wed, 16 Sep 2026 17:51:49 +0400 Subject: [PATCH] fix(pb): makes hostname validation strict enough --- playbooks/deploy_and_set_up_lxc_on_proxmox.yaml | 10 ++++++++-- playbooks/deploy_vm_from_cloud_init.yaml | 12 +++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml b/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml index afe11d9..86440ca 100644 --- a/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml +++ b/playbooks/deploy_and_set_up_lxc_on_proxmox.yaml @@ -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 diff --git a/playbooks/deploy_vm_from_cloud_init.yaml b/playbooks/deploy_vm_from_cloud_init.yaml index 2ce67d7..3053194 100644 --- a/playbooks/deploy_vm_from_cloud_init.yaml +++ b/playbooks/deploy_vm_from_cloud_init.yaml @@ -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