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.

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