Ansible:在容器创建期间获取 docker 容器输出

标签 ansible sentry docker-container

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

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

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

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

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

但是,如果我尝试使用 Ansible 剧本运行相同的命令,则会执行 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
...

fatal: [45.56.93.133]: FAILED! => { "changed": false, "failed": true, "invocation": { "module_args": { "msg": "Valor de saida: {u'changed': True, u'ansible_facts': {}}" }, "module_name": "fail" }, "msg": "Valor de saida: {u'changed': True, u'ansible_facts': {}}" }

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

最佳答案

这是 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 一起发布

关于Ansible:在容器创建期间获取 docker 容器输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43263045/

相关文章:

php - Laravel 和 Sentry : How to set a custom tag in Sentry?

docker - 无法启动容器:[8]系统错误:exec: “up3”:在$ PATH中找不到可执行文件

ansible - 在ansible中设置强制限制参数

jenkins - 如何使用 Ansible 重新启动 Jenkins 并等待它回来?

flutter - Sentry 不会在 Flutter 内部报告错误

azure - docker 图像和图层如何工作?

eclipse - 使用 Docker 容器时如何在 Eclipse 中添加包含和库路径

java - 如何知道 .jar Nexus Artifact 是从哪个分支发出的

Ansible变量将在另一个角色中覆盖默认值

django - 如何通过多个 raven 配置使用 Sentry 日志记录