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.

99 lines
3.6 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 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. - name: Calico | Configure calico network pool for cloud
  25. command: "calicoctl pool add {{ kube_pods_subnet }} --ipip --nat-outgoing"
  26. run_once: true
  27. when: calico_conf.status == 404 and cloud_provider is defined and cloud_provider == True
  28. - name: Calico | Configure calico network pool
  29. command: "calicoctl pool add {{ kube_pods_subnet }}"
  30. run_once: true
  31. when: calico_conf.status == 404 and (cloud_provider is not defined or cloud_provider != True)
  32. - name: Calico | Get calico configuration from etcd
  33. uri:
  34. url: "http://127.0.0.1:2379/v2/keys/calico/v1/ipam/v4/pool"
  35. return_content: yes
  36. register: calico_pools
  37. run_once: true
  38. - name: Calico | Check if calico pool is properly configured
  39. fail:
  40. msg: 'Only one network pool must be configured and it must be the subnet {{ kube_pods_subnet }}.
  41. Please erase calico configuration and run the playbook again ("etcdctl rm --recursive /calico/v1/ipam/v4/pool")'
  42. when: ( calico_pools.json['node']['nodes'] | length > 1 ) or
  43. ( not calico_pools.json['node']['nodes'][0]['key'] | search(".*{{ kube_pods_subnet | ipaddr('network') }}.*") )
  44. run_once: true
  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 /etc/network-environment
  49. template: src=calico/network-environment.j2 dest=/etc/network-environment
  50. when: init_system == "sysvinit"
  51. - name: Calico | Write calico-node systemd init file
  52. template: src=calico/calico-node.service.j2 dest=/etc/systemd/system/calico-node.service
  53. when: init_system == "systemd"
  54. notify: restart calico-node
  55. - name: Calico | Write calico-node initd script
  56. template: src=calico/deb-calico.initd.j2 dest=/etc/init.d/calico-node owner=root mode=0755
  57. when: init_system == "sysvinit" and ansible_os_family == "Debian"
  58. notify: restart calico-node
  59. - name: Calico | Write calico-node initd script
  60. template: src=calico/rh-calico.initd.j2 dest=/etc/init.d/calico-node owner=root mode=0755
  61. when: init_system == "sysvinit" and ansible_os_family == "RedHat"
  62. notify: restart calico-node
  63. - meta: flush_handlers
  64. - name: Calico | Enable calico-node
  65. service: name=calico-node enabled=yes state=started
  66. - name: Calico | Restart calico if binary changed
  67. service:
  68. name: calico-node
  69. state: restarted
  70. when: calico_copy.stdout_lines
  71. - name: Calico | Disable node mesh
  72. shell: calicoctl bgp node-mesh off
  73. environment:
  74. ETCD_AUTHORITY: "127.0.0.1:2379"
  75. when: peer_with_router|default(false) and inventory_hostname in groups['kube-node']
  76. - name: Calico | Configure peering with router(s)
  77. shell: calicoctl node bgp peer add {{ item.router_id }} as {{ item.as }}
  78. environment:
  79. ETCD_AUTHORITY: "127.0.0.1:2379"
  80. with_items: peers
  81. when: peer_with_router|default(false) and inventory_hostname in groups['kube-node']