You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
3.2 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. ---
  2. - name: Calico | Install calicoctl bin
  3. command: cp -pf "{{ local_release_dir }}/calico/bin/calicoctl" "{{ bin_dir }}/calicoctl"
  4. changed_when: false
  5. notify: restart calico-node
  6. - name: Calico | install calicoctl
  7. file: path={{ bin_dir }}/calicoctl mode=0755 state=file
  8. - name: Calico | Create calicoctl symlink (needed by kubelet)
  9. file:
  10. src: /usr/local/bin/calicoctl
  11. dest: /usr/bin/calicoctl
  12. state: link
  13. - wait_for:
  14. port: 2379
  15. when: inventory_hostname in groups['kube-master']
  16. - name: Calico | Check if calico network pool has already been configured
  17. uri:
  18. url: "http://127.0.0.1:2379/v2/keys/calico/v1/ipam/v4/pool"
  19. return_content: yes
  20. status_code: 200,404
  21. register: calico_conf
  22. run_once: true
  23. delegate_to: "{{ groups['etcd'][0] }}"
  24. - name: Calico | Configure calico network pool
  25. shell: calicoctl pool add {{ kube_pods_subnet }}
  26. run_once: true
  27. when: calico_conf.status == 404
  28. delegate_to: "{{ groups['etcd'][0] }}"
  29. - name: Calico | Get calico configuration from etcd
  30. uri:
  31. url: "http://127.0.0.1:2379/v2/keys/calico/v1/ipam/v4/pool"
  32. return_content: yes
  33. register: calico_pools
  34. run_once: true
  35. delegate_to: "{{ groups['etcd'][0] }}"
  36. - name: Calico | Check if calico pool is properly configured
  37. fail:
  38. msg: 'Only one network pool must be configured and it must be the subnet {{ kube_pods_subnet }}.
  39. Please erase calico configuration and run the playbook again ("etcdctl rm --recursive /calico/v1/ipam/v4/pool")'
  40. when: ( calico_pools.json['node']['nodes'] | length > 1 ) or
  41. ( not calico_pools.json['node']['nodes'][0]['key'] | search(".*{{ kube_pods_subnet | ipaddr('network') }}.*") )
  42. run_once: true
  43. delegate_to: "{{ groups['etcd'][0] }}"
  44. - name: Calico | Write calico-node configuration
  45. template: src=calico/calico.conf.j2 dest=/usr/libexec/kubernetes/kubelet-plugins/net/exec/calico/calico_kubernetes.ini
  46. notify: restart calico-node
  47. - name: Calico | Write calico-node systemd init file
  48. template: src=calico/calico-node.service.j2 dest=/etc/systemd/system/calico-node.service
  49. when: init_system == "systemd"
  50. notify: restart systemd-calico-node
  51. - name: Calico | Write calico-node initd script
  52. template: src=calico/deb-calico.initd.j2 dest=/etc/init.d/calico-node owner=root mode=755
  53. when: init_system == "sysvinit" and ansible_os_family == "Debian"
  54. notify: restart calico-node
  55. - name: Calico | Write calico-node initd script
  56. template: src=calico/rh-calico.initd.j2 dest=/etc/init.d/calico-node owner=root mode=755
  57. when: init_system == "sysvinit" and ansible_os_family == "RedHat"
  58. notify: restart calico-node
  59. - name: Calico | Enable calico-node
  60. service: name=calico-node enabled=yes state=started
  61. - name: Calico | Disable node mesh
  62. shell: calicoctl bgp node-mesh off
  63. environment:
  64. ETCD_AUTHORITY: "{{ groups['etcd'][0] }}:2379"
  65. when: peer_with_router|default(false) and inventory_hostname in groups['kube-node']
  66. - name: Calico | Configure peering with router(s)
  67. shell: calicoctl node bgp peer add {{ item.router_id }} as {{ item.as }}
  68. environment:
  69. ETCD_AUTHORITY: "{{ groups['etcd'][0] }}:2379"
  70. with_items: peers
  71. when: peer_with_router|default(false) and inventory_hostname in groups['kube-node']