main.yml 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. - name: Get Iptables Version
  2. shell: iptables --version
  3. ignore_errors: true
  4. register: iptables_version
  5. - block:
  6. - name: Show Iptables Version Info
  7. debug:
  8. msg: "Current iptables version info: {{ iptables_version.stdout }}. Building iptables to enable legacy mode. "
  9. - name: Check if local file exists
  10. stat:
  11. path: "{{ iptables_local_path }}"
  12. register: file_stat
  13. - name: Check Md5 Checksum Of Local File
  14. block:
  15. - name: Get MD5 checksum of local file
  16. command: "md5sum {{ iptables_local_path }}"
  17. register: md5sum_output
  18. - debug: var=md5sum_output
  19. - debug: msg="Compare MD5 checksum with expected value"
  20. when: md5sum_output.stdout.split()[0] != iptables_md5sum
  21. ignore_errors: true
  22. failed_when: false
  23. when: file_stat.stat.exists
  24. - name: Download File From Url If Local File Doesn't Exist Or Has Incorrect Checksum
  25. get_url:
  26. url: "{{ iptables_download_url }}"
  27. dest: "{{ iptables_local_path }}"
  28. when: not file_stat.stat.exists or md5sum_output.stdout.split()[0] != iptables_md5sum
  29. - name: Online Repo Iptables
  30. shell: |
  31. if grep yunion-repo-iptables /etc/yum.repos.d/yunion.repo; then
  32. exit 0
  33. fi
  34. cat >> /etc/yum.repos.d/yunion.repo <<EOF_MISC
  35. [yunion-repo-iptables]
  36. name=Packages for Yunion Multi-Cloud Platform Iptables-
  37. baseurl=https://iso.yunion.cn/{{ ansible_distribution| replace(' ','') | lower }}/{{ ansible_distribution_version }}/iptables/{{ ansible_architecture }}/
  38. sslverify=0
  39. failovermethod=priority
  40. enabled=1
  41. gpgcheck=0
  42. priority=2
  43. EOF_MISC
  44. dnf --disablerepo='*' --enablerepo='yunion*' makecache
  45. become: yes
  46. args:
  47. executable: /bin/bash
  48. - name: Install packages
  49. package:
  50. name: "{{ package_item }}"
  51. state: present
  52. with_items:
  53. - gcc
  54. - make
  55. - kernel-devel
  56. loop_control:
  57. loop_var: package_item
  58. tags:
  59. - iptables
  60. - name: Build Iptables
  61. shell: |
  62. cd /tmp
  63. tar xf iptables-1.8.9.tar.xz
  64. cd iptables-1.8.9
  65. ./configure --disable-nftables --prefix=/usr &>/dev/null && make -j &>/dev/null && make install &>/dev/null
  66. iptables --version | grep -qi legacy && rm -rf /tmp/iptables*
  67. iptables --version
  68. register: iptables_legacy_version
  69. become: true
  70. args:
  71. executable: /bin/bash
  72. tags:
  73. - iptables
  74. - debug: var=iptables_legacy_version.stdout
  75. when:
  76. - not (iptables_version.stdout | default('') | regex_search('legacy', ignorecase=True))