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.

128 lines
4.5 KiB

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