Use api lookup for kubelet hostname when using cloudprovider (#1686)

The value cannot be determined properly via local facts, so
checking k8s api is the most reliable way to look up what hostname
is used when using a cloudprovider.
This commit is contained in:
Matthew Mosesohn
2017-09-24 09:22:15 +01:00
committed by GitHub
parent 4f6362515f
commit d94e3a81eb
4 changed files with 13 additions and 3 deletions

View File

@@ -6,6 +6,13 @@
enabled: yes
failed_when: false
- name: Calico | Get kubelet hostname
shell: >-
kubectl get node -o custom-columns='NAME:.metadata.name,INTERNAL-IP:.status.addresses[?(@.type=="InternalIP")].address'
| egrep "[[:space:]]{{ ansible_all_ipv4_addresses | join('[[:space:]]|[[:space:]]') }}[[:space:]]*$" | cut -d" " -f1
register: calico_kubelet_name
when: cloud_provider is defined
- name: Calico | Write Calico cni config
template:
src: "cni-calico.conf.j2"

View File

@@ -1,7 +1,7 @@
{
"name": "calico-k8s-network",
{% if cloud_provider is defined %}
"nodename": "{{ inventory_hostname }}",
"nodename": "{{ calico_kubelet_name.stdout }}",
{% else %}
"nodename": "{{ ansible_hostname }}",
{% endif %}