Repository: ansible/ansible

Issue:
docker_container: published_ports not triggering rebuild when having less ports
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
docker_container

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible-playbook 2.3.1.0
  config file = /home/wkaczmarek/.ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
Changed inventory, roles path & vault pass file.

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
-->
Ubuntu Server 16.04 LTS
both Ansible host and managed system

##### SUMMARY
<!--- Explain the problem briefly -->
Module does not recreate container when giving it *less* of `published_ports` than the container already has.

Note the container is recreated when ports are *added*. My expected result would be that contained is recreated also in the case when I want less ports, in general - in any case when the existing ports differs from the list of desired ports. 

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
First you run
```yaml
- name: Run container
  docker_container:
    published_ports:
      - "443:443"
      - "22:22"
    name: "foo"
    restart_policy: unless-stopped
    image: "{{ my_image }}"
    volumes:
    state: started
```
then you run
```yaml
- name: Run container
  docker_container:
    published_ports:
      - "443:443"
    name: "foo"
    restart_policy: unless-stopped
    image: "{{ my_image }}"
    volumes:
    state: started
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->

I expected for the second run:
```
TASK [my-role : Run container] ***************************************************
changed: [my-host]
```
Plus of course, docker container to be rebuilt.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

```
TASK [my-role : Run container] ***************************************************
ok: [my-host]
```
..and docker container is not rebuilt.

<!--- Paste verbatim command output between quotes below -->
```

```



Discussion:
Was this working before 2.3.0?
No it wasn't. 

Usually I use 2.2.2.0 and it's the same behavior.

Resolving patch:
diff --git a/lib/ansible/modules/cloud/docker/docker_container.py b/lib/ansible/modules/cloud/docker/docker_container.py
--- a/lib/ansible/modules/cloud/docker/docker_container.py
+++ b/lib/ansible/modules/cloud/docker/docker_container.py
@@ -1302,7 +1302,7 @@ def has_different_configuration(self, image):
                         self.log("comparing lists: %s" % key)
                         set_a = set(getattr(self.parameters, key))
                         set_b = set(value)
-                        match = (set_a <= set_b)
+                        match = (set_a == set_b)
                 elif isinstance(getattr(self.parameters, key), list) and not len(getattr(self.parameters, key)) \
                         and value is None:
                     # an empty list and None are ==


Test patch: