0

Below the docker_container module:

- name: Create a data container
  docker_container:
    name: mydeploycontainer
    image: 1111112222.dkr.ecr.us-east-1.amazonaws.com/someteam/app-deploy:v.1
    env:
      name1: "value1"
      name2: "value2"
      name3: "value3"

we are running this in tower

How to retrieve the execution status of docker_container module? on stdout..

overexchange
  • 15,768
  • 30
  • 152
  • 347
  • Does [the return value of the `docker_container` module](https://docs.ansible.com/ansible/latest/modules/docker_container_module.html#return-values) have what you need? Or [`docker_container_info`](https://docs.ansible.com/ansible/latest/modules/docker_container_info_module.html#docker-container-info-module)? – David Maze Aug 07 '19 at 00:21
  • @DavidMaze return value of container – overexchange Aug 07 '19 at 00:23

1 Answers1

1

You can register the task result to a specific variable, however the docker_container module also creates an ansible_facts variable aptly called docker_container

So using this variable, you can return various values, for example:

  - debug:
      var: docker_container.State.ExitCode

  - debug:
      var: docker_container.State.Status

  - debug:
      var: docker_container.Output

Note that if you want to see the stdout of the container using docker_container.Output, then you need to add the detach argument to your task. For example:

  - name: Create a data container
    docker_container:
      name: mydeploycontainer
      image: 1111112222.dkr.ecr.us-east-1.amazonaws.com/someteam/app-deploy:v.1
      env:
        name1: "value1"
        name2: "value2"
        name3: "value3"
      detach: false
    register: mydeploycontainer_result

The example above also shows how to register the task result to a variable named mydeploycontainer_result. This would allow you to save the result of multiple container deployments.

Matt P
  • 2,452
  • 1
  • 12
  • 15