【问题标题】:ansible playbook: setup and connect to docker (authentication or permission failure)ansible playbook:设置并连接到 docker(身份验证或权限失败)
【发布时间】:2017-01-31 14:27:09
【问题描述】:

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

- 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'

第二局一直失败:

播放 [本地主机]

[...]

任务 [add_host] 更改:[localhost] => (item={u'image_tag': u'12.04', u'image_name': u'ubuntu', u'container_name': u'test_precise'}) 更改:[localhost] => (item={u'image_tag': u'14.04', u'image_name': u'ubuntu', u'container_name': u'test_trusty'})

播放 [泊坞窗]

任务 [设置] 致命:[test_precise]:无法访问! => {"changed": false, "msg": "身份验证或权限失败。在某些情况下,您可能已经能够进行身份验证并且没有远程目录的权限。考虑更改 ansible.cfg 中的远程临时路径到以 \"/tmp\" 为根的路径。失败的命令是:( 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}

[...]

有什么想法吗?

码头工人 1.11.2 可靠的 2.1.1.0 蟒蛇2.7.12 Linux Mint 18 莎拉

【问题讨论】:

  • 您是否在任何地方设置自定义TMP 或TMPDIR 环境变量?
  • 目前我没有。

标签: docker ansible


【解决方案1】:

首先:你需要让你的 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}

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-12
    • 1970-01-01
    • 2021-01-18
    • 1970-01-01
    • 1970-01-01
    • 2018-11-22
    • 2015-08-29
    相关资源
    最近更新 更多