Repository: ansible/ansible

Issue:
sros_config does not run commands correctly in Ansible 2.3
<!---
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 -->
Module sros_config

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.3.0.0
  config file =
  configured module search path = Default w/o overrides
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### OS / ENVIRONMENT
CentOS-7

##### SUMMARY
<!--- Explain the problem briefly -->
sros_config module is not running commands input from file properly in Ansible 2.3. The very basic functionality of feeding in tab-aligned input files causes failures as Ansible is running commands on wrong levels of CLI.

##### 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 -->
When I'm using this input file for sros_config:
```
configure
    system
        name "{{ inventory_hostname }}"
        time
            ntp
                ntp-server authenticate
```

The result is that sros_config tries to run "_ntp-server authenticate_" directly under "_config>system>time_" in SROS, while it should be run in level "config>system>time>*ntp*". Now command "ntp" is not executed at all and therefore "bad command" error appears.
The same input file **worked fine with Ansible 2.2**.

```
"msg": "ntp-server authenticate\r\n                                  ^\r\nError: Bad command. \r\n*A:cont2-dev2>config>system>time# "
```
<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
sros_config shall follow the command hierarchy given in input file and run command "ntp" before running "ntp-server authenticate"

This is how the commands are run manually:
```
*A:cont2-dev2# configure
*A:cont2-dev2>config# system
*A:cont2-dev2>config>system# time
*A:cont2-dev2>config>system>time# ntp
*A:cont2-dev2>config>system>time>ntp# ntp-server authenticate
```

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
fatal: [cont2-dev2 -> localhost]: FAILED! => {
    "changed": false,
    "command": "ntp-server authenticate",
    "failed": true,
    "invocation": {
        "module_args": {
            "backup": false,
            "config": null,
            "defaults": false,
            "host": null,
            "lines": null,
            "match": "line",
            "parents": null,
            "password": null,
            "port": null,
            "provider": {
                "host": "10.2.210.64",
                "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "port": null,
                "ssh_keyfile": null,
                "timeout": null,
                "transport": "cli",
                "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
            },
            "save": true,
            "src": "configure\n    system\n        name \"cont2-dev2\"\n        time\n            ntp \n                ntp-server authenticate\n",
            "ssh_keyfile": null,
            "timeout": null,
            "username": null
        }
    },
    "msg": "ntp-server authenticate\r\n                                  ^\r\nError: Bad command. \r\n*A:cont2-dev2>config>system>time# ",
    "rc": 1
}
```



Discussion:
cc @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/sros/sros_config.py b/lib/ansible/modules/network/sros/sros_config.py
--- a/lib/ansible/modules/network/sros/sros_config.py
+++ b/lib/ansible/modules/network/sros/sros_config.py
@@ -210,18 +210,8 @@
 """
 from ansible.module_utils.basic import AnsibleModule
 from ansible.module_utils.netcfg import NetworkConfig, dumps
-from ansible.module_utils.sros import sros_argument_spec, check_args, load_config, run_commands, get_config
-
-
-def sanitize_config(lines):
-    commands = list()
-    for line in lines:
-        for index, entry in enumerate(commands):
-            if line.startswith(entry):
-                del commands[index]
-                break
-        commands.append(line)
-    return commands
+from ansible.module_utils.sros import sros_argument_spec, check_args
+from ansible.module_utils.sros import load_config, run_commands, get_config
 
 
 def get_active_config(module):
@@ -258,7 +248,7 @@ def run(module, result):
 
     if configobjs:
         commands = dumps(configobjs, 'commands')
-        commands = sanitize_config(commands.split('\n'))
+        commands = commands.split('\n')
 
         result['commands'] = commands
         result['updates'] = commands


Test patch: