Repository: ansible/ansible

Issue:
(P2) nxos_pim is not idempotent
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
 - nxos_pim

##### NXOS VERSION
7.0(3)I5(3), 8.0(1)

##### 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 issue.  Same problem for both transports.

```yaml
---
- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_pim 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 }}"

- block:
  - name: Configure ssm_range
    nxos_pim: &configure
      ssm_range: "232.0.0.0/8"
      provider: "{{ connection }}"
    register: result

  - assert: &true
      that:
        - "result.changed == true"

  - name: Check idempotence
    nxos_pim: *configure
    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 sanity test"
```

```shell
TASK [nxos_pim : debug] ***************************************************************************************************************************************************************************************************************************************
ok: [n7k.example.com] => {
    "msg": "START TRANSPORT:nxapi nxos_pim sanity test"
}

TASK [nxos_pim : Disable feature PIM] *************************************************************************************************************************************************************************************************************************
ok: [n7k.example.com]

TASK [nxos_pim : Enable feature PIM] **************************************************************************************************************************************************************************************************************************
changed: [n7k.example.com]

TASK [nxos_pim : Configure ssm_range] *************************************************************************************************************************************************************************************************************************
changed: [n7k.example.com]

TASK [nxos_pim : assert] **************************************************************************************************************************************************************************************************************************************
ok: [n7k.example.com] => {
    "changed": false, 
    "failed": false, 
    "msg": "All assertions passed"
}

TASK [nxos_pim : Check idempotence] ***************************************************************************************************************************************************************************************************************************
changed: [n7k.example.com]

TASK [nxos_pim : assert] **************************************************************************************************************************************************************************************************************************************
fatal: [n7k.example.com]: FAILED! => {
    "assertion": "result.changed == false", 
    "changed": false, 
    "evaluated_to": false, 
    "failed": true
}

TASK [nxos_pim : Disable feature PIM] *************************************************************************************************************************************************************************************************************************
changed: [n7k.example.com]

TASK [nxos_pim : debug] ***************************************************************************************************************************************************************************************************************************************
ok: [n7k.example.com] => {
    "msg": "END TRANSPORT:nxapi nxos_pim sanity test"
}
	to retry, use: --limit @/root/agents-ci/ansible/test/integration/nxos.retry

PLAY RECAP ****************************************************************************************************************************************************************************************************************************************************
n7k.example.com           : ok=24   changed=6    unreachable=0    failed=1   
```


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.py b/lib/ansible/modules/network/nxos/nxos_pim.py
--- a/lib/ansible/modules/network/nxos/nxos_pim.py
+++ b/lib/ansible/modules/network/nxos/nxos_pim.py
@@ -70,7 +70,7 @@ def get_existing(module, args):
 
     for arg in args:
         command = PARAM_TO_COMMAND_KEYMAP[arg]
-        has_command = re.match(r'(?:{0}\s)(?P<value>.*)$'.format(command), config, re.M)
+        has_command = re.search(r'^{0}\s(?P<value>.*)$'.format(command), config, re.M)
 
         value = ''
         if has_command:


Test patch: