Repository: ansible/ansible

Issue:
Facts returned by docker_network module are removed by ansible >= 2.3.0
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
docker_network

##### ANSIBLE VERSION
```
ansible 2.4.0 (devel e0a7105c2d) last updated 2017/04/24 16:32:33 (GMT +100)
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/willmerae/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/willmerae/src/ansible/lib/ansible
  executable location = /home/willmerae/src/ansible/bin/ansible
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
```

##### CONFIGURATION

##### OS / ENVIRONMENT
Ubuntu 16.04 4.4.0-72-generic \#93-Ubuntu SMP Fri Mar 31 14:07:41 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

##### SUMMARY
The docker_network module returns a fact called `ansible_docker_network`, this is filtered out since Ansible 2.3.0 and the following warning is displayed

> [WARNING]: Removed restricted key from module data: ansible_docker_network =
> {u'Name': u'foo', u'IPAM': {u'Config': [{u'Subnet': u'172.19.0.0/16',
> u'Gateway': u'172.19.0.1/16'}], u'Driver': u'default', u'Options': None},
> u'Labels': {}, u'Driver': u'bridge', u'Options': {}, u'Internal': False,
> u'EnableIPv6': False, u'Scope': u'local', u'Id':
> u'19fce79190891fae85804229b7b82c8d6beb8eb77e57d7a064af2d973fef9531',
> u'Containers': {}}

The fact should probably be renamed to `docker_network`, though that might cause backward incompatibility problems.

##### STEPS TO REPRODUCE

```
ansible-playbook -c docker -u root test.yml
```
<!--- Paste example playbooks or commands between quotes below -->
```yaml
- hosts: localhost
  gather_facts: False
  tasks:
    - docker_network:
        name: foo
        driver: bridge
      register: docker_network_facts

    - debug: var=docker_network_facts
```

##### EXPECTED RESULTS

The details of the network are added to the registered variable (`docker_network_facts`)
##### ACTUAL RESULTS

The variable in question is empty and ansible-playbook warns that the fact returned by the module has been removed.

<details>

```
willmerae@devlaptop06:~/src/ansible$ ansible-playbook -c docker -u root test.yml -vvv
Using /etc/ansible/ansible.cfg as config file
 [WARNING]: provided hosts list is empty, only localhost is available


PLAYBOOK: test.yml *************************************************************
1 plays in test.yml

PLAY [localhost] ***************************************************************
META: ran handlers

TASK [docker_network] **********************************************************
task path: /home/willmerae/src/ansible/test.yml:4
Using module_utils file /home/willmerae/src/ansible/lib/ansible/module_utils/basic.py
Using module_utils file /home/willmerae/src/ansible/lib/ansible/module_utils/docker_common.py
Using module_utils file /home/willmerae/src/ansible/lib/ansible/module_utils/_text.py
Using module_utils file /home/willmerae/src/ansible/lib/ansible/module_utils/pycompat24.py
Using module_utils file /home/willmerae/src/ansible/lib/ansible/module_utils/six/__init__.py
Using module_utils file /home/willmerae/src/ansible/lib/ansible/module_utils/six/_six.py
Using module file /home/willmerae/src/ansible/lib/ansible/modules/cloud/docker/docker_network.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: willmerae
<127.0.0.1> EXEC /bin/sh -c 'echo ~ && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/willmerae/.ansible/tmp/ansible-tmp-1493049382.41-141126467372052 `" && echo ansible-tmp-1493049382.41-141126467372052="` echo /home/willmerae/.ansible/tmp/ansible-tmp-1493049382.41-141126467372052 `" ) && sleep 0'
<127.0.0.1> PUT /tmp/tmp__3Ifn TO /home/willmerae/.ansible/tmp/ansible-tmp-1493049382.41-141126467372052/docker_network.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/willmerae/.ansible/tmp/ansible-tmp-1493049382.41-141126467372052/ /home/willmerae/.ansible/tmp/ansible-tmp-1493049382.41-141126467372052/docker_network.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /home/willmerae/.ansible/tmp/ansible-tmp-1493049382.41-141126467372052/docker_network.py; rm -rf "/home/willmerae/.ansible/tmp/ansible-tmp-1493049382.41-141126467372052/" > /dev/null 2>&1 && sleep 0'
 [WARNING]: Removed restricted key from module data: ansible_docker_network =
{u'Name': u'foo', u'IPAM': {u'Config': [{u'Subnet': u'172.19.0.0/16',
u'Gateway': u'172.19.0.1/16'}], u'Driver': u'default', u'Options': None},
u'Labels': {}, u'Driver': u'bridge', u'Options': {}, u'Internal': False,
u'EnableIPv6': False, u'Scope': u'local', u'Id':
u'19fce79190891fae85804229b7b82c8d6beb8eb77e57d7a064af2d973fef9531',
u'Containers': {}}

ok: [localhost] => {
    "ansible_facts": {}, 
    "changed": false, 
    "invocation": {
        "module_args": {
            "api_version": null, 
            "appends": false, 
            "cacert_path": null, 
            "cert_path": null, 
            "connected": [], 
            "debug": false, 
            "docker_host": null, 
            "driver": "bridge", 
            "driver_options": {}, 
            "filter_logger": false, 
            "force": false, 
            "ipam_driver": null, 
            "ipam_options": {}, 
            "key_path": null, 
            "name": "foo", 
            "network_name": "foo", 
            "ssl_version": null, 
            "state": "present", 
            "timeout": null, 
            "tls": null, 
            "tls_hostname": null, 
            "tls_verify": null
        }
    }
}

TASK [debug] *******************************************************************
task path: /home/willmerae/src/ansible/test.yml:9
ok: [localhost] => {
    "docker_network_facts": {
        "ansible_facts": {}, 
        "changed": false
    }
}
META: ran handlers
META: ran handlers

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0   

```
</details>


Discussion:
cc @olsaki
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/cloud/docker/docker_network.py b/lib/ansible/modules/cloud/docker/docker_network.py
--- a/lib/ansible/modules/cloud/docker/docker_network.py
+++ b/lib/ansible/modules/cloud/docker/docker_network.py
@@ -358,7 +358,7 @@ def present(self):
         if not self.check_mode and not self.parameters.debug:
             self.results.pop('actions')
 
-        self.results['ansible_facts'] = {u'ansible_docker_network': self.get_existing_network()}
+        self.results['ansible_facts'] = {u'docker_network': self.get_existing_network()}
 
     def absent(self):
         self.remove_network()


Test patch: