0

我正在尝试使用 ansible 在本地构建 docker 映像,但遇到了问题。

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

我的 /etc/ansible/hosts 包含

localhost   ansible_connection=local

但是当我尝试运行它时,我得到:

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
4

1 回答 1

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
于 2015-07-02T19:09:49.887 回答