Repository: ansible/ansible

Issue:
influxdb_query module returns None for create or drop continuous query commands
##### ISSUE TYPE

Bug Report

##### COMPONENT NAME

influxdb_query

##### ANSIBLE VERSION
```
ansible 2.5.0
  config file = /Users/arnbal01/Code/Gerrit/OpenShift-Apps/InfluxDB/test/ansible.cfg
  configured module search path = [u'/Users/arnbal01/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.14 (default, Mar  9 2018, 23:57:12) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
```

##### CONFIGURATION

```
ANSIBLE_PIPELINING(/Users/arnbal01/Code/Gerrit/OpenShift-Apps/InfluxDB/test/ansible.cfg) = True
ANY_ERRORS_FATAL(/Users/arnbal01/Code/Gerrit/OpenShift-Apps/InfluxDB/test/ansible.cfg) = True
DEFAULT_FORKS(/Users/arnbal01/Code/Gerrit/OpenShift-Apps/InfluxDB/test/ansible.cfg) = 50
DEFAULT_VAULT_PASSWORD_FILE(env: ANSIBLE_VAULT_PASSWORD_FILE) = /Users/arnbal01/.vaultpass
DEPRECATION_WARNINGS(/Users/arnbal01/Code/Gerrit/OpenShift-Apps/InfluxDB/test/ansible.cfg) = False
```

##### OS / ENVIRONMENT

Running on Mac OS X configuring Mac OS X and/or Linux

##### SUMMARY

Using the influxdb_query module to create or drop continuous queries results in a `None` value being returned

##### STEPS TO REPRODUCE

Create an influxdb database and try to create a continuous query

```yaml
---
- hosts: localhost
  tasks:
    - name: Create database
      influxdb_database:
        database_name: test
    - name: Create continous query
      influxdb_query:
        database_name: test
        query: "CREATE CONTINUOUS QUERY mean ON \"test\" BEGIN SELECT mean(*) INTO "test"."autogen".:MEASUREMENT FROM /.*/ GROUP BY time(30m),* END"
```

##### EXPECTED RESULTS

Expect empty list as a result
```
"results": []
```

##### ACTUAL RESULTS

`None` is returned as the result (like the documentation says) but the query is created

```
ERROR! Unexpected Exception, this is probably a bug: 'NoneType' object is not iterable
the full traceback was:

Traceback (most recent call last):
  File "/usr/local/bin/ansible-playbook", line 118, in <module>
    exit_code = cli.run()
  File "/usr/local/lib/python2.7/site-packages/ansible/cli/playbook.py", line 122, in run
    results = pbex.run()
  File "/usr/local/lib/python2.7/site-packages/ansible/executor/playbook_executor.py", line 159, in run
    result = self._tqm.run(play=play)
  File "/usr/local/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py", line 290, in run
    play_return = strategy.run(iterator, play_context)
  File "/usr/local/lib/python2.7/site-packages/ansible/plugins/strategy/linear.py", line 291, in run
    results += self._wait_on_pending_results(iterator)
  File "/usr/local/lib/python2.7/site-packages/ansible/plugins/strategy/__init__.py", line 680, in _wait_on_pending_results
    results = self._process_pending_results(iterator)
  File "/usr/local/lib/python2.7/site-packages/ansible/plugins/strategy/__init__.py", line 117, in inner
    results = func(self, iterator, one_pass=one_pass, max_passes=max_passes)
  File "/usr/local/lib/python2.7/site-packages/ansible/plugins/strategy/__init__.py", line 453, in _process_pending_results
    if task_result.is_failed() or task_result.is_unreachable():
  File "/usr/local/lib/python2.7/site-packages/ansible/executor/task_result.py", line 59, in is_failed
    'results' in self._result and True in [True for x in self._result['results'] if 'failed_when_result' in x]:
TypeError: 'NoneType' object is not iterable
```


Discussion:
Files identified in the description:
* [lib/ansible/modules/database/influxdb/influxdb_query.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/database/influxdb/influxdb_query.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @kamsz @resmo
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
I locally fixed this with a small change on https://github.com/ansible/ansible/blob/a067575cab10da106f7ee2b5bb30914aa7c18854/lib/ansible/modules/database/influxdb/influxdb_query.py#L99

```
+ module.exit_json(changed=True, results=results or [])
- module.exit_json(changed=True, results=results)
```
@erasche thanks for the update, but the real issue is that the module uses the reserved global return `results` http://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#results

Resolving patch:
diff --git a/lib/ansible/modules/database/influxdb/influxdb_query.py b/lib/ansible/modules/database/influxdb/influxdb_query.py
--- a/lib/ansible/modules/database/influxdb/influxdb_query.py
+++ b/lib/ansible/modules/database/influxdb/influxdb_query.py
@@ -52,11 +52,11 @@
 
 - name: Print results from the query
   debug:
-    var: connection.results
+    var: connection.query_results
 '''
 
 RETURN = '''
-results:
+query_results:
   description: Result from the query
   returned: success
   type: list
@@ -96,7 +96,7 @@ def main():
     influx = AnsibleInfluxDBRead(module)
     query = module.params.get('query')
     results = influx.read_by_query(query)
-    module.exit_json(changed=True, results=results)
+    module.exit_json(changed=True, query_results=results)
 
 
 if __name__ == '__main__':


Test patch: