3
votes

I'm trying to create a docker container which generates a secretkey using Ansible, but the docker_container doesn't seem to return the container output.

If I ssh into the server and run

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

I get the desired output. A secret key such as this

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

But if I try to run the same command using an Ansible playbook, the docker container is executed, but no value is returned:

...
- 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': {}}" }

Is this a limitation with the docker_container module? Do I have to setup any other configuration in docker or ansible to get the container output?

1

1 Answers

1
votes

This is a bug that was introduced in Ansible 2.2.x, that strips ansible_docker_container away from results.

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

Patch:
https://github.com/ansible/ansible/pull/22324/files

The fix is to be released with Ansible 2.3.x