Repository: ansible/ansible

Issue:
net_static_route: module failure
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
net_static_route

##### ANSIBLE VERSION
```
ansible 2.4.0 (devel 189375c611) last updated 2017/08/30 14:29:33 (GMT -400)
  config file = /home/ec2-user/.ansible.cfg
  configured module search path = [u'/home/ec2-user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ec2-user/ansible/lib/ansible
  executable location = /home/ec2-user/ansible/bin/ansible
  python version = 2.7.5 (default, Aug  2 2016, 04:20:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
```

##### OS / ENVIRONMENT

Cisco IOS Software [Everest], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.5.1b

##### SUMMARY
Using net_static_route produces an error

##### STEPS TO REPRODUCE
```yaml
    - name: configure static route
      net_static_route:
        prefix: 172.18.2.0
        mask: 255.255.255.0
        nexthop: 10.0.0.2
```

##### EXPECTED RESULTS
Static route being configured, similar to:
```
ip route 172.18.2.0 255.255.255.0 10.0.0.2
```

##### ACTUAL RESULTS
```
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_VSnrSv/ansible_module_ios_static_route.py", line 235, in <module>
    main()
  File "/tmp/ansible_VSnrSv/ansible_module_ios_static_route.py", line 221, in main
    have = map_config_to_obj(module)
  File "/tmp/ansible_VSnrSv/ansible_module_ios_static_route.py", line 140, in map_config_to_obj
    cidr = ip_network(to_text(splitted_line[1]))
  File "/usr/lib/python2.7/site-packages/ipaddress.py", line 204, in ip_network
    address)
ValueError: u'[1/0]' does not appear to be an IPv4 or IPv6 network

fatal: [student1-rtr1.net-ws.redhatgov.io]: FAILED! => {
    "ansible_facts": {
        "network_os": "ios"
    },
    "changed": false,
    "failed": true,
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_VSnrSv/ansible_module_ios_static_route.py\", line 235, in <module>\n    main()\n  File \"/tmp/ansible_VSnrSv/ansible_module_ios_static_route.py\", line 221, in main\n    have = map_config_to_obj(module)\n  File \"/tmp/ansible_VSnrSv/ansible_module_ios_static_route.py\", line 140, in map_config_to_obj\n    cidr = ip_network(to_text(splitted_line[1]))\n  File \"/usr/lib/python2.7/site-packages/ipaddress.py\", line 204, in ip_network\n    address)\nValueError: u'[1/0]' does not appear to be an IPv4 or IPv6 network\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE",
    "rc": 0
}
```



Discussion:
cc @Qalthos @ganeshrn @gundalow @privateip @rcarrillocruz @trishnaguha
[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/network/ios/ios_static_route.py b/lib/ansible/modules/network/ios/ios_static_route.py
--- a/lib/ansible/modules/network/ios/ios_static_route.py
+++ b/lib/ansible/modules/network/ios/ios_static_route.py
@@ -137,6 +137,11 @@ def map_config_to_obj(module):
         for r in match.group(1).splitlines():
             splitted_line = r.split()
 
+            code = splitted_line[0]
+
+            if code != 'M':
+                continue
+
             cidr = ip_network(to_text(splitted_line[1]))
             prefix = str(cidr.network_address)
             mask = str(cidr.netmask)


Test patch: