Repository: ansible/ansible

Issue:
(P2) nxos_pim_rp_address is not idempotent
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
 - nxos_pim_rp_address

##### NXOS VERSION
All versions

##### ANSIBLE VERSION
```
ansible 2.4.0 (devel 0fb64214a4) last updated 2017/07/27 13:55:58 (GMT -400)
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/usr/share/ansible']
  ansible python module location = /root/agents-ci/ansible/lib/ansible
  executable location = /root/agents-ci/ansible/bin/ansible
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
```

##### OS / ENVIRONMENT
Ubuntu 14.04

##### SUMMARY
The following playbook demonstrates the idempotency problem for the group_list, prefix_list and route_map properties.  Problem is present for both `cli` and `nxapi` transports.

```yaml
---
- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_pim_rp_address sanity test"

- name: "Disable feature PIM"
  nxos_feature: &disable_feature
    feature: pim
    state: disabled
    provider: "{{ connection }}"

- name: "Enable feature PIM"
  nxos_feature:
    feature: pim
    state: enabled
    provider: "{{ connection }}"

# The group_list, prefix_list and route_map properties
# are mutually exclusive, so test them independently.
- block:
  - name: Configure rp_address + group_list 
    nxos_pim_rp_address: &configgl
      rp_address: "10.1.1.20"
      #group_list: "224.0.0.0/8"
      #prefix_list: "pim_prefix_list"
      route_map: "pim_routemap"
      bidir: true 
      state: present
      provider: "{{ connection }}"
    register: result

  - assert: &true
      that:
        - "result.changed == true"

  - name: Check idempotence
    nxos_pim_rp_address: *configgl
    register: result

  - assert: &false
      that:
        - "result.changed == false"

  always:
  - name: "Disable feature PIM"
    nxos_feature: *disable_feature

  - debug: msg="END TRANSPORT:{{ connection.transport }} nxos_pim_rp_address sanity test"
```




Discussion:
cc @GGabriele @jedelman8 @privateip @rahushen @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/nxos/nxos_pim_rp_address.py b/lib/ansible/modules/network/nxos/nxos_pim_rp_address.py
--- a/lib/ansible/modules/network/nxos/nxos_pim_rp_address.py
+++ b/lib/ansible/modules/network/nxos/nxos_pim_rp_address.py
@@ -33,7 +33,7 @@
 author: Gabriele Gerbino (@GGabriele)
 notes:
   - Tested against NXOSv 7.3.(0)D1(1) on VIRL
-  - C(state=absent) remove the whole rp-address configuration, if existing.
+  - C(state=absent) is currently not supported on all platforms.
 options:
   rp_address:
     description:
@@ -102,12 +102,12 @@ def get_existing(module, args):
 
         existing['bidir'] = existing.get('bidir') or 'bidir' in line
         if len(values) > 2:
-            value = values[1]
-            if values[2] == 'route-map':
+            value = values[2]
+            if values[1] == 'route-map':
                 existing['route_map'] = value
-            elif values[2] == 'prefix-list':
+            elif values[1] == 'prefix-list':
                 existing['prefix_list'] = value
-            elif values[2] == 'group-list':
+            elif values[1] == 'group-list':
                 existing['group_list'] = value
 
     return existing


Test patch: