From 3eef8dc8d0b42e5aba9b36ed30dd86376249ab55 Mon Sep 17 00:00:00 2001 From: Tatsuyuki Ishi Date: Mon, 20 Aug 2018 00:20:36 +0900 Subject: [PATCH] Add bad hostname preflight check Hostname must be a valid DNS name, which is checked as https://github.com/kubernetes/apimachinery/blob/master/pkg/util/validation/validation.go#L115 The situation I have encountered is that my hostname contained underscore which is disallowed and apiserver refused to start. --- roles/kubernetes/preinstall/tasks/verify-settings.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/roles/kubernetes/preinstall/tasks/verify-settings.yml b/roles/kubernetes/preinstall/tasks/verify-settings.yml index 581acdc8f..6910824a5 100644 --- a/roles/kubernetes/preinstall/tasks/verify-settings.yml +++ b/roles/kubernetes/preinstall/tasks/verify-settings.yml @@ -103,3 +103,9 @@ that: ansible_kernel.split('-')[0]|version_compare('4.8', '>=') when: kube_network_plugin == 'cilium' ignore_errors: "{{ ignore_assert_errors }}" + +- name: Stop if bad hostname + assert: + that: inventory_hostname | match("[a-z0-9]([-a-z0-9]*[a-z0-9])?$") + msg: "Hostname must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character" + ignore_errors: "{{ ignore_assert_errors }}"