refactor: improve hostname validation logic in OS precheck tasks (#2845)

Signed-off-by: redscholar <blacktiledhouse@gmail.com>
This commit is contained in:
liujian 2025-11-10 11:24:25 +08:00 committed by GitHub
parent 8a5ad6ee8c
commit 38d1dd90e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 6 deletions

View File

@ -45,7 +45,6 @@
when:
- .image_registry.auth.registry | empty | not
- .image_registry.type | empty
run_once: true
command: |
HTTP_CODE=$(curl -skLI -w "%{http_code}" -u "{{ .image_registry.auth.username }}:{{ .image_registry.auth.password }}" "https://{{ .image_registry.auth.registry }}/v2/" -o /dev/null)
if [[ "$HTTP_CODE" == "200" ]]; then

View File

@ -1,9 +1,18 @@
---
- name: OS | Fail if hostname is invalid
assert:
that: .hostname | regexMatch "^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$"
fail_msg: >-
The hostname "{{ .hostname }}" is invalid. Hostnames must use only lowercase alphanumeric characters, '.', or '-', and must start and end with an alphanumeric character.
- name: OS | Assert valid system hostname format
block:
- name: OS | Validate inventory hostname is RFC-compliant
when: .set_hostname
assert:
that: .inventory_hostname | regexMatch "^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$"
fail_msg: >-
The hostname "{{ .inventory_hostname }}" is invalid. Hostnames must use only lowercase alphanumeric characters, '.', or '-', and must start and end with an alphanumeric character.
- name: OS | Validate current host system hostname is RFC-compliant
when: .set_hostname | not
assert:
that: .hostname | regexMatch "^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$"
fail_msg: >-
The hostname "{{ .hostname }}" is invalid. Hostnames must use only lowercase alphanumeric characters, '.', or '-', and must start and end with an alphanumeric character.
- name: OS | Fail if operating system is not supported
assert: