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.

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