连接错误:提取服务器API版本时出错:Ansible

时间:2018-12-20 05:31:57

标签: docker amazon-ec2 ansible

我在Ansible非常陌生。我一直在跟随ansible PlayBook并发现这些错误:

len(df) - df[1].isna().sum()

错误消息:

  

失败! => {“已更改”:false,“ msg”:“连接错误:错误,而   正在获取服务器API版本:(“连接已中止。”,错误(2,“否”   文件或目录'))“}

这是我的文件夹结构:

---
- hosts: webservers
  remote_user: linx
  become: yes
  become_method: sudo
  tasks:

    - name: install docker-py
      pip: name=docker-py

    - name: Build Docker image from Dockerfile
      docker_image:
        name: web
        path: docker
        state: build

    - name: Running the container
      docker_container:
        image: web:latest
        path: docker
        state: running

    - name: Check if container is running
      shell: docker ps

我很困惑. ├── ansible.cfg ├── docker │   └── Dockerfile ├── hosts ├── main.retry ├── main.yml 文件夹已经在我的本地文件夹中,但不知道为什么会遇到这些错误消息。

1 个答案:

答案 0 :(得分:1)

我发现解决方案是Docker安装了Docker后,Ansible守护程序无法工作。必须在游戏板上添加以下命令。

---
- hosts: webservers
  remote_user: ec2-user
  become: yes
  become_method: sudo
  tasks:
    - name: install docker
      yum: name=docker

    **- name: Ensure service is enabled
      command: service docker restart***

    - name: copying file to remote
      copy:
        src: ./docker
        dest: /home/ec2-user/docker
    - name: Build Docker image from Dockerfile
      docker_image:
        name: web
        path: /home/ec2-user/docker
        state: build
    - name: Running the container
      docker_container:
        image: web:latest
        name: web
    - name: Check if container is running
      shell: docker ps