Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error connecting: Error while fetching server API version: Ansible

I'm very new at Ansible. I've run following ansible PlayBook and found those errors:

---
- 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

Error message:

FAILED! => {"changed": false, "msg": "Error connecting: Error while fetching server API version: ('Connection aborted.', error(2, 'No such file or directory'))"}

And here is my folder structure:

.
├── ansible.cfg
├── docker
│   └── Dockerfile
├── hosts
├── main.retry
├── main.yml

I'm confused that docker folder is already inside my local but don't know why I encountered those error message.

like image 880
PPShein Avatar asked Dec 20 '18 05:12

PPShein


1 Answers

I've found solution is Docker daemon is not working after Docker was installed by Ansible. It's required to add following command in my play board.

---
- 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
like image 193
PPShein Avatar answered Oct 24 '22 18:10

PPShein