ansible playbook:设置并连接到docker(authentication或权限失败)

我正在尝试编写一个可靠的剧本,设置一些docker集装箱,然后在其上运行一个angular色:

- hosts: localhost gather_facts: no vars: - docker_test_hosts: - container_name: 'test_precise' image_name: 'ubuntu' image_tag: '12.04' - container_name: 'test_trusty' image_name: 'ubuntu' image_tag: '14.04' # "Registry returned more than one result for ubuntu:16.04" #- container_name: 'xenial' #- image_name: 'ubuntu' #- image_tag: '16.04' tasks: - pip: name: docker-py # >= 1.7.0 # using 1.9.0 due to https://github.com/ansible/ansible/issues/17495 version: 1.9.0 state: present - docker_container: name: '{{item.container_name}}' image: '{{item.image_name}}:{{item.image_tag}}' pull: yes with_items: '{{docker_test_hosts}}' - add_host: name: '{{item.container_name}}' hostname: '{{item.container_name}}' ansible_host: '{{item.container_name}}' ansible_connection: docker ansible_user: root groups: docker with_items: '{{docker_test_hosts}}' - hosts: docker tasks: - debug: msg: 'hello' 

第二场比赛依然失败:

PLAY [localhost]

[…]

TASK [add_host]改变了:[localhost] =>(item = {u'image_tag':u'12.04',u'image_name':u'ubuntu',u'container_name':u'test_precise'})changed:[localhost ] =>(item = {u'image_tag':u'14.04',u'image_name':u'ubuntu',u'container_name':u'test_trusty'})

玩[docker]

任务[setup]致命:[test_precise]:UNREACHABLE! => {“changed”:false,“msg”:“身份validation或权限失败,在某些情况下,您可能已经能够对远程目录进行身份validation并且没有权限,请考虑更改ansible.cfg中的远程临时path到“/ tmp \”的path。失败的命令是:(umask 77 && mkdir -p \“ echo $HOME/.ansible/tmp/ansible/tmp-1474479086.86-239783828445202 ”&& echo ansible-tmp-1474479086.86 -239783828445202 = \“ echo $HOME/.ansible/tmp/ansible-tmp-1474479086.86-239783828445202 \”),结果1退出“,”unreachable“:true}

[…]

有任何想法吗?

docker 1.11.2 ansible 2.1.1.0 python 2.7.12 Linux Mint 18 Sarah

首先:你需要保持你的docker集装箱运行,所以使用

 - docker_container: name: '{{item.container_name}}' image: '{{item.image_name}}:{{item.image_tag}}' command: tail -f /dev/null pull: yes 

应该导致一个改变的错误信息: fatal: [test_trusty]: FAILED! => {"changed": false, "failed": true, "module_stderr": "/bin/sh: 1: /usr/bin/python: not found\n", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false} fatal: [test_trusty]: FAILED! => {"changed": false, "failed": true, "module_stderr": "/bin/sh: 1: /usr/bin/python: not found\n", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}

这意味着python没有安装在容器中。 所以在使用容器之前,你需要在里面安装python。 你可以通过一个自定义的Dockerfile来创buildDockerfile镜像,而不是默认的Ubuntu镜像