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.

75 lines
2.5 KiB

9 years ago
9 years ago
  1. ---
  2. - name: Flannel | Set Flannel etcd configuration
  3. command: |-
  4. {{ bin_dir }}/etcdctl --peers={{ etcd_access_addresses }} \
  5. set /{{ cluster_name }}/network/config \
  6. '{ "Network": "{{ kube_pods_subnet }}", "SubnetLen": {{ kube_network_node_prefix }}, "Backend": { "Type": "{{ flannel_backend_type }}" } }'
  7. delegate_to: "{{groups['etcd'][0]}}"
  8. run_once: true
  9. - name: Flannel | Create flannel pod manifest
  10. template:
  11. src: flannel-pod.yml
  12. dest: /etc/kubernetes/manifests/flannel-pod.manifest
  13. notify: delete default docker bridge
  14. - name: Flannel | Wait for flannel subnet.env file presence
  15. wait_for:
  16. path: /run/flannel/subnet.env
  17. delay: 5
  18. timeout: 600
  19. - name: Flannel | Get flannel_subnet from subnet.env
  20. shell: cat /run/flannel/subnet.env | awk -F'=' '$1 == "FLANNEL_SUBNET" {print $2}'
  21. register: flannel_subnet_output
  22. changed_when: false
  23. - set_fact:
  24. flannel_subnet: "{{ flannel_subnet_output.stdout }}"
  25. - name: Flannel | Get flannel_mtu from subnet.env
  26. shell: cat /run/flannel/subnet.env | awk -F'=' '$1 == "FLANNEL_MTU" {print $2}'
  27. register: flannel_mtu_output
  28. changed_when: false
  29. - set_fact:
  30. flannel_mtu: "{{ flannel_mtu_output.stdout }}"
  31. - set_fact:
  32. docker_options_file: >-
  33. {%- if ansible_os_family == "Debian" -%}/etc/default/docker{%- elif ansible_os_family == "RedHat" -%}/etc/sysconfig/docker{%- endif -%}
  34. - set_fact:
  35. docker_options_name: >-
  36. {%- if ansible_os_family == "Debian" -%}DOCKER_OPTS{%- elif ansible_os_family == "RedHat" -%}other_args{%- endif -%}
  37. - set_fact:
  38. docker_network_options: '"--bip={{ flannel_subnet }} --mtu={{ flannel_mtu }}"'
  39. - name: Flannel | Remove non-systemd docker daemon network options that don't match desired line
  40. lineinfile:
  41. dest: "{{ docker_options_file }}"
  42. regexp: "^DOCKER_NETWORK_OPTIONS=(?!{{ docker_network_options|regex_escape() }})"
  43. state: absent
  44. when: ansible_service_mgr in ["sysvinit","upstart"]
  45. - name: Flannel | Set non-systemd docker daemon network options
  46. lineinfile:
  47. dest: "{{ docker_options_file }}"
  48. line: DOCKER_NETWORK_OPTIONS={{ docker_network_options }}
  49. insertbefore: ^{{ docker_options_name }}=
  50. owner: root
  51. group: root
  52. mode: 0644
  53. notify:
  54. - restart docker
  55. when: ansible_service_mgr in ["sysvinit","upstart"]
  56. - name: Flannel | Create docker network systemd drop-in
  57. template:
  58. src: flannel-options.conf.j2
  59. dest: "/etc/systemd/system/docker.service.d/flannel-options.conf"
  60. notify:
  61. - restart docker
  62. when: ansible_service_mgr == "systemd"
  63. - meta: flush_handlers