overexchange
overexchange

Reputation: 1

How to retrieve the execution status of ansible module?

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

Upvotes: 0

Views: 309

Answers (1)

Matt P
Matt P

Reputation: 2625

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.

Upvotes: 1

Related Questions