title: Why ansible keeps recreating docker containers with state "started"
body: <p>I have a docker container managed by Ansible. Every time I start the container with Ansible it is recreated instead of just started.</p>
  
  <p>Here are the Ansible commands I use to stop/start the container:</p>
  
  <pre><code>ansible-playbook &lt;playbook&gt; -i &lt;inventory&gt; --extra-vars "state=stopped"
  ansible-playbook &lt;playbook&gt; -i &lt;inventory&gt; --extra-vars "state=started"
  </code></pre>
  
  <p>Here's the Ansible taks I use to manage container. The only thing that changes between "stop" and "start" command is {{ state }}.</p>
  
  <pre><code>- docker:
      name: "{{ postgres_container_name }}"
      image: "{{ postgres_image_name }}"
      state: "{{ state }}"
      ports:
        - "{{ postgres_host_port }}:{{ postgres_guest_port }}"
      env:
        POSTGRES_USER: "{{ postgres_user }}"
        POSTGRES_PASSWORD: "{{ postgres_password }}"
        POSTGRES_DB: "{{ postgres_db }}"
  </code></pre>
  
  <p>When I start, stop and start the container I get the following verbose output from Ansible command:</p>
  
  <pre><code>changed: [127.0.0.1] =&gt; {"ansible_facts": {"docker_containers": [{"Id": "ab1c0f6cc30de33aba31ce93671267783ba08a1294df40556870e66e8bf77b6d", "Warnings": null}]}, "changed": true, "containers": [{"Id": "ab1c0f6cc30de33aba31ce93671267783ba08a1294df40556870e66e8bf77b6d", "Warnings": null}], "msg": "removed 1 container, started 1 container, created 1 container.", "reload_reasons": null, "summary": {"created": 1, "killed": 0, "pulled": 0, "removed": 1, "restarted": 0, "started": 1, "stopped": 0}}
  </code></pre>
  
  <p>It states that the container changed, was removed, created and started.</p>
  
  <p>Could you tell me why Ansible sees my container as changed and recreates it instead of starts?</p>