Repository: ansible/ansible

Issue:
Timeout: Cannot save running-config with nxos_command or save: yes in nxos_config
##### ISSUE TYPE
- Bug Report
##### COMPONENT NAME

nxos_command
nxos_config
##### ANSIBLE VERSION

```
ansible 2.3.0~git20161010.03765ba
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
```
##### CONFIGURATION

inventory   = ./hosts
gathering = explicit
roles_path = /home/actionmystique/Program-Files/Ubuntu/Ansible/Roles/roles
private_role_vars = yes
log_path = /var/log/ansible.log
fact_caching = redis
fact_caching_timeout = 86400
retry_files_enabled = False
##### OS / ENVIRONMENT
- host: Ubuntu 16.04 4.4.0
- target: **NX-OSv 7.3(0)D1(1)**
##### SUMMARY

cf. title
##### STEPS TO REPRODUCE

**Inventory ./hosts**:

```
[all:vars]
nms_mgt_ip_address=172.21.100.1
[spines]
NX_OSv_Spine_11 ansible_host=172.21.100.11 
NX_OSv_Spine_12 ansible_host=172.21.100.12 
```

Structure passed as "**provider**": connections.ssh
Defined in group_vars/nx_osv/connections.yml and a symbolic link in roles/nxos_snmp/defaults points to nx_osv

```
connections
...
        nxapi:
          transport: nxapi
          host: "{{ ansible_host }}"
          # ansible_port
          port: "{{ http.port }}"
          # ansible_user
          username: admin
          password: xxxxxxxx
          # enable_secret_password
          auth_pass: xxxxxxxx
          # http or https
          use_ssl: no
          validate_certs: "{{ https.validate_certs }}"
```

**Role**: nxos_snmp:

```
- include_vars: "../defaults/{{ os_family }}/connections.yml"
...
- name: Saving the running-config
  nxos_command:
        provider: "{{ connections.nxapi }}"
        commands:
          - "copy running-config startup-config"
  register: result
```

**Playbook**:

```
- name: Configuring SNMP on NX-OS/NX-OSv
  hosts:
    - nx_osv
  roles:
    - nxos_snmp
```
##### EXPECTED RESULTS

We should be able to save the modifications.
##### ACTUAL RESULTS

```
TASK [nxos_snmp : Saving the running-config] ***********************************
fatal: [NX_OSv_Spine_12]: FAILED! => {"changed": false, "clierror": "Syntax error while parsing 'copy running-config startup-config  | xml '\n\n\nCmd exec error.\n", "code": "400", "failed": true, "input": "copy running-config startup-config", "msg": "Input CLI command error", "output": {"clierror": "Syntax error while parsing 'copy running-config startup-config  | xml '\n\n\nCmd exec error.\n", "code": "400", "input": "copy running-config startup-config", "msg": "Input CLI command error"}, "url": "http://172.21.100.12:8080/ins"}
```

No issue when configuring through the CLI:

```
NX_OSv_Spine_12# copy running-config startup-config 
[########################################] 100%
Copy complete.
NX_OSv_Spine_12# show startup-config

!Command: show startup-config
!Time: Mon Oct 10 18:12:08 2016
!Startup config saved at: Mon Oct 10 18:01:55 2016

version 7.3(0)D1(1)
power redundancy-mode redundant

```



Discussion:
This issue has been originally posted in ansible//ansible-modules-core [here](https://github.com/ansible/ansible-modules-core/issues/5215#issuecomment-265543826).
cc @jedelman8, @GGabriele, @privateip, @gundalow, @qalthos
[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_config.py b/lib/ansible/modules/network/nxos/nxos_config.py
--- a/lib/ansible/modules/network/nxos/nxos_config.py
+++ b/lib/ansible/modules/network/nxos/nxos_config.py
@@ -332,7 +332,8 @@ def main():
 
     if module.params['save']:
         if not module.check_mode:
-            run_commands(module, ['copy running-config startup-config'])
+            cmd = {'command': 'copy running-config startup-config', 'output': 'text'}
+            run_commands(module, [cmd])
         result['changed'] = True
 
     module.exit_json(**result)


Test patch: