Repository: ansible/ansible

Issue:
(P2)nxos_bgp_neighbor - several properties not idempotent
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
- nxos_bgp_neighbor

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
 ansible 2.4.0 (devel 6bed831f8c) last updated 2017/06/27 15:24:19 (GMT -400)
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  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
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
- Ansible Server : Ubuntu 14.04
- Device: Nexus9000 C9508  running 7.0(3)I6(1)

##### SUMMARY
<!--- Explain the problem briefly -->
Several properties are not idempotent

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
---
cli:
  host: "{{ inventory_hostname }}"
  username: "{{ nxos_cli_user | default('admin') }}"
  password: "{{ nxos_cli_pass | default('admin') }}"

nxapi:
  host: "{{ inventory_hostname }}"
  username: "{{ nxos_nxapi_user | default('admin') }}"
  password: "{{ nxos_nxapi_pass | default('admin') }}"
  transport: nxapi
  user_ssl: no

---
- name: NXOS Sample Playbook
  hosts: nxos
  connection: local
  gather_facts: no

  tasks:

  - name: Ensure BGP Is Enabled
    nxos_feature:
      feature: bgp
      state: enabled
      provider: "{{ cli }}"

  - name: "Configure BGP neighbor"
    nxos_bgp_neighbor: &configure_non_default
      asn: 65535
      neighbor: 3.3.3.3
      description: "tested by ansible"
      connected_check: true
      capability_negotiation: true
      dynamic_capability: true
      ebgp_multihop: 2
      log_neighbor_changes: enable
      low_memory_exempt: true
      remote_as: 12.1
      remove_private_as: all
      suppress_4_byte_as: true
      update_source: loopback151
      state: present
      provider: "{{ cli }}"
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
expected playbook to be ok the second time instead of 'changed'.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
PLAY [NXOS Sample Playbook] ***********************************************************************************************************************************************************************************************************************************

TASK [Ensure BGP Is Enabled] **********************************************************************************************************************************************************************************************************************************
ok: [nxxxx-xxx.example.com]

TASK [Configure BGP neighbor] *********************************************************************************************************************************************************************************************************************************
changed: [nxxxx-xxx.example.com]

PLAY RECAP ****************************************************************************************************************************************************************************************************************************************************
nxxxx-xxx.example.com          : ok=2    changed=1    unreachable=0    failed=0
```



Discussion:
cc @jedelman8 @GGabriele @privateip @rcarrillocruz @mikewiebe @trishnaguha
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Hi @rahushen. What version of Ansible are you using?
needs_info
@s-hertel updated issue with ansible version.

Resolving patch:
diff --git a/lib/ansible/modules/network/nxos/nxos_bgp_neighbor.py b/lib/ansible/modules/network/nxos/nxos_bgp_neighbor.py
--- a/lib/ansible/modules/network/nxos/nxos_bgp_neighbor.py
+++ b/lib/ansible/modules/network/nxos/nxos_bgp_neighbor.py
@@ -198,7 +198,6 @@
     remote_as: 30
     description: "just a description"
     update_source: Ethernet1/3
-    shutdown: default
     state: present
 '''
 
@@ -266,13 +265,15 @@ def get_value(arg, config):
     has_command = re.search(r'\s+{0}\s*$'.format(command), config, re.M)
     has_command_value = re.search(r'(?:{0}\s)(?P<value>.*)$'.format(command), config, re.M)
 
-    if arg in BOOL_PARAMS:
-        value = False
-        try:
-            if has_command:
-                value = True
-        except TypeError:
+    if arg == 'dynamic_capability':
+        has_no_command = re.search(r'\s+no\s{0}\s*$'.format(command), config, re.M)
+        value = True
+        if has_no_command:
             value = False
+    elif arg in BOOL_PARAMS:
+        value = False
+        if has_command:
+            value = True
     elif arg == 'log_neighbor_changes':
         value = ''
         if has_command:
@@ -389,10 +390,10 @@ def state_present(module, existing, proposed, candidate):
                 else:
                     command = '{0} {1}'.format(key, value)
                     commands.append(command)
-            elif key.startswith('timers'):
+            elif key == 'timers':
                 command = 'timers {0} {1}'.format(
-                    proposed_commands['timers-keepalive'],
-                    proposed_commands['timers-holdtime'])
+                    proposed['timers_keepalive'],
+                    proposed['timers_holdtime'])
                 if command not in commands:
                     commands.append(command)
             else:
@@ -442,7 +443,7 @@ def main():
         pwd_type=dict(required=False, type='str', choices=['cleartext', '3des', 'cisco_type_7', 'default']),
         remote_as=dict(required=False, type='str'),
         remove_private_as=dict(required=False, type='str', choices=['enable', 'disable', 'all', 'replace-as']),
-        shutdown=dict(required=False, type='str'),
+        shutdown=dict(required=False, type='bool'),
         suppress_4_byte_as=dict(required=False, type='bool'),
         timers_keepalive=dict(required=False, type='str'),
         timers_holdtime=dict(required=False, type='str'),


Test patch: