Repository: ansible/ansible

Issue:
nxos_vpc* : failures seen on N1 images
<!---
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_vpc
- nxos_vpc_interface

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.4.0.0 (detached HEAD d14467b029) last updated 2017/09/22 13:55:10 (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.
-->
Ubuntu 14.04

##### SUMMARY
<!--- Explain the problem briefly -->
`show running-config section vpc` is an invalid command on N1 images. The correct command is `show running-config vpc` which works on all tested platforms.

 ##### 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
  - name: Configure vpc
    nxos_vpc: &conf_vpc
      state: present
      domain: 100
      role_priority: 500
      system_priority: 2000
      pkl_dest: 192.168.100.4
      pkl_src: 10.1.100.20
      pkl_vrf: ntc
      peer_gw: true
      delay_restore: 5
      auto_recovery: true
      provider: "{{ connection }}"
    register: result

  - assert: &true
      that:
        - "result.changed == true"

  - name: "Conf Idempotence"
    nxos_vpc: *conf_vpc
    register: result

  - assert: &false
      that:
        - "result.changed == false"
```

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
TASK [nxos_vpc : Conf Idempotence] ************************************************************************************************************************
task path: /root/agents-ci/ansible/test/integration/targets/nxos_vpc/tests/common/sanity.yaml:35
<n5k-xxx.example.com> connection transport is cli
<n5k-xxx.example.com> using connection plugin network_cli
<n5k-xxx.example.com> socket_path: /root/.ansible/pc/1b4e3e6315
Using module file /root/agents-ci/ansible/lib/ansible/modules/network/nxos/nxos_vpc.py
<n5k-xxx.example.com> ESTABLISH LOCAL CONNECTION FOR USER: root
<n5k-xxx.example.com> EXEC /bin/sh -c 'echo ~ && sleep 0'
<n5k-xxx.example.com> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1506021693.26-171102847106688 `" && echo ansible-tmp-1506021693.26-171102847106688="` echo /root/.ansible/tmp/ansible-tmp-1506021693.26-171102847106688 `" ) && sleep 0'
<n5k-xxx.example.com> PUT /tmp/tmpFZqODu TO /root/.ansible/tmp/ansible-tmp-1506021693.26-171102847106688/nxos_vpc.py
<n5k-xxx.example.com> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1506021693.26-171102847106688/ /root/.ansible/tmp/ansible-tmp-1506021693.26-171102847106688/nxos_vpc.py && sleep 0'
<n5k-xxx.example.com> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1506021693.26-171102847106688/nxos_vpc.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1506021693.26-171102847106688/" > /dev/null 2>&1 && sleep 0'
The full traceback is:
  File "/tmp/ansible_8gZfUw/ansible_modlib.zip/ansible/module_utils/nxos.py", line 127, in get_config
    return self._device_configs[cmd]
FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "auto_recovery": true, 
            "delay_restore": "5", 
            "domain": "100",  
            "host": "n5k-xxx.example.com", 
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
            "peer_gw": true,  
            "pkl_dest": "192.168.100.4", 
            "pkl_src": "10.1.100.20", 
            "pkl_vrf": "ntc", 
            "port": null, 
            "provider": {
                "host": "n5k-xxx.example.com",               
                "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
                "port": null, 
                "ssh_keyfile": null, 
                "timeout": null, 
                "transport": "cli", 
                "use_ssl": null, 
                "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
                "validate_certs": null
            }, 
            "role_priority": "500", 
            "ssh_keyfile": null, 
            "state": "present", 
            "system_priority": "2000", 
            "timeout": null,  
            "transport": "cli", 
            "use_ssl": null,  
            "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
            "validate_certs": null
        }
    }, 
    "msg": "show running-config section vpc\r\r\n                                ^\r\n% Invalid command at '^' marker.\r\n\rn5k-136# "
}
```



Discussion:
cc @GGabriele @jedelman8 @mikewiebe @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/nxos/nxos_vpc.py b/lib/ansible/modules/network/nxos/nxos_vpc.py
--- a/lib/ansible/modules/network/nxos/nxos_vpc.py
+++ b/lib/ansible/modules/network/nxos/nxos_vpc.py
@@ -181,7 +181,7 @@ def get_vpc(module):
         pkl_vrf = None
         peer_gw = False
 
-        run = get_config(module, flags=['section vpc'])
+        run = get_config(module, flags=['vpc'])
         if run:
             vpc_list = run.split('\n')
             for each in vpc_list:
diff --git a/lib/ansible/modules/network/nxos/nxos_vpc_interface.py b/lib/ansible/modules/network/nxos/nxos_vpc_interface.py
--- a/lib/ansible/modules/network/nxos/nxos_vpc_interface.py
+++ b/lib/ansible/modules/network/nxos/nxos_vpc_interface.py
@@ -131,7 +131,7 @@ def get_existing_portchannel_to_vpc_mappings(module):
 
 def peer_link_exists(module):
     found = False
-    run = get_config(module, flags=['section vpc'])
+    run = get_config(module, flags=['vpc'])
 
     vpc_list = run.split('\n')
     for each in vpc_list:
@@ -262,9 +262,10 @@ def main():
     active_peer_link = None
 
     if portchannel not in get_portchannel_list(module):
-        module.fail_json(msg="The portchannel you are trying to make a"
-                             " VPC or PL is not created yet. "
-                             "Create it first!")
+        if not portchannel.isdigit() or int(portchannel) not in get_portchannel_list(module):
+            module.fail_json(msg="The portchannel you are trying to make a"
+                                 " VPC or PL is not created yet. "
+                                 "Create it first!")
     if vpc:
         mapping = get_existing_portchannel_to_vpc_mappings(module)
 


Test patch: