使用Ansible将.kube配置文件从主服务器复制到所有节点

时间:2019-07-06 05:39:24

标签: kubernetes ansible

我想使用ansible sync将kube admin配置文件从Kubernetes主控主机复制到节点,但是由于缺少python解释器而失败,但是我已经在所有机器上安装了docker,没有任何问题。

查看我的任务

- name: admin conf file to nodes environment: ANSIBLE_PYTHON_INTERPRETER: python3 synchronize: src: /home/{{ansible_ssh_user}}/.kube/config dest: /home/{{ansible_ssh_user}} delegate_to: "{{item}}" loop: "{{groups.node}}"

1 个答案:

答案 0 :(得分:2)

仅当在源服务器(在您的情况下为kube master)或kube节点中启用rsync时,才可以使用syncize模块。

方法1:要从主服务器推送,需要在主服务器上启用rsync

默认情况下同步使用push模式

- hosts: nodes
  tasks:
    - name: Transfer file from master to nodes
      synchronize:
        src: /etc/kubernetes/admin.conf
        dest: $HOME/.kube/config
      delegate_to: "{{ master }}"

方法2:使用获取和复制模块

 - hosts: all
   tasks:
     - name: Fetch the file from the master to ansible
       run_once: yes
       fetch: src=/etc/kubernetes/admin.conf dest=temp/ flat=yes
       when: "{{ ansible_hostname == 'master' }}"
     - name: Copy the file from the ansible to nodes
       copy: src=temp/admin.conf dest=$HOME/.kube/config
       when: "{{ ansible_hostname != 'master' }}"

希望这会有所帮助。