Ansible Shell无法提取Docker镜像

我遇到了使用Ansible的Docker模块从私有DockerHub仓库中拖出Docker镜像的问题,因此为了理智,检查代码决定尝试首先使用shell抽取有问题的镜像。 这也失败了。 这里发生了什么? 如果我SSH上的框,我能够运行完全相同的命令在shell和它的作品,拉正确的形象。

孤立的例子玩法:

--- - hosts: <host-ip> gather_facts: True remote_user: ubuntu sudo: yes tasks: - include_vars: vars/client_vars.yml - name: Pull stardog docker image [private] shell: sudo docker pull {{stardog_docker_repo}} - name: Tag stardog docker image [private] shell: sudo docker tag {{stardog_docker_repo}} stardog_tag 

正在输出的错误是:

 failed: [<host-ip>] => {"changed": true, "cmd": "sudo docker pull <org>/<image>:latest", "delta": "0:00:01.395931", "end": "2015-08-05 17:35:22.480811", "rc": 1, "start": "2015-08-05 17:35:21.084880", "warnings": []} stderr: Error: image <org>/<image>:latest not found stdout: Pulling repository <org>/<image> FATAL: all hosts have already failed -- aborting 

注意:我已经对我的<org><image>清理,但是放心在playbook中显示它们的图像标识符,并且错误日志logging与我可以在shell中通过ssh成功运行的映像完全匹配:

 $ sudo docker pull <org>/<image>:latest 

我知道各种GitHub问题( 比如我使用Docker模块时遇到的问题),docker docker-py库相关的补丁等等,但是这里只是使用了Ansible shell模块。 我错过了什么?

我的一位同事指出了一些事情 – 如果你loginenv ,你会发现sudo: yes默认运行docker命令,因此ubuntu用户的Docker凭据不会被提取。 这个剧本可以工作(假设你在dockercfg.json文件夹中有一个有效的dockercfg.json ,相对于这个剧本。

 --- - hosts: <host-ip> gather_facts: True remote_user: ubuntu sudo: yes tasks: - include_vars: vars/client_vars.yml # run the docker tasks - name: Add docker credentials for ubuntu user copy: src=docker/dockercfg.json dest=/root/.dockercfg - name: Get env shell: sudo env register: sudo_env - name: Debug debug: msg="{{sudo_env}}" - name: Pull stardog docker image [private] shell: docker pull {{stardog_docker_repo}} - name: Tag stardog docker image [private] shell: docker tag {{stardog_docker_repo}} stardog_tag 

这给了root权利DockerHub信誉。 或者,您可以为每个播放添加sudo: false ,并在每个shell调用中使用sudo作为ubuntu用户运行。

你应该使用Ansible的docker_container模块来拉图像。

这样,你不需要在shell中运行sudo。

http://docs.ansible.com/ansible/docker_container_module.html