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.

146 lines
4.9 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 | Determine hyperkube cni to use depending of the version of kube
  23. set_fact:
  24. use_hyperkube_cni: >
  25. {%- if kube_version | version_compare('v1.3.4','>=') -%}
  26. true
  27. {%- elif kube_version | version_compare('v1.3.4','<') -%}
  28. false
  29. {%- else -%}
  30. {{ ErrorCannotRecognizeVersion }}
  31. {%- endif -%}
  32. - name: Calico | Install calico cni bin
  33. command: rsync -piu "{{ local_release_dir }}/calico/bin/calico" "/opt/cni/bin/calico"
  34. changed_when: false
  35. when: "{{ not use_hyperkube_cni|bool }}"
  36. - name: Calico | Install calico-ipam cni bin
  37. command: rsync -piu "{{ local_release_dir }}/calico/bin/calico" "/opt/cni/bin/calico-ipam"
  38. changed_when: false
  39. when: "{{ not use_hyperkube_cni|bool }}"
  40. - name: Calico | Copy cni plugins from hyperkube
  41. command: "/usr/bin/docker run --rm -v /opt/cni/bin:/cnibindir {{ hyperkube_image_repo }}:{{ hyperkube_image_tag }} /bin/cp -r /opt/cni/bin/. /cnibindir/"
  42. register: cni_task_result
  43. until: cni_task_result.rc == 0
  44. retries: 4
  45. delay: "{{ retry_stagger | random + 3 }}"
  46. changed_when: false
  47. when: "{{ use_hyperkube_cni|bool }}"
  48. - name: Calico | wait for etcd
  49. uri: url=http://localhost:2379/health
  50. register: result
  51. until: result.status == 200
  52. retries: 10
  53. delay: 5
  54. when: inventory_hostname in groups['kube-master']
  55. - name: Calico | Check if calico network pool has already been configured
  56. uri:
  57. url: "{{ etcd_endpoint }}/v2/keys/calico/v1/ipam/v4/pool"
  58. return_content: yes
  59. status_code: 200,404
  60. register: calico_conf
  61. run_once: true
  62. - name: Calico | Define ipip pool argument
  63. run_once: true
  64. set_fact:
  65. ipip_arg: "--ipip"
  66. when: cloud_provider is defined or ipip|default(false)
  67. - name: Calico | Define nat-outgoing pool argument
  68. run_once: true
  69. set_fact:
  70. nat_arg: "--nat-outgoing"
  71. when: nat_outgoing|default(false) and not peer_with_router|default(false)
  72. - name: Calico | Define calico pool task name
  73. run_once: true
  74. set_fact:
  75. pool_task_name: "with options {{ ipip_arg|default('') }} {{ nat_arg|default('') }}"
  76. when: ipip_arg|default(false) or nat_arg|default(false)
  77. - name: Calico | Configure calico network pool {{ pool_task_name|default('') }}
  78. command: "{{ bin_dir}}/calicoctl pool add {{ kube_pods_subnet }} {{ ipip_arg|default('') }} {{ nat_arg|default('') }}"
  79. environment:
  80. NO_DEFAULT_POOLS: true
  81. run_once: true
  82. when: calico_conf.status == 404
  83. - name: Calico | Get calico configuration from etcd
  84. uri:
  85. url: "{{ etcd_endpoint }}/v2/keys/calico/v1/ipam/v4/pool"
  86. return_content: yes
  87. register: calico_pools
  88. run_once: true
  89. - name: Calico | Check if calico pool is properly configured
  90. fail:
  91. msg: 'Only one network pool must be configured and it must be the subnet {{ kube_pods_subnet }}.
  92. Please erase calico configuration and run the playbook again ("etcdctl rm --recursive /calico/v1/ipam/v4/pool")'
  93. when: ( calico_pools.json['node']['nodes'] | length > 1 ) or
  94. ( not calico_pools.json['node']['nodes'][0]['key'] | search(".*{{ kube_pods_subnet | ipaddr('network') }}.*") )
  95. run_once: true
  96. - name: Calico | Write /etc/network-environment
  97. template: src=network-environment.j2 dest=/etc/network-environment
  98. when: ansible_service_mgr in ["sysvinit","upstart"]
  99. - name: Calico | Write calico-node systemd init file
  100. template: src=calico-node.service.j2 dest=/etc/systemd/system/calico-node.service
  101. when: ansible_service_mgr == "systemd"
  102. notify: restart calico-node
  103. - name: Calico | Write calico-node initd script
  104. template: src=deb-calico.initd.j2 dest=/etc/init.d/calico-node owner=root mode=0755
  105. when: ansible_service_mgr in ["sysvinit","upstart"] and ansible_os_family == "Debian"
  106. notify: restart calico-node
  107. - name: Calico | Write calico-node initd script
  108. template: src=rh-calico.initd.j2 dest=/etc/init.d/calico-node owner=root mode=0755
  109. when: ansible_service_mgr in ["sysvinit","upstart"] and ansible_os_family == "RedHat"
  110. notify: restart calico-node
  111. - meta: flush_handlers
  112. - name: Calico | Enable calico-node
  113. service:
  114. name: calico-node
  115. state: started
  116. enabled: yes
  117. - name: Calico | Disable node mesh
  118. shell: "{{ bin_dir }}/calicoctl bgp node-mesh off"
  119. when: peer_with_router|default(false) and inventory_hostname in groups['kube-node']
  120. - name: Calico | Configure peering with router(s)
  121. shell: "{{ bin_dir }}/calicoctl node bgp peer add {{ item.router_id }} as {{ item.as }}"
  122. with_items: peers
  123. when: peer_with_router|default(false) and inventory_hostname in groups['kube-node']