Repository: ansible/ansible

Issue:
dellos6_config takes action despite check_mode
##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
dellos6_config

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.3.1.0
  config file = /home/lgarrett/Coding/playbook2/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118]

```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
```
$ cat ansible.cfg
[defaults]
ansible_managed         = Ansible managed: Any changes will be overwritten!
display_args_to_stdout  = true
force_color             = true
forks                   = 100
hash_behaviour          = merge
inventory               = intranet
nocows                  = 1
remote_user             = root
retry_files_enabled     = false
roles_path              = roles:roles/windows
strategy                = linear

[ssh_connection]
pipelining  = true
```
##### 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.
-->
Debian 9 with ansible 2.3.1 on the controller, DellOS 6.2.7.2 on the switch.

##### SUMMARY
The dellos6_config module will take action and make a backup, even if running with --check on the command line. Example below.

##### 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
$ cat dellos.yml
---

- hosts: dellos6-host
  connection: local
  gather_facts: no
  tasks:
    - name: Backup config
      dellos6_config:
        authorize:  yes
        backup:     yes
        host:       "{{ inventory_hostname }}"
        username:   admin

```

```
$ ll backup/
total 12
drwxr-xr-x  2 lgarrett lgarrett 4096 Aug 31 14:44 .
drwxr-xr-x 13 lgarrett lgarrett 4096 Aug 31 14:44 ..
-rw-r--r--  1 lgarrett lgarrett 2535 Aug 31 14:44 switch_config.2017-08-31@14:44:37
$ ansible-playbook dellos.yml --diff --check

PLAY [switch] **************************************************************************************************************************************

TASK [Backup config authorize=True, username=admin, host={{ inventory_hostname }}, backup=True] ****
 [WARNING]: argument username has been deprecated and will be removed in a future version

 [WARNING]: argument authorize has been deprecated and will be removed in a future version

 [WARNING]: argument host has been deprecated and will be removed in a future version

ok: [switch]

PLAY RECAP **************************************************************************************************************************************
switch : ok=1    changed=0    unreachable=0    failed=0

$ ll backup/
total 12
drwxr-xr-x  2 lgarrett lgarrett 4096 Aug 31 15:34 .
drwxr-xr-x 13 lgarrett lgarrett 4096 Aug 31 14:44 ..
-rw-r--r--  1 lgarrett lgarrett 2535 Aug 31 15:34 switch_config.2017-08-31@15:34:02
```

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
I expected it to do nothing, since we're running in check mode.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
It created a new backup in ./backup/ (and deleted the old file, but that's a separate bug)



Discussion:
cc @abirami-n @skg-net
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
@leegarrett Thanks for reporting the issue, we will get back to you.

Resolving patch:
diff --git a/lib/ansible/modules/network/dellos10/dellos10_config.py b/lib/ansible/modules/network/dellos10/dellos10_config.py
--- a/lib/ansible/modules/network/dellos10/dellos10_config.py
+++ b/lib/ansible/modules/network/dellos10/dellos10_config.py
@@ -255,7 +255,8 @@ def main():
         configobjs = candidate.items
 
     if module.params['backup']:
-        result['__backup__'] = get_config(module)
+        if not module.check_mode:
+            result['__backup__'] = get_config(module)
 
     commands = list()
 
diff --git a/lib/ansible/modules/network/dellos6/dellos6_config.py b/lib/ansible/modules/network/dellos6/dellos6_config.py
--- a/lib/ansible/modules/network/dellos6/dellos6_config.py
+++ b/lib/ansible/modules/network/dellos6/dellos6_config.py
@@ -249,7 +249,8 @@ def main():
     else:
         configobjs = candidate.items
     if module.params['backup']:
-        result['__backup__'] = get_config(module)
+        if not module.check_mode:
+            result['__backup__'] = get_config(module)
 
     commands = list()
 
diff --git a/lib/ansible/modules/network/dellos9/dellos9_config.py b/lib/ansible/modules/network/dellos9/dellos9_config.py
--- a/lib/ansible/modules/network/dellos9/dellos9_config.py
+++ b/lib/ansible/modules/network/dellos9/dellos9_config.py
@@ -261,7 +261,8 @@ def main():
         configobjs = candidate.items
 
     if module.params['backup']:
-        result['__backup__'] = get_config(module)
+        if not module.check_mode:
+            result['__backup__'] = get_config(module)
 
     commands = list()
 


Test patch: