Ansible error message

时间:2015-06-25 18:27:43

标签: ansible ansible-playbook devops

I'm trying to use ansible to build a docker image locally but I'm running into problems.

- hosts: all
  tasks:
    - name: Build Docker image
      local_action:
          module: docker_image
          path: .
          name: SlothSloth
          state: present

And my /etc/ansible/hosts contains

localhost   ansible_connection=local

But when I try to run it I get:

TASK: [Build Docker image] **************************************************** 
failed: [localhost -> 127.0.0.1] => {"failed": true, "parsed": false}
failed=True msg='failed to import python module: No module named docker.client'


FATAL: all hosts have already failed -- aborting

1 个答案:

答案 0 :(得分:1)

如果你使用的是virtualenv,你可能默认使用/ usr / bin / python运行ansible。要绕过此行为,您必须定义变量" ansible_python_interpreter"。

尝试使用:

- hosts: all
  vars:
    - ansible_python_interpreter: python
  tasks:
    - name: Build Docker image
      local_action:
          module: docker_image
          path: .
          name: SlothSloth
          state: present