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.

125 lines
4.1 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. ---
  2. - name: Calico | Set docker daemon options
  3. template:
  4. src: docker
  5. dest: "/etc/default/docker"
  6. owner: root
  7. group: root
  8. mode: 0644
  9. notify:
  10. - restart docker
  11. - name: Calico | Write docker.service systemd file
  12. template:
  13. src: systemd-docker.service
  14. dest: /lib/systemd/system/docker.service
  15. notify: restart docker
  16. when: init_system == "systemd"
  17. - meta: flush_handlers
  18. - name: Calico | Install calicoctl bin
  19. command: rsync -piu "{{ local_release_dir }}/calico/bin/calicoctl" "{{ bin_dir }}/calicoctl"
  20. register: calico_copy
  21. changed_when: false
  22. - name: Calico | Install calico cni bin
  23. command: rsync -piu "{{ local_release_dir }}/calico/bin/calico" "/opt/cni/bin/calico"
  24. changed_when: false
  25. - name: Calico | Install calico-ipam cni bin
  26. command: rsync -piu "{{ local_release_dir }}/calico/bin/calico" "/opt/cni/bin/calico-ipam"
  27. changed_when: false
  28. - name: Calico | install calicoctl
  29. file: path={{ bin_dir }}/calicoctl mode=0755 state=file
  30. - name: Calico | Create calicoctl symlink (needed by kubelet)
  31. file:
  32. src: /usr/local/bin/calicoctl
  33. dest: /usr/bin/calicoctl
  34. state: link
  35. - name: Calico | wait for etcd
  36. wait_for:
  37. port: 2379
  38. when: inventory_hostname in groups['kube-master']
  39. - name: Calico | Check if calico network pool has already been configured
  40. uri:
  41. url: "http://127.0.0.1:2379/v2/keys/calico/v1/ipam/v4/pool"
  42. return_content: yes
  43. status_code: 200,404
  44. register: calico_conf
  45. run_once: true
  46. - name: Calico | Configure calico network pool for cloud
  47. command: "calicoctl pool add {{ kube_pods_subnet }} --ipip --nat-outgoing"
  48. run_once: true
  49. when: calico_conf.status == 404 and cloud_provider is defined and cloud_provider == True
  50. - name: Calico | Configure calico network pool
  51. command: "calicoctl pool add {{ kube_pods_subnet }}"
  52. run_once: true
  53. when: calico_conf.status == 404 and (cloud_provider is not defined or cloud_provider != True)
  54. - name: Calico | Get calico configuration from etcd
  55. uri:
  56. url: "http://127.0.0.1:2379/v2/keys/calico/v1/ipam/v4/pool"
  57. return_content: yes
  58. register: calico_pools
  59. run_once: true
  60. - name: Calico | Check if calico pool is properly configured
  61. fail:
  62. msg: 'Only one network pool must be configured and it must be the subnet {{ kube_pods_subnet }}.
  63. Please erase calico configuration and run the playbook again ("etcdctl rm --recursive /calico/v1/ipam/v4/pool")'
  64. when: ( calico_pools.json['node']['nodes'] | length > 1 ) or
  65. ( not calico_pools.json['node']['nodes'][0]['key'] | search(".*{{ kube_pods_subnet | ipaddr('network') }}.*") )
  66. run_once: true
  67. - name: Calico | Write /etc/network-environment
  68. template: src=network-environment.j2 dest=/etc/network-environment
  69. when: init_system == "sysvinit"
  70. - name: Calico | Write calico-node systemd init file
  71. template: src=calico-node.service.j2 dest=/etc/systemd/system/calico-node.service
  72. when: init_system == "systemd"
  73. notify: restart calico-node
  74. - name: Calico | Write calico-node initd script
  75. template: src=deb-calico.initd.j2 dest=/etc/init.d/calico-node owner=root mode=0755
  76. when: init_system == "sysvinit" and ansible_os_family == "Debian"
  77. notify: restart calico-node
  78. - name: Calico | Write calico-node initd script
  79. template: src=rh-calico.initd.j2 dest=/etc/init.d/calico-node owner=root mode=0755
  80. when: init_system == "sysvinit" and ansible_os_family == "RedHat"
  81. notify: restart calico-node
  82. - meta: flush_handlers
  83. - name: Calico | Enable calico-node
  84. service:
  85. name: calico-node
  86. state: started
  87. enabled: yes
  88. - name: Calico | Restart calico if binary changed
  89. service:
  90. name: calico-node
  91. state: restarted
  92. when: calico_copy.stdout_lines
  93. - name: Calico | Disable node mesh
  94. shell: calicoctl bgp node-mesh off
  95. environment:
  96. ETCD_AUTHORITY: "127.0.0.1:2379"
  97. when: peer_with_router|default(false) and inventory_hostname in groups['kube-node']
  98. - name: Calico | Configure peering with router(s)
  99. shell: calicoctl node bgp peer add {{ item.router_id }} as {{ item.as }}
  100. environment:
  101. ETCD_AUTHORITY: "127.0.0.1:2379"
  102. with_items: peers
  103. when: peer_with_router|default(false) and inventory_hostname in groups['kube-node']