开发者社区> 问答> 正文

Ansible:无法重新加载sysctl:sysctl:无法stat / proc / sys / net / bridge / bridge-nf-call-iptables:没有这样的文件或目录

我正在用ansible建立kubernetes集群。尝试启用内核IP路由时出现以下错误:

Failed to reload sysctl: sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-iptables: No such file or directory
这是ansible的错误还是我的playbook有问题?


file: site.yml

description: Asentaa ja kaynnistaa kubernetes-klusterin riippuvuuksineen

resources:

- https://kubernetes.io/docs/setup/independent/install-kubeadm/

- http://michele.sciabarra.com/2018/02/12/devops/Kubernetes-with-KubeAdm-Ansible-Vagrant/

- https://docs.ansible.com/ansible/latest/modules/

- https://github.com/geerlingguy/ansible-role-kubernetes/blob/master/tasks/setup-RedHat.yml

- https://docs.docker.com/install/linux/docker-ce/centos/

author: Tuomas Toivonen

date: 30.12.2018

  • name: Asenna docker ja kubernetes

hosts: k8s-machines
become: true
become_method: sudo

roles:

- common

vars:

ip_modules:
  - ip_vs
  - ip_vs_rr
  - ip_vs_wrr
  - ip_vs_sh
  - nf_conntrack_ipv4

tasks:

- name: Poista swapfile
  tags:
    - os-settings
  mount:
    name: swap
    fstype: swap
    state: absent

- name: Disabloi swap-muisti
  tags:
    - os-settings
  command: swapoff -a
  when: ansible_swaptotal_mb > 0

- name: Konfiguroi verkkoasetukset
  tags:
    - os-settings
  command: modprobe {{ item }}
  loop: "{{ ip_modules }}"

- name: Modprobe
  tags:
    - os-settings
  lineinfile:
    path: "/etc/modules"
    line: "{{ item }}"
    create: yes
    state: present
  loop: "{{ ip_modules }}"

- name: Iptables
  tags:
    - os-settings
  sysctl:
      name: "{{ item }}"
      value: 1
      sysctl_set: yes
      state: present
      reload: yes
  loop:
    - 'net.bridge.bridge-nf-call-iptables'
    - 'net.bridge.bridge-nf-call-ip6tables'

- name: Salli IP-reititys
  sysctl:
    name: net.ipv4.ip_forward
    value: 1
    state: present
    reload: yes
    sysctl_set: yes
- name: Lisaa docker-ce -repositorio
  tags:
    - repos
  yum_repository:
    name: docker-ce
    description: docker-ce
    baseurl: https://download.docker.com/linux/centos/7/x86_64/stable/
    enabled: true
    gpgcheck: true
    repo_gpgcheck: true
    gpgkey:
      - https://download.docker.com/linux/centos/gpg
    state: present

- name: Lisaa kubernetes -repositorio
  tags:
    - repos
  yum_repository:
    name: kubernetes
    description: kubernetes
    baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
    enabled: true
    gpgcheck: true
    repo_gpgcheck: true
    gpgkey:
      - https://packages.cloud.google.com/yum/doc/yum-key.gpg
      - https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
    state: present

- name: Asenna docker-ce -paketti
  tags:
    - packages
  yum:
    name: docker-ce
    state: present

- name: Asenna NTP -paketti
  tags:
    - packages
  yum:
    name: ntp
    state: present

- name: Asenna kubernetes -paketit
  tags:
    - packages
  yum:
    name: "{{ item }}"
    state: present
  loop:
    - kubelet
    - kubeadm
    - kubectl

- name: Kaynnista palvelut
  tags:
    - services
  service: name={{ item }} state=started enabled=yes
  loop:
    - docker
    - ntpd
    - kubelet
  • name: Alusta kubernetes masterit
    become: true

become_method: sudo
hosts: k8s-masters
tags:

- cluster

tasks:

- name: kubeadm reset
  shell: "kubeadm reset -f"

- name: kubeadm init
  shell: "kubeadm init --token-ttl=0 --apiserver-advertise-address=10.0.0.101 --pod-network-cidr=20.0.0.0/8" # TODO
  register: kubeadm_out

- set_fact:
    kubeadm_join: "{{ kubeadm_out.stdout_lines[-1] }}"
  when: kubeadm_out.stdout.find("kubeadm join") != -1

- debug:
    var: kubeadm_join

- name: Aseta ymparistomuuttujat
  shell: >
      cp /etc/kubernetes/admin.conf /home/vagrant/ &&
      chown vagrant:vagrant /home/vagrant/admin.conf &&
      export KUBECONFIG=/home/vagrant/admin.conf &&
      echo export KUBECONFIG=$KUBECONFIG >> /home/vagrant/.bashrc
  • name: Konfiguroi CNI-verkko
    become: true

become_method: sudo
hosts: k8s-masters
tags:

- cluster-network

tasks:

- sysctl: name=net.bridge.bridge-nf-call-iptables value=1 state=present reload=yes sysctl_set=yes
- sysctl: name=net.bridge.bridge-nf-call-ip6tables value=1 state=present reload=yes sysctl_set=yes
- name: Asenna Flannel-plugin
  shell: >
    export KUBECONFIG=/home/vagrant/admin.conf ;
    kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

- shell: sleep 10
  • name: Alusta kubernetes workerit
    become: true

become_method: sudo
hosts: k8s-workers
tags:

- cluster

tasks:

- name: kubeadm reset
  shell: "kubeadm reset -f"

- name: kubeadm join
  tags:
    - cluster
  shell: "{{ hostvars['k8s-n1'].kubeadm_join }}" # TODO

这是完整的ansible日志

ansible-controller: Running ansible-playbook...
cd /vagrant && PYTHONUNBUFFERED=1 ANSIBLE_NOCOLOR=true ANSIBLE_CONFIG='ansible/ansible.cfg' ansible-playbook --limit="all" --inventory-file=ansible/hosts -v ansible/site.yml
Using /vagrant/ansible/ansible.cfg as config file
/vagrant/ansible/hosts did not meet host_list requirements, check plugin documentation if this is unexpected
/vagrant/ansible/hosts did not meet script requirements, check plugin documentation if this is unexpected

PLAY [Asenna docker ja kubernetes] *

TASK [Gathering Facts] *
ok: [k8s-n1]
ok: [k8s-n3]
ok: [k8s-n2]

TASK [common : Testaa] *
changed: [k8s-n3] => {"changed": true, "checksum": "6920e1826e439962050ec0ab4221719b3a045f04", "dest": "/template.test", "gid": 0, "group": "root", "md5sum": "a4f61c365318c3e23d466914fbd02687", "mode": "0644", "owner": "root", "secontext": "system_u:object_r:etc_runtime_t:s0", "size": 14, "src": "/home/vagrant/.ansible/tmp/ansible-tmp-1546760756.54-124542112178019/source", "state": "file", "uid": 0}
changed: [k8s-n2] => {"changed": true, "checksum": "6920e1826e439962050ec0ab4221719b3a045f04", "dest": "/template.test", "gid": 0, "group": "root", "md5sum": "a4f61c365318c3e23d466914fbd02687", "mode": "0644", "owner": "root", "secontext": "system_u:object_r:etc_runtime_t:s0", "size": 14, "src": "/home/vagrant/.ansible/tmp/ansible-tmp-1546760756.51-240329169302936/source", "state": "file", "uid": 0}
changed: [k8s-n1] => {"changed": true, "checksum":

展开
收起
k8s小能手 2019-01-09 12:00:43 12058 0
1 条回答
写回答
取消 提交回答
  • 整合最优质的专家资源和技术资料,问答解疑

    加载br_netfilter内核模块修复了问题。我只是将它附加到playbook vars声明中的ip_modules列表中。我正在使用Centos 7。

    2019-07-17 23:24:55
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
ANSIBLE在生产环境中的实践 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载