Repository: ansible/ansible

Issue:
nxos_bgp_neighbor_af advertise-map* properties generate error
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
 - nxos_bgp_neighbor_af

##### NXOS VERSION
7.0(3)I5(3)

##### ANSIBLE VERSION
```
ansible 2.4.0 (devel d08ff86169) last updated 2017/06/30 13:58:00 (GMT -400)
  config file = None
  configured module search path = [u'/Users/mwiebe/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/mwiebe/Projects/nxos_ansible/fix_ansible/lib/ansible
  executable location = /Users/mwiebe/Projects/nxos_ansible/fix_ansible/bin/ansible
  python version = 2.7.13 (default, Apr  4 2017, 08:47:57) [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)]
```

##### OS / ENVIRONMENT
macOS

##### SUMMARY
The module errors out in latest `devel` when attempting to use the `advertise_map_exist` or `advertise_map_non_exist`.  The failure occurs for both transpots `cli` and `nxapi`.

##### STEPS TO REPRODUCE
```yaml
  - name: "Configure BGP neighbor address-family defaults"
    nxos_bgp_neighbor_af: &configure_default
      asn: 65535
      vrf: 'blue'
      neighbor: '3.3.3.3'
      afi: ipv4
      safi: unicast
      additional_paths_receive: 'inherit'
      additional_paths_send: 'inherit'
      advertise_map_exist: 'map_exist'
      allowas_in: 'false'
      allowas_in_max: 'default'
      as_override: 'false'
      default_originate: 'false'
      default_originate_route_map: 'default'
      filter_list_in: 'default'
      filter_list_out: 'default'
      next_hop_self: 'false'
      next_hop_third_party: 'true'
      prefix_list_in: 'default'
      prefix_list_out: 'default'
      route_map_in: 'default'
      route_map_out: 'default'
      route_reflector_client: 'false'
      send_community: 'default'
      soft_reconfiguration_in: 'inherit'
      soo: 'default'
      suppress_inactive: 'false'
      unsuppress_map: 'default'
      weight: 'default'
      state: present
      provider: "{{ cli }}"
```

##### EXPECTED RESULTS
Expect module to run clean.

##### ACTUAL RESULTS FOR TRANSPORT CLI or NXAPI

```shell
TASK [nxos_bgp_neighbor_af : Setup] *******************************************************************************************************************************************************************************************************************
ok: [n9k.example.com]

TASK [nxos_bgp_neighbor_af : Configure BGP neighbor address-family defaults] **************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: IndexError: tuple index out of range
fatal: [n9k.example.com]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/ww/538d42ys18l5tjyz0l1yk1rc0000gn/T/ansible_KxAk2i/ansible_module_nxos_bgp_neighbor_af.py\", line 761, in <module>\n    main()\n  File \"/var/folders/ww/538d42ys18l5tjyz0l1yk1rc0000gn/T/ansible_KxAk2i/ansible_module_nxos_bgp_neighbor_af.py\", line 745, in main\n    state_present(module, existing, proposed, candidate)\n  File \"/var/folders/ww/538d42ys18l5tjyz0l1yk1rc0000gn/T/ansible_KxAk2i/ansible_module_nxos_bgp_neighbor_af.py\", line 603, in state_present\n    commands.append('advertise-map {1} {0} {2}'.format(direction, *value))\nIndexError: tuple index out of range\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}

```


Discussion:
cc @jedelman8 @GGabriele @rahushen @privateip @rcarrillocruz @trishnaguha
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
The [documentation](https://docs.ansible.com/ansible/nxos_bgp_neighbor_af_module.html#options) suggests that `advertise_map_exist` and `advertise_map_non_exist` require two parameters, an advertise-map and a route-map. Modifying the playbook to match that causes the playbook to succeed. Is the documentation here in error?

Resolving patch:
diff --git a/lib/ansible/modules/network/nxos/nxos_bgp_neighbor_af.py b/lib/ansible/modules/network/nxos/nxos_bgp_neighbor_af.py
--- a/lib/ansible/modules/network/nxos/nxos_bgp_neighbor_af.py
+++ b/lib/ansible/modules/network/nxos/nxos_bgp_neighbor_af.py
@@ -305,8 +305,8 @@
     'neighbor': 'neighbor',
     'additional_paths_receive': 'capability additional-paths receive',
     'additional_paths_send': 'capability additional-paths send',
-    'advertise_map_exist': 'advertise-map',
-    'advertise_map_non_exist': 'advertise-map',
+    'advertise_map_exist': 'advertise-map exist',
+    'advertise_map_non_exist': 'advertise-map non-exist',
     'allowas_in': 'allowas-in',
     'allowas_in_max': 'allowas-in',
     'as_override': 'as-override',
@@ -599,7 +599,7 @@ def state_present(module, existing, proposed, candidate):
                 command += ' disable'
             commands.append(command)
         elif key.startswith('advertise-map'):
-            direction = key.split()[0]
+            direction = key.split()[1]
             commands.append('advertise-map {1} {0} {2}'.format(direction, *value))
         elif key in ['filter-list', 'prefix-list', 'route-map']:
             commands.append('{0} {1} {2}'.format(key, *value))


Test patch:
diff --git a/test/units/modules/network/nxos/test_nxos_bgp_neighbor_af.py b/test/units/modules/network/nxos/test_nxos_bgp_neighbor_af.py
--- a/test/units/modules/network/nxos/test_nxos_bgp_neighbor_af.py
+++ b/test/units/modules/network/nxos/test_nxos_bgp_neighbor_af.py
@@ -64,3 +64,19 @@ def test_nxos_bgp_neighbor_af_absent(self):
             changed=True, sort=False,
             commands=['router bgp 65535', 'neighbor 3.3.3.5', 'no address-family ipv4 unicast']
         )
+
+    def test_nxos_bgp_neighbor_af_advertise_map(self):
+        set_module_args(dict(asn=65535, neighbor='3.3.3.5', afi='ipv4', safi='unicast',
+                             advertise_map_exist=['my_advertise_map', 'my_exist_map']))
+        self.execute_module(
+            changed=True, sort=False,
+            commands=['router bgp 65535', 'neighbor 3.3.3.5', 'advertise-map my_advertise_map exist my_exist_map']
+        )
+
+    def test_nxos_bgp_neighbor_af_advertise_map_non_exist(self):
+        set_module_args(dict(asn=65535, neighbor='3.3.3.5', afi='ipv4', safi='unicast',
+                             advertise_map_non_exist=['my_advertise_map', 'my_exist_map']))
+        self.execute_module(
+            changed=True, sort=False,
+            commands=['router bgp 65535', 'neighbor 3.3.3.5', 'advertise-map my_advertise_map non-exist my_exist_map']
+        )