Failed to import the required Python library
See original GitHub issueGiven this vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "generic/ubuntu1804"
config.vm.define "vagrant"
config.vm.provision "deploy", type: 'ansible' do |ansible|
ansible.compatibility_mode = "2.0"
ansible.playbook = "ansible/deploy.yml"
ansible.groups = {
"staging" => ["vagrant"]
}
end
end
and this playbook:
- name: Deploy
hosts: vagrant
tasks:
- name: Update and upgrade apt packages
become: yes
apt:
upgrade: 'yes'
update_cache: yes
cache_valid_time: 3600
# Reference: https://github.com/ansible/ansible/issues/56832
force_apt_get: yes
- name: Install Docker & Docker compose
include_role:
name: "nickjj.docker"
apply:
become: yes
tags:
- docker
- name: Pip install docker for Ansible's docker_* modules
pip:
name:
- docker
- "docker-compose"
- name: Save services
local_action:
module: docker_image
archive_path: /tmp/{{ item }}.tar
build:
path: ../{{ item }}
pull: yes
name: {{ item }}
tag: latest
force_source: yes
source: build
with_items:
- database
- server
- client
- documents
- name: Upload services
copy:
src: /tmp/{{ item }}.tar
dest: "{{ base_path }}/{{ item }}.tar"
with_items:
- database
- server
- client
- documents
- name: Load services
become: yes
docker_image:
load_path: "{{ base_path }}/{{ item }}.tar"
name: {{ item }}
tag: latest
source: load
with_items:
- database
- server
- client
- documents
vars:
ansible_python_interpreter: "/usr/bin/env python-docker"
I get:
failed: [vagrant] (item=database) => {"ansible_loop_var": "item", "changed": false, "item": "database", "msg": "Failed to import the required Python library (Docker SDK for Python: docker (Python >= 2.7) or docker-py (Python 2.6)) on ubuntu1804.localdomain's Python /usr/local/bin/python-docker. 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 'docker'"}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:27 (13 by maintainers)
Top Results From Across the Web
ansible returns with "Failed to import the required Python ...
It appears that you don't have the docker module installed. You will need to install it via your system package manager ( apt...
Read more >AWS Failed to import the required Python library (botocore or ...
This fatal error message happens when we are trying to execute some code against your AWS EC2 Infrastructure without the necessary Python libraries...
Read more >Failed to import the required Python library (hcloud-python)
When running an Ansible script, an error shows up and the script stops: "Failed to import the required Python library (hcloud-python) on computer's...
Read more >Failed to import the required Python library Docker SDK for ...
So here you need to reinstall the docker SDK in your system using the below-given command. I hope this will solve your error!...
Read more >AWS Failed to import the required Python library (botocore or ...
Let's troubleshoot together the Ansible fatal error " Failed to import the required Python library (botocore or boto3)" to find the root ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hint for everyone else who ran into this, upgrade your locally cached version 😉
ansible-galaxy install -f nickjj.dockerIt just fails to connect with
connect to host localhost port 2222: Connection refusedand also trying to connect to the VM’s IP over port 22 fails too with the same message.Normally with my Vagrantfiles, I wouldn’t bother with their insecure key and I would copy in my SSH key, so it’s more similar to how it would be on a real server.
But in any case, when I spin up a new DO server I’m unable to
import dockerin that virtualenv too, and it’s due to the docker pip package not being installed, which is interesting considering the package’s state is set to present and the task showed it was changed.I wonder if something changed since September 2019 and today with Ansible. I’m going to investigate this further today. I only did a quick test on it yesterday.
By the way, are you using Python 2 or 3 as your Ansible interpreter?