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.

121 lines
4.3 KiB

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