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.

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