Repository: ansible/ansible

Issue:
route53 get is broken after 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 -->
route53 module

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
The bug exists on devel/2.4
```
ansible 2.4.0 (devel 09b2964dee) last updated 2017/05/10 16:22:55 (GMT -500)
  config file = /Users/mconlon/git/hyperwave_relay_devel/ansible.cfg
  configured module search path = [u'custom_modules']
  ansible python module location = /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/src/ansible/lib/ansible
  executable location = /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/bin/ansible
  python version = 2.7.12 (default, Oct 11 2016, 05:20:59) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)]
```

I tested this on 2.3 and it works just fine there:
```
ansible 2.3.0.0 (devel d56ba0945d) last updated 2017/05/10 16:28:41 (GMT -500)
  config file = /Users/mconlon/git/hyperwave_relay_inf_as_code/ansible.cfg
  configured module search path = [u'custom_modules']
  python version = 2.7.12 (default, Oct 11 2016, 05:20:59) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)]
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
ansible.cfg:
```
[defaults]
roles_path = roles
lookup_plugins = lookup_plugins
filter_plugins = filter_plugins
hash_behaviour = merge
library = custom_modules
forks = 50

[ssh_connection]
scp_if_ssh = True
pipelining = True
# an attempt to fix ssh unreachable errors when machines are actually reachable
retries = 5
```

##### 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.
-->
Mac OS 10.12.4

##### SUMMARY
<!--- Explain the problem briefly -->
get fails with the error below (`TypeError: 'NoneType' object is not iterable`), regardless of using `command: get` or `state: get`

##### 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 -->
Following the example from the docs:
```yaml
- name: check if DNS entry exists in my zone
      route53:
        state: get
        zone: <my_zone>
        record: <my_dns>
        type: A
      register: record_facts
```
or with the legacy `command`:
```yaml
- name: check if DNS entry exists in my zone
      route53:
        command: get
        zone: <my_zone>
        record: <my_dns>
        type: A
      register: record_facts
```
<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
I should get a record set

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
task path: /Users/mconlon/git/hyperwave_relay_devel/playbooks/test.yml:4
Using module_utils file /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/src/ansible/lib/ansible/module_utils/basic.py
Using module_utils file /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/src/ansible/lib/ansible/module_utils/ec2.py
Using module_utils file /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/src/ansible/lib/ansible/module_utils/_text.py
Using module_utils file /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/src/ansible/lib/ansible/module_utils/pycompat24.py
Using module_utils file /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/src/ansible/lib/ansible/module_utils/six/__init__.py
Using module_utils file /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/src/ansible/lib/ansible/module_utils/six/_six.py
Using module_utils file /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/src/ansible/lib/ansible/module_utils/cloud.py
Using module file /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/src/ansible/lib/ansible/modules/cloud/amazon/route53.py
<localhost> ESTABLISH SSH CONNECTION FOR USER: ubuntu
<localhost> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o Port=4242 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 -o 'ProxyCommand=ssh -W %h:%p bastion-01.edge.aworks.us' -o ControlPath=/Users/mconlon/.ansible/cp/b927653f42 localhost '/bin/sh -c '"'"'/usr/bin/python && sleep 0'"'"''
<localhost> (1, '', 'OpenSSH_7.4p1, LibreSSL 2.5.0\r\ndebug1: Reading configuration data /Users/mconlon/.ssh/config\r\ndebug1: /Users/mconlon/.ssh/config line 1: Applying options for *\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 50989\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\nTraceback (most recent call last):\n  File "/tmp/ansible_OmM54P/ansible_module_route53.py", line 605, in <module>\n    main()\n  File "/tmp/ansible_OmM54P/ansible_module_route53.py", line 516, in main\n    for v in value_in:\nTypeError: \'NoneType\' object is not iterable\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\n')
fatal: [localhost]: FAILED! => {
    "changed": false,
    "failed": true,
    "module_stderr": "OpenSSH_7.4p1, LibreSSL 2.5.0\r\ndebug1: Reading configuration data /Users/mconlon/.ssh/config\r\ndebug1: /Users/mconlon/.ssh/config line 1: Applying options for *\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 50989\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\nTraceback (most recent call last):\n  File \"/tmp/ansible_OmM54P/ansible_module_route53.py\", line 605, in <module>\n    main()\n  File \"/tmp/ansible_OmM54P/ansible_module_route53.py\", line 516, in main\n    for v in value_in:\nTypeError: 'NoneType' object is not iterable\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE",
    "rc": 1
}
	to retry, use: --limit @/Users/mconlon/git/hyperwave_relay_devel/playbooks/test.retry

PLAY RECAP ******************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1
```

route53 get is broken after 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 -->
route53 module

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
The bug exists on devel/2.4
```
ansible 2.4.0 (devel 09b2964dee) last updated 2017/05/10 16:22:55 (GMT -500)
  config file = /Users/mconlon/git/hyperwave_relay_devel/ansible.cfg
  configured module search path = [u'custom_modules']
  ansible python module location = /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/src/ansible/lib/ansible
  executable location = /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/bin/ansible
  python version = 2.7.12 (default, Oct 11 2016, 05:20:59) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)]
```

I tested this on 2.3 and it works just fine there:
```
ansible 2.3.0.0 (devel d56ba0945d) last updated 2017/05/10 16:28:41 (GMT -500)
  config file = /Users/mconlon/git/hyperwave_relay_inf_as_code/ansible.cfg
  configured module search path = [u'custom_modules']
  python version = 2.7.12 (default, Oct 11 2016, 05:20:59) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)]
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
ansible.cfg:
```
[defaults]
roles_path = roles
lookup_plugins = lookup_plugins
filter_plugins = filter_plugins
hash_behaviour = merge
library = custom_modules
forks = 50

[ssh_connection]
scp_if_ssh = True
pipelining = True
# an attempt to fix ssh unreachable errors when machines are actually reachable
retries = 5
```

##### 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.
-->
Mac OS 10.12.4

##### SUMMARY
<!--- Explain the problem briefly -->
get fails with the error below (`TypeError: 'NoneType' object is not iterable`), regardless of using `command: get` or `state: get`

##### 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 -->
Following the example from the docs:
```yaml
- name: check if DNS entry exists in my zone
      route53:
        state: get
        zone: <my_zone>
        record: <my_dns>
        type: A
      register: record_facts
```
or with the legacy `command`:
```yaml
- name: check if DNS entry exists in my zone
      route53:
        command: get
        zone: <my_zone>
        record: <my_dns>
        type: A
      register: record_facts
```
<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
I should get a record set

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
task path: /Users/mconlon/git/hyperwave_relay_devel/playbooks/test.yml:4
Using module_utils file /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/src/ansible/lib/ansible/module_utils/basic.py
Using module_utils file /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/src/ansible/lib/ansible/module_utils/ec2.py
Using module_utils file /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/src/ansible/lib/ansible/module_utils/_text.py
Using module_utils file /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/src/ansible/lib/ansible/module_utils/pycompat24.py
Using module_utils file /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/src/ansible/lib/ansible/module_utils/six/__init__.py
Using module_utils file /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/src/ansible/lib/ansible/module_utils/six/_six.py
Using module_utils file /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/src/ansible/lib/ansible/module_utils/cloud.py
Using module file /Users/mconlon/git/hyperwave_relay_devel/ansible_devel/src/ansible/lib/ansible/modules/cloud/amazon/route53.py
<localhost> ESTABLISH SSH CONNECTION FOR USER: ubuntu
<localhost> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o Port=4242 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 -o 'ProxyCommand=ssh -W %h:%p bastion-01.edge.aworks.us' -o ControlPath=/Users/mconlon/.ansible/cp/b927653f42 localhost '/bin/sh -c '"'"'/usr/bin/python && sleep 0'"'"''
<localhost> (1, '', 'OpenSSH_7.4p1, LibreSSL 2.5.0\r\ndebug1: Reading configuration data /Users/mconlon/.ssh/config\r\ndebug1: /Users/mconlon/.ssh/config line 1: Applying options for *\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 50989\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\nTraceback (most recent call last):\n  File "/tmp/ansible_OmM54P/ansible_module_route53.py", line 605, in <module>\n    main()\n  File "/tmp/ansible_OmM54P/ansible_module_route53.py", line 516, in main\n    for v in value_in:\nTypeError: \'NoneType\' object is not iterable\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\n')
fatal: [localhost]: FAILED! => {
    "changed": false,
    "failed": true,
    "module_stderr": "OpenSSH_7.4p1, LibreSSL 2.5.0\r\ndebug1: Reading configuration data /Users/mconlon/.ssh/config\r\ndebug1: /Users/mconlon/.ssh/config line 1: Applying options for *\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 50989\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\nTraceback (most recent call last):\n  File \"/tmp/ansible_OmM54P/ansible_module_route53.py\", line 605, in <module>\n    main()\n  File \"/tmp/ansible_OmM54P/ansible_module_route53.py\", line 516, in main\n    for v in value_in:\nTypeError: 'NoneType' object is not iterable\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE",
    "rc": 1
}
	to retry, use: --limit @/Users/mconlon/git/hyperwave_relay_devel/playbooks/test.retry

PLAY RECAP ******************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1
```



Discussion:
cc @bpennypacker
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
cc @bpennypacker
[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/cloud/amazon/route53.py b/lib/ansible/modules/cloud/amazon/route53.py
--- a/lib/ansible/modules/cloud/amazon/route53.py
+++ b/lib/ansible/modules/cloud/amazon/route53.py
@@ -411,7 +411,7 @@ def main():
         alias=dict(required=False, type='bool'),
         alias_hosted_zone_id=dict(required=False),
         alias_evaluate_target_health=dict(required=False, type='bool', default=False),
-        value=dict(required=False, type='list'),
+        value=dict(required=False, type='list', default=[]),
         overwrite=dict(required=False, type='bool'),
         retry_interval=dict(required=False, default=500),
         private_zone=dict(required=False, type='bool', default=False),
@@ -565,7 +565,7 @@ def main():
 
     if command_in == 'get':
         if type_in == 'NS':
-            ns = record['values']
+            ns = record.get('values', [])
         else:
             # Retrieve name servers associated to the zone.
             z = invoke_with_throttling_retries(conn.get_zone, zone_in)


Test patch: