Repository: ansible/ansible

Issue:
os_floating_ip may throw AttributeError: internal_network
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
os_floating_ip

##### ANSIBLE VERSION
```
2.4.1.0
```

##### CONFIGURATION
N/A

##### OS / ENVIRONMENT
N/A

##### SUMMARY
When there is no network called `internal_network`, use of os_floating_ip module may throw an error that look like:

```
 
```

##### STEPS TO REPRODUCE
<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: Create floating IPs
  os_floating_ip:
      cloud: "some-cloud"
      network: "some_network"
      nat_destination: "some_nat"
      server: "some_server"
      state: present
      wait: yes
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Success.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/dn/bdsfszyj63569bgkwf1jsrw80000gn/T/ansible_GYIz2Z/ansible_module_os_floating_ip.py\", line 276, in <module>\n    main()\n  File \"/var/folders/dn/bdsfszyj63569bgkwf1jsrw80000gn/T/ansible_GYIz2Z/ansible_module_os_floating_ip.py\", line 215, in main\n    (nat_destination and f_ip.internal_network == fixed_address),\n  File \"/Users/ssbarnea/.pyenv/versions/2.7.13/lib/python2.7/site-packages/munch/__init__.py\", line 103, in __getattr__\n    raise AttributeError(k)\nAttributeError: internal_network\n",
```



Discussion:
cc @dagnello @emonty @j2sol @juliakreger @rcarrillocruz @shrews @thingee
[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/openstack/os_floating_ip.py b/lib/ansible/modules/cloud/openstack/os_floating_ip.py
--- a/lib/ansible/modules/cloud/openstack/os_floating_ip.py
+++ b/lib/ansible/modules/cloud/openstack/os_floating_ip.py
@@ -204,8 +204,21 @@ def main():
                     network_id = cloud.get_network(name_or_id=network)["id"]
                 else:
                     network_id = None
-                if all([(fixed_address and f_ip.fixed_ip_address == fixed_address) or
-                        (nat_destination and f_ip.internal_network == fixed_address),
+                # check if we have floting ip on given nat_destination network
+                if nat_destination:
+                    nat_floating_addrs = [addr for addr in server.addresses.get(
+                        cloud.get_network(nat_destination)['name'], [])
+                        if addr.addr == public_ip and
+                        addr['OS-EXT-IPS:type'] == 'floating']
+
+                    if len(nat_floating_addrs) == 0:
+                        module.fail_json(msg="server {server} already has a "
+                                             "floating-ip on a different "
+                                             "nat-destination than '{nat_destination}'"
+                                         .format(server=server_name_or_id,
+                                                 nat_destination=nat_destination))
+
+                if all([fixed_address, f_ip.fixed_ip_address == fixed_address,
                         network, f_ip.network != network_id]):
                     # Current state definitely conflicts with requirements
                     module.fail_json(msg="server {server} already has a "


Test patch: