Repository: ansible/ansible

Issue:
ios_system does not disable ip domain lookup
<!---
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: ios_system

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.3.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, Jul 21 2017, 03:24:34) [GCC 7.1.1 20170630]
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
N/A

##### 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.
-->
Archlinux

##### SUMMARY
<!--- Explain the problem briefly -->
The ios_system module will not set `no ip domain lookup` even if lookup_enabled is set to no.

##### 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
- hosts: ios_devices
  connection: local
  tasks:
    - name: Configure System
      ios_system:
        lookup_enabled: no
```
```
csr-test1#show run | i domain
ip domain name ansible.test
csr-test1#
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
`no ip domain lookup` will be executed on the device

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->


<!--- Paste verbatim command output between quotes below -->
```
[~/ansible-test]$ ansible-playbook -i inventory system.yml -vvvv        
Using /etc/ansible/ansible.cfg as config file
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc

PLAYBOOK: system.yml **********************************************************************************************************************************************************************************************
1 plays in system.yml

PLAY [ios_devices] ************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
Using module file /usr/lib/python2.7/site-packages/ansible/modules/system/setup.py
<csr-test1> ESTABLISH LOCAL CONNECTION FOR USER: paul
<csr-test1> EXEC /bin/sh -c 'echo ~ && sleep 0'
<csr-test1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/paul/.ansible/tmp/ansible-tmp-1505221356.82-128997150227344 `" && echo ansible-tmp-1505221356.82-128997150227344="` echo /home/paul/.ansible/tmp/ansible-tmp-1505221356.82-128997150227344 `" ) && sleep 0'
<csr-test1> PUT /tmp/tmpxervRc TO /home/paul/.ansible/tmp/ansible-tmp-1505221356.82-128997150227344/setup.py
<csr-test1> EXEC /bin/sh -c 'chmod u+x /home/paul/.ansible/tmp/ansible-tmp-1505221356.82-128997150227344/ /home/paul/.ansible/tmp/ansible-tmp-1505221356.82-128997150227344/setup.py && sleep 0'
<csr-test1> EXEC /bin/sh -c '/usr/bin/python /home/paul/.ansible/tmp/ansible-tmp-1505221356.82-128997150227344/setup.py; rm -rf "/home/paul/.ansible/tmp/ansible-tmp-1505221356.82-128997150227344/" > /dev/null 2>&1 && sleep 0'
ok: [csr-test1]
META: ran handlers

TASK [Configure System] *******************************************************************************************************************************************************************************************
task path: /home/paul/ansible-test/system.yml:4
<csr-test1> using connection plugin network_cli
<csr-test1> socket_path: /home/paul/.ansible/pc/9ab465d0f7
open_shell() returned 0 ok 
Using module file /usr/lib/python2.7/site-packages/ansible/modules/network/ios/ios_system.py
<csr-test1> ESTABLISH LOCAL CONNECTION FOR USER: paul
<csr-test1> EXEC /bin/sh -c 'echo ~ && sleep 0'
<csr-test1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/paul/.ansible/tmp/ansible-tmp-1505221359.24-200115829271165 `" && echo ansible-tmp-1505221359.24-200115829271165="` echo /home/paul/.ansible/tmp/ansible-tmp-1505221359.24-200115829271165 `" ) && sleep 0'
<csr-test1> PUT /tmp/tmpuzf5Iy TO /home/paul/.ansible/tmp/ansible-tmp-1505221359.24-200115829271165/ios_system.py
<csr-test1> EXEC /bin/sh -c 'chmod u+x /home/paul/.ansible/tmp/ansible-tmp-1505221359.24-200115829271165/ /home/paul/.ansible/tmp/ansible-tmp-1505221359.24-200115829271165/ios_system.py && sleep 0'
<csr-test1> EXEC /bin/sh -c '/usr/bin/python /home/paul/.ansible/tmp/ansible-tmp-1505221359.24-200115829271165/ios_system.py; rm -rf "/home/paul/.ansible/tmp/ansible-tmp-1505221359.24-200115829271165/" > /dev/null 2>&1 && sleep 0'
 [WARNING]: argument username has been deprecated and will be removed in a future version

 [WARNING]: argument password has been deprecated and will be removed in a future version

ok: [csr-test1] => {
    "changed": false, 
    "commands": [], 
    "invocation": {
        "module_args": {
            "auth_pass": null, 
            "authorize": null, 
            "domain_name": null, 
            "domain_search": null, 
            "host": null, 
            "hostname": null, 
            "lookup_enabled": false, 
            "lookup_source": null, 
            "name_servers": null, 
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
            "port": null, 
            "provider": null, 
            "ssh_keyfile": null, 
            "state": "present", 
            "timeout": null, 
            "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
        }
    }
}
META: ran handlers
META: ran handlers

PLAY RECAP ********************************************************************************************************************************************************************************************************
csr-test1                  : ok=2    changed=0    unreachable=0    failed=0   

```



Discussion:
cc @privateip @rcarrillocruz
[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/ios/ios_system.py b/lib/ansible/modules/network/ios/ios_system.py
--- a/lib/ansible/modules/network/ios/ios_system.py
+++ b/lib/ansible/modules/network/ios/ios_system.py
@@ -146,7 +146,7 @@ def map_obj_to_commands(want, have, module):
     commands = list()
     state = module.params['state']
 
-    needs_update = lambda x: want.get(x) and (want.get(x) != have.get(x))
+    needs_update = lambda x: want.get(x) is not None and (want.get(x) != have.get(x))
 
     if state == 'absent':
         if have['hostname'] != 'Router':


Test patch:
diff --git a/test/integration/targets/ios_system/tests/cli/set_lookup_source.yaml b/test/integration/targets/ios_system/tests/cli/set_lookup_source.yaml
--- a/test/integration/targets/ios_system/tests/cli/set_lookup_source.yaml
+++ b/test/integration/targets/ios_system/tests/cli/set_lookup_source.yaml
@@ -33,6 +33,30 @@
     that:
       - result.changed == false
 
+- name: Disable lookup_source
+  ios_system:
+    lookup_enabled: False
+    provider: "{{ cli }}"
+    authorize: yes
+  register: result
+
+- assert:
+    that:
+      - result.changed == true
+      - "'no ip domain lookup' in result.commands"
+
+- name: Disable lookup_source
+  ios_system:
+    lookup_enabled: True
+    provider: "{{ cli }}"
+    authorize: yes
+  register: result
+
+- assert:
+    that:
+      - result.changed == true
+      - "'ip domain lookup' in result.commands"
+
 #- name: change to vrf
 #  ios_system:
 #    lookup_source: