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.

101 lines
3.4 KiB

  1. ---
  2. - name: Macvlan | Retrieve Pod Cidr
  3. command: "{{ bin_dir }}/kubectl get nodes {{ kube_override_hostname | default(inventory_hostname) }} -o jsonpath='{.spec.podCIDR}'"
  4. changed_when: false
  5. register: node_pod_cidr_cmd
  6. delegate_to: "{{ groups['kube-master'][0] }}"
  7. - name: Macvlan | set node_pod_cidr
  8. set_fact:
  9. node_pod_cidr={{ node_pod_cidr_cmd.stdout }}
  10. - name: Macvlan | Retrieve default gateway network interface
  11. become: false
  12. raw: ip -4 route list 0/0 | sed 's/.*dev \([[:alnum:]]*\).*/\1/'
  13. changed_when: false
  14. register: node_default_gateway_interface_cmd
  15. - name: Macvlan | set node_default_gateway_interface
  16. set_fact:
  17. node_default_gateway_interface={{ node_default_gateway_interface_cmd.stdout | trim }}
  18. - name: Macvlan | Install network gateway interface on debian
  19. template:
  20. src: debian-network-macvlan.cfg.j2
  21. dest: /etc/network/interfaces.d/60-mac0.cfg
  22. notify: Macvlan | restart network
  23. when: ansible_os_family in ["Debian"]
  24. - name: Macvlan | Install macvlan script on centos
  25. copy:
  26. src: "{{ item }}"
  27. dest: /etc/sysconfig/network-scripts/
  28. owner: root
  29. group: root
  30. mode: "0755"
  31. with_fileglob:
  32. - files/*
  33. when: ansible_os_family in ["CentOS","RedHat"]
  34. - name: Macvlan | Install post-up script on centos
  35. copy:
  36. src: "files/ifup-local"
  37. dest: /sbin/
  38. owner: root
  39. group: root
  40. mode: "0755"
  41. when: ansible_os_family in ["CentOS","RedHat"] and enable_nat_default_gateway
  42. - name: Macvlan | Install network gateway interface on centos
  43. template:
  44. src: "{{ item.src }}.j2"
  45. dest: "/etc/sysconfig/network-scripts/{{ item.dst }}"
  46. with_items:
  47. - {src: centos-network-macvlan.cfg, dst: ifcfg-mac0 }
  48. - {src: centos-routes-macvlan.cfg, dst: route-mac0 }
  49. - {src: centos-postup-macvlan.cfg, dst: post-up-mac0 }
  50. notify: Macvlan | restart network
  51. when: ansible_os_family in ["CentOS","RedHat"]
  52. - name: Macvlan | Install service nat via gateway on Flatcar Container Linux
  53. template:
  54. src: coreos-service-nat_ouside.j2
  55. dest: /etc/systemd/system/enable_nat_ouside.service
  56. when: ansible_os_family in ["Flatcar Container Linux by Kinvolk"] and enable_nat_default_gateway
  57. - name: Macvlan | Enable service nat via gateway on Flatcar Container Linux
  58. command: "{{ item }}"
  59. with_items:
  60. - systemctl daemon-reload
  61. - systemctl enable enable_nat_ouside.service
  62. when: ansible_os_family in ["Flatcar Container Linux by Kinvolk"] and enable_nat_default_gateway
  63. - name: Macvlan | Install network gateway interface on Flatcar Container Linux
  64. template:
  65. src: "{{ item.src }}.j2"
  66. dest: "/etc/systemd/network/{{ item.dst }}"
  67. with_items:
  68. - {src: coreos-device-macvlan.cfg, dst: macvlan.netdev }
  69. - {src: coreos-interface-macvlan.cfg, dst: output.network }
  70. - {src: coreos-network-macvlan.cfg, dst: macvlan.network }
  71. notify: Macvlan | restart network
  72. when: ansible_os_family in ["Flatcar Container Linux by Kinvolk"]
  73. - name: Macvlan | Install cni definition for Macvlan
  74. template:
  75. src: 10-macvlan.conf.j2
  76. dest: /etc/cni/net.d/10-macvlan.conf
  77. - name: Macvlan | Install loopback definition for Macvlan
  78. template:
  79. src: 99-loopback.conf.j2
  80. dest: /etc/cni/net.d/99-loopback.conf
  81. - name: Enable net.ipv4.conf.all.arp_notify in sysctl
  82. sysctl:
  83. name: net.ipv4.conf.all.arp_notify
  84. value: 1
  85. sysctl_set: yes
  86. sysctl_file: "{{ sysctl_file_path }}"
  87. state: present
  88. reload: yes