“在 PATH 中找不到 docker 命令”对于“ansible_connection:community.docker.docker”,但不适用于“docker_container”和其他

问题描述 投票:0回答:1

首先,这篇文章与其他关于此错误的文章不同,因为它首先起作用,然后不起作用。 当从 ansible playbook 中提取并安装映像并将任务委托给我的远程 docker 主机时,一切正常,但是当尝试使用同一集合(community.docker)中的连接插件时 我明白了

fatal: [localhost -> instance-139.xxx.xxx.xxx]: FAILED! => {
    "msg": "docker command not found in PATH"
}

我看过一两篇类似的帖子,但他们都谈到了不同的问题,即用户可能缺乏访问权限。对于我的情况,用户是完全相同的(root)。我想知道为什么它适用于除了连接插件之外的所有东西。

Error: fatal: [localhost -> instance-139.xxx.xxx.xxx]: FAILED! => {
    "msg": "docker command not found in PATH"
}

我的 ansible 剧本的删节版本

- name: Create an API instance
  hosts: localhost
  gather_facts: no
  collections:
    - linode.cloud
    - community.docker
  tasks:
    - block:
      - name: Linode IPS
        debug:
          msg: "{{ linode_ips }}"
      - name: Update apt and install dependencies
        apt:
          update_cache: yes
          name: "{{ item }}"
          force_apt_get: yes
          state: present
        loop:
          - apt-transport-https
          - ca-certificates
          - curl
          - gzip
          - software-properties-common
          
      - name: Add Docker GPG key
        apt_key:
          url: https://download.docker.com/linux/ubuntu/gpg
          state: present

      - name: Add Docker repository
        apt_repository:
          repo: deb https://download.docker.com/linux/ubuntu focal stable
          state: present

      - name: Install Docker
        apt:
          name: docker-ce
          state: present
          force_apt_get: yes
          update_cache: yes

      - name: Start and enable Docker
        systemd:
          name: docker
          state: started
          enabled: yes

      - debug:
          msg: "Registry: docker.registry.aksantinet.com/{{ host_group }}"

      - name: Pull the image from the registry
        community.docker.docker_image:
          name: "docker.registry.aksantinet.com/{{ host_group }}"
          tag: latest
          source: pull

      - name: Run Docker container
        community.docker.docker_container:
          name: "{{ container_name }}"
          image: "docker.registry.aksantinet.com/{{ host_group }}"
          network_mode: host
          state: started
          capabilities:
            - NET_ADMIN
          devices:
            - /dev/net/tun:/dev/net/tun
          privileged: yes 
        become: yes
        
      - name: Copy LetsEncrypt from ansible to Docker
        become: yes
        block:
        - lineinfile:
          path: "test"
          line: "example"
          create: yes
          state: present
        - ansible.builtin.copy:
            src: /etc/letsencrypt/
            dest: /etc/letsencrypt/
        - shell: nginx
        vars:
          ansible_docker_host: "{{ container_name }}"
          ansible_connection: docker
      - name: Instance added
        debug: 
          msg: "Addded instance at {{ linode_ip }}"
      delegate_to: "instance-{{ linode_ip }}"  
docker ansible
1个回答
0
投票

所以我们的 docker 连接插件假设 docker 实例与 ansible 在同一台机器上运行。从 larsks 评论中,我假设我只需要在我的机器上安装 docker-cli 和 docker-ce,并且它仍然会以某种方式在我的 delegate_to 主机上执行 docker 命令,但事实并非如此。

the 'docker' connection plugin assumes the host running ansible contains the docker instances
来自我通过查找
ansible docker connection delegate to
找到的github帖子,当你查看实际给出的错误时,这是一个几乎不相关的搜索。

© www.soinside.com 2019 - 2024. All rights reserved.