Repository: ansible/ansible

Issue:
(P1) nxos_snapshot compare does not work
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
nxos_snapshot

##### ANSIBLE VERSION
```
ansible 2.4.0 (devel 54cd641df4) last updated 2017/07/19 18:06:44 (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/p2/Projects/nxos_ansible/p1_ansible/lib/ansible
  executable location = /root/p2/Projects/nxos_ansible/p1_ansible/bin/ansible
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
```

##### OS / ENVIRONMENT
Ansible Server : Ubuntu 14.04
Device: Nexus7000 C7010 running 8.1(1)

##### SUMMARY
When we try to compare 2 snapshots, it is supposed save the difference in a file but nothing happens. The issue seems to be that, there is a method write_on_file() defined but never getting called. So basically, the output of the compare is just thrown away once the task is complete and the properties "comparison_results_file", "path" and "save_snapshot_locally" are never being used.

##### STEPS TO REPRODUCE
playbook:

```
- name: create snapshot
  nxos_snapshot:
    action: create
    snapshot_name: test_snapshot1
    description: Ansible
    provider: "{{ cli }}"

- nxos_snapshot:
    action: create
    snapshot_name: test_snapshot2
    description: row
    section: myshow
    show_command: show ip interface brief
    row_id: ROW_intf
    element_key1: intf-name
    provider: "{{ cli }}"

- nxos_snapshot:
    action: compare
    snapshot1: test_snapshot1
    snapshot2: test_snapshot2
    comparison_results_file: compare_snapshots.txt
    compare_option: summary
    path: '/root/p2'
    provider: "{{ cli }}"

- name: delete snapshot
  nxos_snapshot:
    action: delete_all
    snapshot_name: test_snapshot
    provider: "{{ cli }}"
```

##### EXPECTED RESULTS
A file "compare_snapshots.txt" should be created in the given path.

##### ACTUAL RESULTS
Nothing happens, no file is created.



Discussion:
cc @GGabriele @jedelman8 @mikewiebe @privateip @rahushen @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_snapshot.py b/lib/ansible/modules/network/nxos/nxos_snapshot.py
--- a/lib/ansible/modules/network/nxos/nxos_snapshot.py
+++ b/lib/ansible/modules/network/nxos/nxos_snapshot.py
@@ -397,12 +397,27 @@ def main():
     if not module.check_mode:
         if action == 'compare':
             result['commands'] = []
+
+            if module.params['path'] and comparison_results_file:
+                snapshot1 = module.params['snapshot1']
+                snapshot2 = module.params['snapshot2']
+                compare_option = module.params['compare_option']
+                command = 'show snapshot compare {0} {1} {2}'.format(snapshot1, snapshot2, compare_option)
+                content = execute_show_command(command, module)[0]
+                if content:
+                    write_on_file(content, comparison_results_file, module)
         else:
             if action_results:
                 load_config(module, action_results)
                 result['commands'] = action_results
                 result['changed'] = True
 
+            if action == 'create' and module.params['path']:
+                command = 'show snapshot | include {}'.format(module.params['snapshot_name'])
+                content = execute_show_command(command, module)[0]
+                if content:
+                    write_on_file(content, module.params['snapshot_name'], module)
+
     module.exit_json(**result)
 
 if __name__ == '__main__':


Test patch: