Below is the shell command we use to launch a docker container:


docker container run --rm -it  \
        -e name1=value1 -e name2=value2 -e name3=value3 \

where we use --rm & --it option.

Currently I wrote the above code logic in ansible using docker_container module as:

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

How to start the container using ansible module with --rm & --it mode?


Set auto_remove: yes, tty: yes, and I believe interactive: yes, but that may be wrong, I'm just guessing based on a brief Google.

Credit where credit is due for the first half of my answer: https://stackoverflow.com/questions/35298664/way-to-set-rm-flag-for-ansible-docker-module

Look through the options here if you ever need to set a flag and see if any match:


  • @JeffSchaller This is part of the jenkins pipeline.. where jenkins triggers this ansible module very frequently...so am not sure, how tty:yes impacts? – overexchange Aug 6 at 19:07
  • The -it flag stands for interactive and tty, i.e. it creates an interactive pseudoterminal for you, so you need to specify both in the module if you want to keep that flag. – Zach Sanchez Aug 6 at 19:23
  • I see this error: "Unsupported parameters for (docker_container) module: auto_remove. – overexchange Aug 7 at 15:45
  • What version of Ansible are you running? It was added in 2.4. – Zach Sanchez Aug 7 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.