From ad9049a49ed44104558ac8820f1ca3e51c29088b Mon Sep 17 00:00:00 2001
From: Ryan Zenker <ryan@nodal.org>
Date: Mon, 5 Feb 2018 19:38:05 -0500
Subject: [PATCH] baremetal tweaks

* allow installs to not have hostname overriden with fqdn from inventory
* calico-config no longer requires local as and will default to global
* when cloudprovider is not defined, use the inventory_hostname for cni-calico
* allow reset to not restart network (buggy nodes die with this cmd)
* default kube_override_hostname to inventory_hostname instead of ansible_hostname
---
 roles/bootstrap-os/defaults/main.yml                        | 2 ++
 roles/bootstrap-os/tasks/main.yml                           | 4 ++--
 roles/kubernetes/node/defaults/main.yml                     | 2 +-
 roles/network_plugin/calico/templates/calico-config.yml.j2  | 6 +++---
 .../network_plugin/calico/templates/cni-calico.conflist.j2  | 2 +-
 roles/reset/defaults/main.yml                               | 1 +
 roles/reset/tasks/main.yml                                  | 2 +-
 7 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/roles/bootstrap-os/defaults/main.yml b/roles/bootstrap-os/defaults/main.yml
index 11e45196f..c191ebd2b 100644
--- a/roles/bootstrap-os/defaults/main.yml
+++ b/roles/bootstrap-os/defaults/main.yml
@@ -2,3 +2,5 @@
 pip_python_coreos_modules:
   - httplib2
   - six
+
+override_system_hostname: true
diff --git a/roles/bootstrap-os/tasks/main.yml b/roles/bootstrap-os/tasks/main.yml
index 6f45fb073..01031deeb 100644
--- a/roles/bootstrap-os/tasks/main.yml
+++ b/roles/bootstrap-os/tasks/main.yml
@@ -29,12 +29,12 @@
 - name: Assign inventory name to unconfigured hostnames (non-CoreOS)
   hostname:
     name: "{{inventory_hostname}}"
-  when: ansible_os_family not in ['CoreOS', 'Container Linux by CoreOS']
+  when: ansible_os_family not in ['CoreOS', 'Container Linux by CoreOS'] and override_system_hostname
 
 - name: Assign inventory name to unconfigured hostnames (CoreOS only)
   command: "hostnamectl set-hostname  {{inventory_hostname}}"
   register: hostname_changed
-  when: ansible_hostname == 'localhost' and ansible_os_family in ['CoreOS', 'Container Linux by CoreOS']
+  when: ansible_hostname == 'localhost' and ansible_os_family in ['CoreOS', 'Container Linux by CoreOS'] and override_system_hostname
 
 - name: Update hostname fact (CoreOS only)
   setup:
diff --git a/roles/kubernetes/node/defaults/main.yml b/roles/kubernetes/node/defaults/main.yml
index 8540aa159..50a30add3 100644
--- a/roles/kubernetes/node/defaults/main.yml
+++ b/roles/kubernetes/node/defaults/main.yml
@@ -84,7 +84,7 @@ kube_hyperkube_image_repo: ""
 kube_override_hostname: >-
   {%- if cloud_provider is defined and cloud_provider in [ 'aws' ] -%}
   {%- else -%}
-  {{ ansible_hostname }}
+  {{ inventory_hostname }}
   {%- endif -%}
 
 # cAdvisor port
diff --git a/roles/network_plugin/calico/templates/calico-config.yml.j2 b/roles/network_plugin/calico/templates/calico-config.yml.j2
index fbae4eda1..92d2f1f0a 100644
--- a/roles/network_plugin/calico/templates/calico-config.yml.j2
+++ b/roles/network_plugin/calico/templates/calico-config.yml.j2
@@ -14,6 +14,6 @@ data:
   cluster_type: "kubespray,bgp"
 {% endif %}
   calico_backend: "bird"
-  {%- if inventory_hostname in groups['k8s-cluster'] and peer_with_router|default(false) %}
-  as: "{{ local_as }}"
-  {% endif -%}
+{% if inventory_hostname in groups['k8s-cluster'] and peer_with_router|default(false) %}
+  as: "{{ local_as|default(global_as_num) }}"
+{% endif -%}
diff --git a/roles/network_plugin/calico/templates/cni-calico.conflist.j2 b/roles/network_plugin/calico/templates/cni-calico.conflist.j2
index abe43f7f7..32f2bfff6 100644
--- a/roles/network_plugin/calico/templates/cni-calico.conflist.j2
+++ b/roles/network_plugin/calico/templates/cni-calico.conflist.j2
@@ -6,7 +6,7 @@
     {% if cloud_provider is defined %}
       "nodename": "{{ calico_kubelet_name.stdout }}",
     {% else %}
-      "nodename": "{{ ansible_hostname }}",
+      "nodename": "{{ inventory_hostname }}",
     {% endif %}
       "type": "calico",
       "etcd_endpoints": "{{ etcd_access_addresses }}",
diff --git a/roles/reset/defaults/main.yml b/roles/reset/defaults/main.yml
index 7d4dbfdff..e45cee42e 100644
--- a/roles/reset/defaults/main.yml
+++ b/roles/reset/defaults/main.yml
@@ -1,2 +1,3 @@
 ---
 flush_iptables: true
+reset_restart_network: true
diff --git a/roles/reset/tasks/main.yml b/roles/reset/tasks/main.yml
index 7be66e707..f6714f680 100644
--- a/roles/reset/tasks/main.yml
+++ b/roles/reset/tasks/main.yml
@@ -195,7 +195,7 @@
       networking
       {%- endif %}
     state: restarted
-  when: ansible_os_family not in ["CoreOS", "Container Linux by CoreOS"]
+  when: ansible_os_family not in ["CoreOS", "Container Linux by CoreOS"] and reset_restart_network
   tags:
     - services
     - network
-- 
GitLab