【问题标题】:Ansible: get docker container output during container creationAnsible:在容器创建期间获取 docker 容器输出
【发布时间】:2017-09-01 22:45:37
【问题描述】:

我正在尝试创建一个使用 Ansible 生成密钥的 docker 容器,但 docker_container 似乎没有返回容器输出。

如果我 ssh 进入服务器并运行

root@localhost:~# docker run --rm sentry-onpremise config generate-secret-key

我得到了想要的输出。像这样的密钥

q16w8(5s9_+%4@z8m%c%0uzb&agf0pn+6zfocraponasww&r)f

但如果我尝试使用 Ansible playbook 运行相同的命令,则会执行 docker 容器,但不会返回任何值:

...
- name: Cria secret key para utilizacao em passos seguintes
  docker_container:
    name: sentry-key-generator
    cleanup: True
    image: sentry-onpremise
    command: config generate-secret-key
  register: saida
  tags:
    - debug

- fail:
    msg: "Valor de saida: {{ saida }}"
  tags:
    - debug
...

致命:[45.56.93.133]:失败! => { “改变”:错误, “失败”:是的, “调用”:{ “模块参数”:{ "msg": "Valor de saida: {u'changed': True, u'ansible_facts': {}}" }, “模块名称”:“失败” }, "msg": "Valor de saida: {u'changed': True, u'ansible_facts': {}}" }

这是 docker_container 模块的限制吗?我是否必须在 docker 或 ansible 中设置任何其他配置才能获取容器输出?

【问题讨论】:

    标签: ansible sentry docker-container


    【解决方案1】:

    这是 Ansible 2.2.x 中引入的一个错误,它将ansible_docker_container 从结果中删除。

    见:
    https://github.com/ansible/ansible/issues/22323
    https://github.com/ansible/ansible/issues/20543

    补丁:
    https://github.com/ansible/ansible/pull/22324/files

    此修复程序将与 Ansible 2.3.x 一起发布

    【讨论】:

    • 我明天将测试 development/2.3 分支,检查问题是否已解决。谢谢!
    • 我的 ubuntu 将 Ansible 更新到了 2.3 版,但仍然没有解决问题。我得到了很多关于容器的数据(卷、网络、名称等),但没有得到容器吐出到主机可见的标准输出的数据。我还有其他方法可以实现吗?
    • 你设置detach: false了吗?
    • 我没有。确实我错过了那个细节!谢谢
    猜你喜欢
    • 2016-01-10
    • 2019-06-29
    • 2021-02-25
    • 1970-01-01
    • 2019-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多