ansible +docker

683 views
Skip to first unread message

Sunitha Iyer

unread,
Oct 16, 2019, 2:07:41 PM10/16/19
to Ansible Project

I am trying to run a play book from host(ansible VM) to pull an image from docker host, I tried pip install docker still it not working, can you please help.


failed to import the required python library (docker sdk for python: docker (python >= 2.7) or docker-py (python 2.6)) on host's python /usr/bin/python3. please read module documentation and install in the appropriate location, for example via pip install docker or pip install docker-py (python 2.6). the error was: no module named request.exceptions")

Rohith Pagadala

unread,
Oct 16, 2019, 2:25:55 PM10/16/19
to Ansible Project
Can you check the ansible version on your server and let us know


Sunitha Iyer

unread,
Oct 16, 2019, 3:30:23 PM10/16/19
to Ansible Project
thanks for getting back Rohith, its 2.8.5
Message has been deleted

Stefan Hornburg (Racke)

unread,
Oct 17, 2019, 12:28:23 AM10/17/19
to ansible...@googlegroups.com
Try to set the following variable to make sure Ansible uses Python3 on the target host:

ansible_python_interpreter: /usr/bin/python3

Regards
Racke

>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Sunitha Iyer

unread,
Oct 17, 2019, 5:45:43 AM10/17/19
to Ansible Project
Hi Stefan

I tried installing docker using pip command... pip install docker

and then when I tried to run the below command it is not recognising the docker that's the issue.

 ansible-playbook pull_image.yml  -u *** -e 'ansible_python_interpreter=/usr/bin/python'



 Using cached https://files.pythonhosted.org/packages/cc/ca/699d4754a932787ef353a157ada74efd1ceb6d1fc0bfb7989ae1e7b33111/docker-4.1.0-py2.py3-none-any.whl
Requirement already satisfied: requests!=2.18.0,>=2.14.2 in /usr/lib/python2.7/site-packages (from docker) (2.22.0)
Requirement already satisfied: websocket-client>=0.32.0 in /usr/lib/python2.7/site-packages (from docker) (0.56.0)
Requirement already satisfied: ipaddress>=1.0.16; python_version < "3.3" in /usr/lib/python2.7/site-packages (from docker) (1.0.22)
Requirement already satisfied: backports.ssl-match-hostname>=3.5; python_version < "3.5" in /usr/lib/python2.7/site-packages (from docker) (3.7.0.1)
Requirement already satisfied: six>=1.4.0 in /usr/lib/python2.7/site-packages (from docker) (1.12.0)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/lib/python2.7/site-packages (from requests!=2.18.0,>=2.14.2->docker) (3.0.4)
Requirement already satisfied: idna<2.9,>=2.5 in /usr/lib/python2.7/site-packages (from requests!=2.18.0,>=2.14.2->docker) (2.8)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/lib/python2.7/site-packages (from requests!=2.18.0,>=2.14.2->docker) (1.25.6)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python2.7/site-packages (from requests!=2.18.0,>=2.14.2->docker) (2019.9.11)
Installing collected packages: docker
Successfully installed docker-4.1.0


On Thursday, October 17, 2019 at 5:28:23 AM UTC+1, Stefan Hornburg (Racke) wrote:
On 10/16/19 8:07 PM, Sunitha Iyer wrote:
> I am trying to run a play book from host(ansible VM) to pull an image from docker host, I tried pip install docker still
> it not working, can you please help.
>
>
> failed to import the required python library (docker sdk for python: docker (python >= 2.7) or docker-py (python 2.6))
> on host's python /usr/bin/python3. please read module documentation and install in the appropriate location, for example
> via pip install docker or pip install docker-py (python 2.6). the error was: no module named request.exceptions")

Try to set the following variable to make sure Ansible uses Python3 on the target host:

ansible_python_interpreter: /usr/bin/python3

Regards
         Racke

>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to

Stefan Hornburg (Racke)

unread,
Oct 17, 2019, 7:44:29 AM10/17/19
to ansible...@googlegroups.com
On 10/17/19 11:45 AM, Sunitha Iyer wrote:
> Hi Stefan
>
> I tried installing docker using pip command... pip install docker
>
> and then when I tried to run the below command it is not recognising the docker that's the issue.
>
>  ansible-playbook pull_image.yml  -u *** -e 'ansible_python_interpreter=/usr/bin/python'

Please share the contents of pull_image.yml, the actual error messages and the OS details of the target.

Regards
Racke
> > ansible...@googlegroups.com <javascript:> <mailto:ansible-proje...@googlegroups.com <javascript:>>.
> <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/66728461-928d-4691-bfa9-4204c7ffb4a8%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/66728461-928d-4691-bfa9-4204c7ffb4a8%40googlegroups.com?utm_medium=email&utm_source=footer>.
signature.asc

Sunitha Iyer

unread,
Oct 17, 2019, 5:30:33 PM10/17/19
to Ansible Project
Stefen, 

I will do that..why cant I find python2.7 under /usr/bin

but I could see under /usr/lib......


Here is the error message


FAILED ! >= {"changed" ,  false ,msg failed to import docker-py - no module named exceptions , try pip install docker}


pull_image.yml 


- name: pull image
  hosts:TestVM
  tasks:
     - name: build docker image
       docker_image:
           name: xyz
           path: /var/dockertest
>     > ansible...@googlegroups.com <javascript:> <mailto:ansible-project+unsub...@googlegroups.com <javascript:>>.
>     > To view this discussion on the web visit
>     > https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com
>     <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com>
>     >
>     <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com?utm_medium=email&utm_source=footer
>     <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
>     --
>     Ecommerce and Linux consulting + Perl and web application programming.
>     Debian and Sympa administration. Provisioning with Ansible.
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to

Stefan Hornburg (Racke)

unread,
Oct 18, 2019, 1:53:03 AM10/18/19
to ansible...@googlegroups.com
On 10/18/19 12:30 AM, Sunitha Iyer wrote:
> Stefen, 
>
> I will do that..why cant I find python2.7 under /usr/bin

Hello Sunitha,

you didn't report the OS distribution and version of the target. This is crucial
information.

Regards
Racke
> >     > ansible...@googlegroups.com <javascript:> <mailto:ansible-proje...@googlegroups.com <javascript:>
> <javascript:>>.
> >     > To view this discussion on the web visit
> >     > https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com>
> >     <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com>>
> >     >
> >    
> <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com?utm_medium=email&utm_source=footer>
>
> >    
> <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com?utm_medium=email&utm_source=footer>>>.
>
> >
> >
> >
> >     --
> >     Ecommerce and Linux consulting + Perl and web application programming.
> >     Debian and Sympa administration. Provisioning with Ansible.
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to
> > ansible...@googlegroups.com <javascript:> <mailto:ansible-proje...@googlegroups.com <javascript:>>.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/ansible-project/66728461-928d-4691-bfa9-4204c7ffb4a8%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/66728461-928d-4691-bfa9-4204c7ffb4a8%40googlegroups.com>
> >
> <https://groups.google.com/d/msgid/ansible-project/66728461-928d-4691-bfa9-4204c7ffb4a8%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/66728461-928d-4691-bfa9-4204c7ffb4a8%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/0705ac32-323b-4b7f-8527-3c3b1a5715de%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/0705ac32-323b-4b7f-8527-3c3b1a5715de%40googlegroups.com?utm_medium=email&utm_source=footer>.
signature.asc

Sunitha Iyer

unread,
Oct 18, 2019, 3:22:47 AM10/18/19
to Ansible Project
Sorry Stefen missed it, oracle linux server 7.6, RHEL7
>     >     > ansible...@googlegroups.com <javascript:> <mailto:ansible-project+unsub...@googlegroups.com <javascript:>
>     <javascript:>>.
>     >     > To view this discussion on the web visit
>     >     > https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com
>     <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com>
>     >     <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com
>     <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com>>
>     >     >
>     >    
>     <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com?utm_medium=email&utm_source=footer
>     <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com?utm_medium=email&utm_source=footer>
>
>     >    
>     <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com?utm_medium=email&utm_source=footer
>     <https://groups.google.com/d/msgid/ansible-project/60121656-a085-444f-8081-f14f069bace5%40googlegroups.com?utm_medium=email&utm_source=footer>>>.
>
>     >
>     >
>     >
>     >     --
>     >     Ecommerce and Linux consulting + Perl and web application programming.
>     >     Debian and Sympa administration. Provisioning with Ansible.
>     >
>     > --
>     > You received this message because you are subscribed to the Google Groups "Ansible Project" group.
>     > To unsubscribe from this group and stop receiving emails from it, send an email to
>     > ansible...@googlegroups.com <javascript:> <mailto:ansible-project+unsub...@googlegroups.com <javascript:>>.
>     > To view this discussion on the web visit
>     > https://groups.google.com/d/msgid/ansible-project/66728461-928d-4691-bfa9-4204c7ffb4a8%40googlegroups.com
>     <https://groups.google.com/d/msgid/ansible-project/66728461-928d-4691-bfa9-4204c7ffb4a8%40googlegroups.com>
>     >
>     <https://groups.google.com/d/msgid/ansible-project/66728461-928d-4691-bfa9-4204c7ffb4a8%40googlegroups.com?utm_medium=email&utm_source=footer
>     <https://groups.google.com/d/msgid/ansible-project/66728461-928d-4691-bfa9-4204c7ffb4a8%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
>     --
>     Ecommerce and Linux consulting + Perl and web application programming.
>     Debian and Sympa administration. Provisioning with Ansible.
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to

wei zhang

unread,
Jan 6, 2020, 7:39:36 AM1/6/20
to Ansible Project
i have the same error
bash-4.4# ansible-playbook 04-loadbalancer.yml                 

PLAY [master] **********************************************************************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************************************************
ok: [master01]

TASK [loadbalancer : make lb dir] **************************************************************************************************************************************************************************
ok: [master01]

TASK [loadbalancer : generate lb config] *******************************************************************************************************************************************************************
ok: [master01]

TASK [loadbalancer : copy lb images] ***********************************************************************************************************************************************************************
changed: [master01]

TASK [loadbalancer : load lb image] ************************************************************************************************************************************************************************
fatal: [master01]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (Docker SDK for Python: docker (Python >= 2.7) or docker-py (Python 2.6)) on localhost.localdomain's Python /usr/bin/python. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter, for example via `pip install docker` or `pip install docker-py` (Python 2.6). The error was: No module named requests.exceptions"}

PLAY RECAP *************************************************************************************************************************************************************************************************
master01                   : ok=4    changed=1    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   


master01 is centos 7.7

i install docker 18.09.9 with binary at master01

ansible server version:
bash-4.4# ansible --version
ansible 2.9.2
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.9 (default, Oct 17 2019, 11:10:22) [GCC 8.3.0]


i change my task to shell it is ok.but docker_image and docker-container will error
- name: load lb image
  shell: 'docker load -i {{ dpath  }}/loadbalancer/haproxy-{{ haproxy_version }}.tar.bz2'
#  docker_image:
#    load_path: '{{ dpath  }}/loadbalancer/haproxy-{{ haproxy_version }}.tar.bz2'
#    name: lb
#    timeout: 600






wei zhang

unread,
Jan 6, 2020, 9:54:39 AM1/6/20
to Ansible Project
and i find that if i install docker with yum install -y docker-ce in destination hosts, it will be success, so there must be some python package i haven't install ,but what it is?

if i install docker use binary ,maybe some package skiped
Reply all
Reply to author
Forward
0 new messages