Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible: Failed to import docker or docker-py - No module named docker

I've installed Docker and Ansible to my AWS Ec2 Linux as follow:

sudo yum update -y
sudo yum install docker -v
sudo service docker start

sudo yum-config-manager --enable epel
sudo yum repolist
sudo yum install ansible

I've found following error message when I've tried to pull docker images to my AWS Ec2 Linux with ansible.

fatal: [127.0.0.1]: FAILED! => {"changed": false, "msg": "Failed to import docker or docker-py - No module named docker. Try `pip install docker` or `pip install docker-py` (Python 2.6)"}

Docker version

Client:
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        e68fc7a215d7133c34aa18e3b72b4a21fd0c6136
 Built:             Fri Oct 26 23:38:19 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Ansible version is

ansible 2.6.8
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/ec2-user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.6.9 (unknown, Nov  2 2017, 19:21:21) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]

Here is my part of ansible playbook file

- name: Pull a container image
  docker_container:
    name: mynodejs
    image: registry.gitlab.com/ppshein/test:latest
    pull: yes
    state: started
    published_ports:
      - 8080:80

Please let me know which I'm missed to configure inside AWS Ec2 Linux.

like image 355
PPShein Avatar asked Dec 27 '18 07:12

PPShein


2 Answers

What worked for me for ansible 2.9.1 and Ubuntu 20.10 was installing python3-docker:

sudo apt-get install python3-docker
like image 120
Bogdan Iordache Avatar answered Oct 19 '22 12:10

Bogdan Iordache


You need to install the Python docker module:

sudo yum install python-pip
sudo pip install docker
like image 10
Uku Loskit Avatar answered Oct 19 '22 11:10

Uku Loskit