From 1b8e78afd3a3981284cfadd69b1379322b87724a Mon Sep 17 00:00:00 2001
From: Adam Miller <maxamillion@fedoraproject.org>
Date: Jul 22 2016 19:09:13 +0000
Subject: Rearrange dir structure to follow ansible best practices on content

oranization:
    http://docs.ansible.com/ansible/playbooks_best_practices.html#content-organization

Signed-off-by: Adam Miller <maxamillion@fedoraproject.org>

---

diff --git a/ansible/datagrepperdemo.yml b/ansible/datagrepperdemo.yml
new file mode 100644
index 0000000..34156d3
--- /dev/null
+++ b/ansible/datagrepperdemo.yml
@@ -0,0 +1,12 @@
+---
+- name: Demo datagrepper ansible plugin
+  hosts: automator
+  tasks:
+  - name: datagrepper query
+    datagrepper_query:
+      url: "https://apps.fedoraproject.org/datagrepper/raw"
+      topic: "org.fedoraproject.prod.autocloud.image.success"
+    register: query_data
+
+  - debug: var="query_data['data'][0]"
+
diff --git a/ansible/inventory.txt b/ansible/inventory.txt
deleted file mode 100644
index d445985..0000000
--- a/ansible/inventory.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-[automator]
-localhost              ansible_connection=local
diff --git a/ansible/inventory/inventory.txt b/ansible/inventory/inventory.txt
new file mode 100644
index 0000000..d445985
--- /dev/null
+++ b/ansible/inventory/inventory.txt
@@ -0,0 +1,2 @@
+[automator]
+localhost              ansible_connection=local
diff --git a/ansible/library/datagrepper_query.py b/ansible/library/datagrepper_query.py
new file mode 100755
index 0000000..1ad518a
--- /dev/null
+++ b/ansible/library/datagrepper_query.py
@@ -0,0 +1,111 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# datagrepper_query.py - Ansible library to query datagrepper
+#
+# For more information about datagrepper
+#   https://github.com/fedora-infra/datagrepper
+#
+# Copyright (C) 2016 Red Hat, Inc.
+# SPDX-License-Identifier:      GPL-2.0+
+#
+# Authors:
+#     Adam Miller <maxamillion@fedoraproject.org>
+#
+
+DOCUMENTATION = '''
+---
+author:
+  - "Adam Miller <maxamillion@fedoraproject.org>"
+module: datagrepper_query
+short_description: Query datagrepper
+description:
+  - Query datagrepper
+options:
+  url:
+    description:
+      - The url of the datagrepper instance to query
+    default: null
+    required: true
+  topic:
+    description:
+      - fedmsg topic
+    default: null
+    required: true
+  delta:
+    description:
+      - time delta to search for, in seconds of elapsed time
+    default: 1209600
+    required: false
+  pages:
+    description:
+      - number of pagination pages to request, if 0 then the module will
+        request all available. Default is 1
+    default: 1
+    required: false
+
+FIXME
+'''
+
+EXAMPLES = '''
+# Query for AutoCloud successful test data from the last two weeks
+- datagrepper_query:
+    topic: org.fedoraproject.prod.autocloud.image.success
+    url: https://apps.fedoraproject.org/datagrepper/raw
+    delta: 1209600
+    pages: 1
+
+FIXME
+'''
+
+import requests
+
+def main():
+
+    module = AnsibleModule(
+        argument_spec=dict(
+            url=dict(required=True, default=None),
+            topic=dict(required=True, default=None),
+            delta=dict(required=False, type="int", default=1209600),
+            pages=dict(required=False, type="int", default=1),
+        ),
+        supports_check_mode=False
+    )
+
+    # Maximum rows per page is 100, let's just do that
+    request_params = {
+        "delta": module.params['delta'],
+        "topic": module.params['topic'],
+        "rows_per_page": 100,
+    }
+
+
+    query_request = requests.get(module.params['url'], params=request_params)
+
+    # Start with page 1 response from datagrepper, grab raw messages and then
+    # iterate through pagination pages
+    query_data = query_request.json()[u'raw_messages']
+    if module.params['pages'] == 0:
+        page_range = range(2, query_request.json()[u'pages']+1)
+    else:
+        page_range = range(2, module.params['pages']+1)
+
+    for rpage in page_range:
+        query_data += requests.get(
+            module.params['url'],
+            params=dict(page=rpage, **request_params)
+        ).json()[u'raw_messages']
+
+    # Technically this never changes anything on the system, so always mark
+    # changed=False
+    module.exit_json(
+        changed=False,
+        msg="Successfully queried {}".format(module.params['topic']),
+        data=query_data
+    )
+
+##################################################
+# import module snippets
+from ansible.module_utils.basic import *
+main()
+# vim: set expandtab sw=4 sts=4 ts=4
diff --git a/ansible/playbooks/datagrepperdemo.yml b/ansible/playbooks/datagrepperdemo.yml
deleted file mode 100644
index 34156d3..0000000
--- a/ansible/playbooks/datagrepperdemo.yml
+++ /dev/null
@@ -1,12 +0,0 @@
----
-- name: Demo datagrepper ansible plugin
-  hosts: automator
-  tasks:
-  - name: datagrepper query
-    datagrepper_query:
-      url: "https://apps.fedoraproject.org/datagrepper/raw"
-      topic: "org.fedoraproject.prod.autocloud.image.success"
-    register: query_data
-
-  - debug: var="query_data['data'][0]"
-
diff --git a/ansible/playbooks/library/datagrepper_query.py b/ansible/playbooks/library/datagrepper_query.py
deleted file mode 100755
index 1ad518a..0000000
--- a/ansible/playbooks/library/datagrepper_query.py
+++ /dev/null
@@ -1,111 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-#
-# datagrepper_query.py - Ansible library to query datagrepper
-#
-# For more information about datagrepper
-#   https://github.com/fedora-infra/datagrepper
-#
-# Copyright (C) 2016 Red Hat, Inc.
-# SPDX-License-Identifier:      GPL-2.0+
-#
-# Authors:
-#     Adam Miller <maxamillion@fedoraproject.org>
-#
-
-DOCUMENTATION = '''
----
-author:
-  - "Adam Miller <maxamillion@fedoraproject.org>"
-module: datagrepper_query
-short_description: Query datagrepper
-description:
-  - Query datagrepper
-options:
-  url:
-    description:
-      - The url of the datagrepper instance to query
-    default: null
-    required: true
-  topic:
-    description:
-      - fedmsg topic
-    default: null
-    required: true
-  delta:
-    description:
-      - time delta to search for, in seconds of elapsed time
-    default: 1209600
-    required: false
-  pages:
-    description:
-      - number of pagination pages to request, if 0 then the module will
-        request all available. Default is 1
-    default: 1
-    required: false
-
-FIXME
-'''
-
-EXAMPLES = '''
-# Query for AutoCloud successful test data from the last two weeks
-- datagrepper_query:
-    topic: org.fedoraproject.prod.autocloud.image.success
-    url: https://apps.fedoraproject.org/datagrepper/raw
-    delta: 1209600
-    pages: 1
-
-FIXME
-'''
-
-import requests
-
-def main():
-
-    module = AnsibleModule(
-        argument_spec=dict(
-            url=dict(required=True, default=None),
-            topic=dict(required=True, default=None),
-            delta=dict(required=False, type="int", default=1209600),
-            pages=dict(required=False, type="int", default=1),
-        ),
-        supports_check_mode=False
-    )
-
-    # Maximum rows per page is 100, let's just do that
-    request_params = {
-        "delta": module.params['delta'],
-        "topic": module.params['topic'],
-        "rows_per_page": 100,
-    }
-
-
-    query_request = requests.get(module.params['url'], params=request_params)
-
-    # Start with page 1 response from datagrepper, grab raw messages and then
-    # iterate through pagination pages
-    query_data = query_request.json()[u'raw_messages']
-    if module.params['pages'] == 0:
-        page_range = range(2, query_request.json()[u'pages']+1)
-    else:
-        page_range = range(2, module.params['pages']+1)
-
-    for rpage in page_range:
-        query_data += requests.get(
-            module.params['url'],
-            params=dict(page=rpage, **request_params)
-        ).json()[u'raw_messages']
-
-    # Technically this never changes anything on the system, so always mark
-    # changed=False
-    module.exit_json(
-        changed=False,
-        msg="Successfully queried {}".format(module.params['topic']),
-        data=query_data
-    )
-
-##################################################
-# import module snippets
-from ansible.module_utils.basic import *
-main()
-# vim: set expandtab sw=4 sts=4 ts=4

