From 873876a3f0a624b885797369675f9154bdcfb9e3 Mon Sep 17 00:00:00 2001 From: gjmzj Date: Sun, 17 Oct 2021 10:33:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:prepare=E9=98=B6=E6=AE=B5=E7=9A=84=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- roles/prepare/tasks/centos.yml | 1 + roles/prepare/tasks/common.yml | 14 ++++--------- roles/prepare/tasks/main.yml | 20 +++++++++++++------ roles/prepare/tasks/ubuntu.yml | 1 + .../prepare/templates/10-k8s-modules.conf.j2 | 2 ++ 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/roles/prepare/tasks/centos.yml b/roles/prepare/tasks/centos.yml index a330c03..23f8202 100644 --- a/roles/prepare/tasks/centos.yml +++ b/roles/prepare/tasks/centos.yml @@ -22,6 +22,7 @@ - socat # 用于port forwarding state: present when: 'INSTALL_SOURCE != "offline"' + ignore_errors: true # 离线安装基础软件包 - import_tasks: offline.yml diff --git a/roles/prepare/tasks/common.yml b/roles/prepare/tasks/common.yml index d211e49..99923b0 100644 --- a/roles/prepare/tasks/common.yml +++ b/roles/prepare/tasks/common.yml @@ -14,15 +14,6 @@ set_fact: KERNEL_VER: "{{ ansible_kernel.split('-')[0].split('.')[0]|int + ansible_kernel.split('-')[0].split('.')[1]|int/100 }}" -#- name: 设置 nf_conntrack 模块名 -# set_fact: NF_CONNTRACK="nf_conntrack" -# when: "KERNEL_VER|float >= 4.19" - -#- name: 设置 nf_conntrack_ipv4 模块名 -# set_fact: NF_CONNTRACK="nf_conntrack_ipv4" -# when: "KERNEL_VER|float < 4.19" - -# 若提示nf_conntrack_ipv4模块不存在,错误可以忽略 - name: 加载内核模块 modprobe: name={{ item }} state=present with_items: @@ -32,9 +23,12 @@ - ip_vs_wrr - ip_vs_sh - nf_conntrack - - nf_conntrack_ipv4 ignore_errors: true +- name: 尝试加载nf_conntrack_ipv4 + shell: 'modprobe nf_conntrack_ipv4 || echo "NoFound"' + register: NF_CONNTRACK_IPV4 + - name: 启用systemd自动加载模块服务 service: name=systemd-modules-load enabled=yes diff --git a/roles/prepare/tasks/main.yml b/roles/prepare/tasks/main.yml index e909017..1232a86 100644 --- a/roles/prepare/tasks/main.yml +++ b/roles/prepare/tasks/main.yml @@ -1,10 +1,10 @@ # 系统基础软件环境 -#- name: apt更新缓存刷新 -# apt: update_cache=yes cache_valid_time=72000 -# ignore_errors: true -# when: -# - 'ansible_distribution in ["Ubuntu","Debian"]' -# - 'INSTALL_SOURCE != "offline"' +- name: apt更新缓存刷新 + apt: update_cache=yes cache_valid_time=72000 + ignore_errors: true + when: + - 'ansible_distribution in ["Ubuntu","Debian"]' + - 'INSTALL_SOURCE != "offline"' - import_tasks: ubuntu.yml when: 'ansible_distribution in ["Ubuntu","Debian"]' @@ -23,6 +23,14 @@ - /root/.kube - /opt/kube/images +# 某些系统没有/usr/bin/python,需要配置一个软链接,否则connection: local的任务会失败 +# 如果仍旧出现任务失败,重新执行一遍即可 https://github.com/ansible/ansible/issues/64903 +- name: symlink /usr/bin/python -> /usr/bin/python3 + raw: | + if [ -f /usr/bin/python3 ] && [ ! -f /usr/bin/python ]; then + ln --symbolic /usr/bin/python3 /usr/bin/python; + fi + - name: 写入环境变量$PATH lineinfile: dest: ~/.bashrc diff --git a/roles/prepare/tasks/ubuntu.yml b/roles/prepare/tasks/ubuntu.yml index c1effb7..eea170c 100644 --- a/roles/prepare/tasks/ubuntu.yml +++ b/roles/prepare/tasks/ubuntu.yml @@ -26,6 +26,7 @@ - socat # 用于port forwarding state: present when: 'INSTALL_SOURCE != "offline"' + ignore_errors: true # 离线安装基础软件包 - import_tasks: offline.yml diff --git a/roles/prepare/templates/10-k8s-modules.conf.j2 b/roles/prepare/templates/10-k8s-modules.conf.j2 index 9429260..613416a 100644 --- a/roles/prepare/templates/10-k8s-modules.conf.j2 +++ b/roles/prepare/templates/10-k8s-modules.conf.j2 @@ -4,4 +4,6 @@ ip_vs_rr ip_vs_wrr ip_vs_sh nf_conntrack +{% if 'NoFound' not in NF_CONNTRACK_IPV4.stdout %} nf_conntrack_ipv4 +{% endif %}