Repository: ansible/ansible

Issue:
Ordering issue in networking modules
##### ISSUE TYPE
- Bug Report
##### ANSIBLE VERSION

```
ansible 2.1.0
  config file =
  configured module search path = Default w/o overrides
```
##### CONFIGURATION

N/A
##### OS / ENVIRONMENT

N/A
##### SUMMARY

The networking modules can change the order of the configuration when using the *_config modules. This behaviour only occur when you don't use the parents: argument in the task.
##### STEPS TO REPRODUCE

```

---
-  hosts: all
   connection: local
   gather_facts: false
   vars_files:
     - vars/creds.yml
   tasks:
     - name: Create ACL
       ios_config:
         host: "{{ inventory_hostname }}"
         provider: "{{ cli }}"
         commands:
           - access-list 140 permit ip 192.168.10.0 0.0.0.255 any
           - access-list 140 permit ip 192.168.20.0 0.0.0.255 any
           - access-list 140 permit ip 192.168.30.0 0.0.0.255 any
           - access-list 140 permit ip 192.168.40.0 0.0.0.255 any
```

<!--- You can also paste gist.github.com links for larger files -->
##### EXPECTED RESULTS

The expected result is that this playbook should create an access-list looking like this:

```
access-list 140 permit ip 192.168.10.0 0.0.0.255 any
access-list 140 permit ip 192.168.20.0 0.0.0.255 any
access-list 140 permit ip 192.168.30.0 0.0.0.255 any
access-list 140 permit ip 192.168.40.0 0.0.0.255 any
```
##### ACTUAL RESULTS

Instead Ansible changes the order of the configuration which results in an access-list looking like this:

```
access-list 140 permit ip 192.168.30.0 0.0.0.255 any
access-list 140 permit ip 192.168.40.0 0.0.0.255 any
access-list 140 permit ip 192.168.10.0 0.0.0.255 any
access-list 140 permit ip 192.168.20.0 0.0.0.255 any
```
#### "SCREENSHOT"

```
 ansible-playbook -i hosts playbook.yml -v
No config file found; using defaults

PLAY [all] *********************************************************************

TASK [Create ACL] **************************************************************
changed: [nap-cmts-2] => {"changed": true, "responses": ["", "", "", ""], "updates": ["access-list 140 permit ip 192.168.30.0 0.0.0.255 any", "access-list 140 permit ip 192.168.40.0 0.0.0.255 any", "access-list 140 permit ip 192.168.10.0 0.0.0.255 any", "access-list 140 permit ip 192.168.20.0 0.0.0.255 any"]}
```



Discussion:
Hi!

Thanks very much for your interest in Ansible.  It sincerely means a lot to us. 

On September 26, 2014, due to enormous levels of contribution to the project Ansible decided to reorganize module repos, making it easier
for developers to work on the project and for us to more easily manage new contributions and tickets.

We split modules from the main project off into two repos, http://github.com/ansible/ansible-modules-core and http://github.com/ansible/ansible-modules-extras

If you would still like this ticket attended to, we will need your help in having it reopened in one of the two new repos, and instructions are provided below.

We apologize that we are not able to make this transition happen seamlessly, though this is a one-time change and your help is greatly appreciated -- 
this will greatly improve velocity going forward.

Both sets of modules will ship with Ansible, though they'll receive slightly different ticket handling.

To locate where a module lives between 'core' and 'extras'
- Find the module at http://docs.ansible.com/list_of_all_modules.html
- Open the documentation page for that module
- If the bottom of the docs say "This is an extras module", submit your ticket to https://github.com/ansible/ansible-modules-extras
- Otherwise, submit your pull request to update the existing module to https://github.com/ansible/ansible-modules-core
- action_plugins (modules with server side components) still live in the main repo.  If your ticket affects both, open the ticket
   on the module repo just the same.

Additionally, should you need more help with this, you can ask questions on:
- the ansible-project mailing list: https://groups.google.com/forum/#!forum/ansible-project

Thank you very much!

I'm going to reopen this issue as its actually tied to the netcfg.py shared module which is used across networking modules and makes more sense to track it here than in individual modules.  


Resolving patch:
diff --git a/lib/ansible/module_utils/netcfg.py b/lib/ansible/module_utils/netcfg.py
--- a/lib/ansible/module_utils/netcfg.py
+++ b/lib/ansible/module_utils/netcfg.py
@@ -229,7 +229,7 @@ def difference(self, other, path=None, match='line', replace='line'):
         if self._device_os == 'junos':
             return updates
 
-        diffs = dict()
+        diffs = collections.OrderedDict()
         for update in updates:
             if replace == 'block' and update.parents:
                 update = update.parents[-1]


Test patch: