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.

129 lines
4.4 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. - meta: flush_handlers
  13. - name: Calico | Install calicoctl container script
  14. template:
  15. src: calicoctl-container.j2
  16. dest: "{{ bin_dir }}/calicoctl"
  17. mode: 0755
  18. owner: root
  19. group: root
  20. changed_when: false
  21. notify: restart calico-node
  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. when: not use_hyperkube_cni
  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. when: not use_hyperkube_cni
  30. - name: Calico | Copy cni plugins from hyperkube
  31. command: "/usr/bin/docker run --rm -v /opt/cni/bin:/cnibindir {{ hyperkube_image_repo }}:{{ hyperkube_image_tag }} /bin/cp -r /opt/cni/bin/. /cnibindir/"
  32. changed_when: false
  33. when: use_hyperkube_cni
  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 | Define ipip pool argument
  49. run_once: true
  50. set_fact:
  51. ipip_arg: "--ipip"
  52. when: cloud_provider is defined or ipip|default(false)
  53. - name: Calico | Define nat-outgoing pool argument
  54. run_once: true
  55. set_fact:
  56. nat_arg: "--nat-outgoing"
  57. when: nat_outgoing|default(false) and not peer_with_router|default(false)
  58. - name: Calico | Define calico pool task name
  59. run_once: true
  60. set_fact:
  61. pool_task_name: "with options {{ ipip_arg|default('') }} {{ nat_arg|default('') }}"
  62. when: ipip_arg|default(false) or nat_arg|default(false)
  63. - name: Calico | Configure calico network pool {{ pool_task_name|default('') }}
  64. command: "{{ bin_dir}}/calicoctl pool add {{ kube_pods_subnet }} {{ ipip_arg|default('') }} {{ nat_arg|default('') }}"
  65. run_once: true
  66. when: calico_conf.status == 404
  67. - name: Calico | Get calico configuration from etcd
  68. uri:
  69. url: "{{ etcd_endpoint }}/v2/keys/calico/v1/ipam/v4/pool"
  70. return_content: yes
  71. register: calico_pools
  72. run_once: true
  73. - name: Calico | Check if calico pool is properly configured
  74. fail:
  75. msg: 'Only one network pool must be configured and it must be the subnet {{ kube_pods_subnet }}.
  76. Please erase calico configuration and run the playbook again ("etcdctl rm --recursive /calico/v1/ipam/v4/pool")'
  77. when: ( calico_pools.json['node']['nodes'] | length > 1 ) or
  78. ( not calico_pools.json['node']['nodes'][0]['key'] | search(".*{{ kube_pods_subnet | ipaddr('network') }}.*") )
  79. run_once: true
  80. - name: Calico | Write /etc/network-environment
  81. template: src=network-environment.j2 dest=/etc/network-environment
  82. when: ansible_service_mgr in ["sysvinit","upstart"]
  83. - name: Calico | Write calico-node systemd init file
  84. template: src=calico-node.service.j2 dest=/etc/systemd/system/calico-node.service
  85. when: ansible_service_mgr == "systemd"
  86. notify: restart calico-node
  87. - name: Calico | Write calico-node initd script
  88. template: src=deb-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 == "Debian"
  90. notify: restart calico-node
  91. - name: Calico | Write calico-node initd script
  92. template: src=rh-calico.initd.j2 dest=/etc/init.d/calico-node owner=root mode=0755
  93. when: ansible_service_mgr in ["sysvinit","upstart"] and ansible_os_family == "RedHat"
  94. notify: restart calico-node
  95. - meta: flush_handlers
  96. - name: Calico | Enable calico-node
  97. service:
  98. name: calico-node
  99. state: started
  100. enabled: yes
  101. - name: Calico | Disable node mesh
  102. shell: "{{ bin_dir }}/calicoctl bgp node-mesh off"
  103. when: peer_with_router|default(false) and inventory_hostname in groups['kube-node']
  104. - name: Calico | Configure peering with router(s)
  105. shell: "{{ bin_dir }}/calicoctl node bgp peer add {{ item.router_id }} as {{ item.as }}"
  106. with_items: peers
  107. when: peer_with_router|default(false) and inventory_hostname in groups['kube-node']