Repository: ansible/ansible

Issue:
Removed restricted key from module data: ansible_lxc_bridge
<!---
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
Gathering Facts

##### ANSIBLE VERSION
```
ansible 2.3.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, Jul 21 2017, 03:24:34) [GCC 7.1.1 20170630]
```

##### CONFIGURATION
No

##### OS / ENVIRONMENT
Archlinux, but probably not platform specific

##### SUMMARY
During gathering facts I get following warning

```
TASK [Gathering Facts] ************************************************************************
 [WARNING]: Removed restricted key from module data: ansible_lxc_bridge = {u'macaddress':
u'70:85:c2:0b:a3:4a', u'features': {}, u'interfaces': [u'vethG18OR8', u'enp0s31f6',
u'vethWYJVBN'], u'mtu': 1500, u'active': True, u'promisc': False, u'stp': False, u'ipv4':
{u'broadcast': u'192.168.0.255', u'netmask': u'255.255.255.0', u'network': u'192.168.0.0',
u'address': u'192.168.0.110'}, u'ipv6': [{u'scope': u'link', u'prefix': u'64', u'address':
u'fe80::7285:c2ff:fe0b:a34a'}], u'device': u'lxc_bridge', u'type': u'bridge', u'id':
u'8000.7085c20ba34a'}
```

##### STEPS TO REPRODUCE
Try to run playbook against host with lxc and bridge configured.

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
No warning.

##### ACTUAL RESULTS
Warning.


Discussion:
cc @risaacson
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Hi Guys,

I am experiencing the same error on OpenSuse Leap when trying to manage a CentOS server:

>  [WARNING]: Removed restricted key from module data: ansible_lxc_virbr0_nic = {u'macaddress': u'c0:bb:00:00:00:02', u'features': {u'tx_checksum_ipv4': u'off [fixed]',
u'generic_receive_offload': u'on', u'tx_checksum_ipv6': u'off [fixed]', u'tx_scatter_gather_fraglist': u'on', u'rx_all': u'off [fixed]', u'highdma': u'off [fixed]', u'rx_fcs': u'off
[fixed]', u'tx_lockless': u'off [fixed]', u'tx_tcp_ecn_segmentation': u'off [requested on]', u'tx_gso_robust': u'off [fixed]', u'tx_ipip_segmentation': u'off [fixed]', u'tx_checksumming':
u'off', u'vlan_challenged': u'off [fixed]', u'loopback': u'off [fixed]', u'fcoe_mtu': u'off [fixed]', u'tx_checksum_sctp': u'off [fixed]', u'tx_vlan_stag_hw_insert': u'on',
u'rx_vlan_stag_hw_parse': u'off [fixed]', u'tx_nocache_copy': u'off', u'rx_vlan_stag_filter': u'off [fixed]', u'large_receive_offload': u'off [fixed]', u'tx_checksum_ip_generic': u'off
[requested on]', u'rx_checksumming': u'off [fixed]', u'tx_tcp_segmentation': u'off [requested on]', u'tx_fcoe_segmentation': u'off [fixed]', u'busy_poll': u'off [fixed]',
u'generic_segmentation_offload': u'on', u'tx_udp_tnl_segmentation': u'off [fixed]', u'tcp_segmentation_offload': u'off', u'rx_vlan_offload': u'off [fixed]', u'ntuple_filters': u'off
[fixed]', u'rx_vlan_filter': u'off [fixed]', u'tx_tcp6_segmentation': u'off [requested on]', u'tx_mpls_segmentation': u'off [fixed]', u'udp_fragmentation_offload': u'off [requested on]',
u'scatter_gather': u'on', u'tx_sit_segmentation': u'off [fixed]', u'tx_checksum_fcoe_crc': u'off [fixed]', u'tx_scatter_gather': u'on', u'netns_local': u'off [fixed]', u'tx_vlan_offload':
u'on', u'receive_hashing': u'off [fixed]', u'tx_gre_segmentation': u'off [fixed]'}, u'mtu': 1500, u'active': False, u'promisc': True, u'device': u'lxc_virbr0-nic', u'type': u'ether'}

Running Ansible version:

> ansible 2.3.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Jul 01 2016, 15:34:22) [GCC]


Resolving patch:
diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py
--- a/lib/ansible/playbook/task.py
+++ b/lib/ansible/playbook/task.py
@@ -25,7 +25,7 @@
 from ansible.module_utils.six import iteritems, string_types
 from ansible.module_utils._text import to_native
 from ansible.parsing.mod_args import ModuleArgsParser
-from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleMapping, AnsibleUnicode
+from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleMapping
 from ansible.plugins.loader import lookup_loader
 from ansible.playbook.attribute import FieldAttribute
 from ansible.playbook.base import Base
@@ -205,23 +205,24 @@ def preprocess_data(self, ds):
 
         for (k, v) in iteritems(ds):
             if k in ('action', 'local_action', 'args', 'delegate_to') or k == action or k == 'shell':
-                # we don't want to re-assign these values, which were
-                # determined by the ModuleArgsParser() above
+                # we don't want to re-assign these values, which were determined by the ModuleArgsParser() above
                 continue
             elif k.replace("with_", "") in lookup_loader:
+                # transform into loop property
                 self._preprocess_loop(ds, new_ds, k, v)
             else:
-                # pre-2.0 syntax allowed variables for include statements at the
-                # top level of the task, so we move those into the 'vars' dictionary
-                # here, and show a deprecation message as we will remove this at
-                # some point in the future.
+                # pre-2.0 syntax allowed variables for include statements at the top level of the task,
+                # so we move those into the 'vars' dictionary here, and show a deprecation message
+                # as we will remove this at some point in the future.
                 if action in ('include', 'include_tasks') and k not in self._valid_attrs and k not in self.DEPRECATED_ATTRIBUTES:
                     display.deprecated("Specifying include variables at the top-level of the task is deprecated."
                                        " Please see:\nhttp://docs.ansible.com/ansible/playbooks_roles.html#task-include-files-and-encouraging-reuse\n\n"
                                        " for currently supported syntax regarding included files and variables", version="2.7")
                     new_ds['vars'][k] = v
-                else:
+                elif k in self._valid_attrs:
                     new_ds[k] = v
+                else:
+                    display.warning("Ignoring invalid attribute: %s" % k)
 
         return super(Task, self).preprocess_data(new_ds)
 
diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py
--- a/lib/ansible/plugins/action/__init__.py
+++ b/lib/ansible/plugins/action/__init__.py
@@ -780,7 +780,8 @@ def _clean_returned_data(self, data):
                 conn_name = os.path.splitext(os.path.basename(conn_path))[0]
                 re_key = re.compile('^ansible_%s_' % conn_name)
                 for fact_key in fact_keys:
-                    if re_key.match(fact_key):
+                    # exception for lvm tech, whic normally returns asnible_x_bridge facts that get filterd out (docker,lxc, etc)
+                    if re_key.match(fact_key) and not fact_key.endswith(('_bridge', '_gwbridge')):
                         remove_keys.add(fact_key)
             except AttributeError:
                 pass


Test patch: