aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/modules
diff options
context:
space:
mode:
authorbinary <me@rgoncalves.se>2020-11-12 14:30:12 +0100
committerbinary <me@rgoncalves.se>2020-11-12 14:30:16 +0100
commitbd50f2355502263970419213c1b33bcca8cc48de (patch)
treeef6703dd7fc4b05fb31628aaedcdea93f6c49a04 /plugins/modules
parentb419094cda74405eb4cbb8b7031b53cd2f347566 (diff)
downloadinfrastructure-bd50f2355502263970419213c1b33bcca8cc48de.tar.gz
Start some experiments with modules
Diffstat (limited to 'plugins/modules')
-rw-r--r--plugins/modules/repology.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/plugins/modules/repology.py b/plugins/modules/repology.py
new file mode 100644
index 0000000..c8d9508
--- /dev/null
+++ b/plugins/modules/repology.py
@@ -0,0 +1,51 @@
+#!/bin/python
+
+from __future__ import (absolute_import, division, print_function)
+import requests
+
+__metaclass__ = type
+
+
+from ansible.module_utils.basic import AnsibleModule
+
+
+API_ENDPOINT="https://repology.org/api/v1/project/"
+
+
+def main():
+ # Available arguments
+ module_args = dict(
+ package=dict(type="str", required=True),
+ repository=dict(type="str", required=False)
+ )
+
+ # Result to return
+ result = dict(
+ changed=False,
+ message=""
+ )
+
+ # Object for manipulating argument
+ module = AnsibleModule(
+ argument_spec=module_args,
+ supports_check_mode=True
+ )
+
+ print("aa")
+ if module.check_mode:
+ module.exit_json(**result)
+
+ response = requests.get(f"{API_ENDPOINT}/{module.params['package']}")
+ print(response)
+ for res in response.json():
+ try:
+ #print(res["name"])
+ result.message = (res["name"])
+ except Exception:
+ pass
+
+
+ module.exit_json(**result)
+
+if __name__ == "__main__":
+ main()
remember that computers suck.