2016-07-04 13:13:49 +00:00
|
|
|
# FXIME: add persistent routing rule
|
|
|
|
- hosts: kube-master
|
|
|
|
tasks:
|
2016-07-05 10:43:14 +00:00
|
|
|
- name: Get kube service net
|
|
|
|
shell: grep KUBE_SERVICE_ADDRESSES /etc/kubernetes/kube-apiserver.env | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]{1,2}\b"
|
|
|
|
register: kube_service_addresses
|
2016-07-04 13:13:49 +00:00
|
|
|
run_once: true
|
|
|
|
- hosts: all
|
|
|
|
tasks:
|
|
|
|
- name: Get local IP
|
|
|
|
shell: "calicoctl status | grep IP: | awk '{print $2}'"
|
|
|
|
register: local_ip
|
|
|
|
- name: Get route
|
2016-07-05 10:43:14 +00:00
|
|
|
shell: ip ro ls | grep "^{{ hostvars[groups['kube-master'][0]]['kube_service_addresses']['stdout'] }}" || echo ""
|
2016-07-04 13:13:49 +00:00
|
|
|
register: local_route
|
|
|
|
- name: Clean up route
|
2016-07-05 10:43:14 +00:00
|
|
|
shell: ip ro del {{ hostvars[groups['kube-master'][0]]['kube_service_addresses']['stdout'] }} || true
|
2016-07-04 13:13:49 +00:00
|
|
|
when: local_route.stdout.find('{{ local_ip.stdout }}') == -1
|
|
|
|
- name: Setup route
|
2016-07-05 10:43:14 +00:00
|
|
|
shell: ip ro add {{ hostvars[groups['kube-master'][0]]['kube_service_addresses']['stdout'] }} via {{ local_ip.stdout }}
|
2016-07-04 13:13:49 +00:00
|
|
|
when: local_route.stdout.find('{{ local_ip.stdout }}') == -1
|