gpt4 book ai didi

docker - Ansible 剧本 : setup and connect to docker (authentication or permission failure)

转载 作者:行者123 更新时间:2023-12-02 06:39:17 26 4
gpt4 key购买 nike

我正在尝试编写一个 ansible 剧本来设置一些 docker 容器,然后在它们上运行一个角色:

- 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] changed: [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'})

PLAY [docker]

TASK [setup] fatal: [test_precise]: UNREACHABLE! => {"changed": false, "msg": "Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the remote directory. Consider changing the remote temp path in ansible.cfg to a path rooted in \"/tmp\". Failed command was: ( 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\" ), exited with result 1", "unreachable": true}

[...]

有什么想法吗?

docker 1.11.2安塞 bool 2.1.1.0 python 2.7.12Linux Mint 18 莎拉

最佳答案

首先:您需要保持 docker 容器运行,因此使用

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

应该会导致更改的错误消息:致命:[test_trusty]:失败! => {“更改”:假,“失败”:真,“module_stderr”:“/bin/sh:1:/usr/bin/python:找不到\n”,“module_stdout”:“”,“msg” :“模块失败”,“已解析”:错误}

这意味着 python 没有安装在容器内。因此,在使用容器之前,您需要在其中安装 python。您可以通过自定义 Dockerfile 并使用创建的 docker 镜像而不是默认的 ubuntu 镜像来完成此操作

关于docker - Ansible 剧本 : setup and connect to docker (authentication or permission failure),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39648710/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com