diff options
-rw-r--r-- | ansible.cfg | 1 | ||||
-rw-r--r-- | plugins/modules/repology.py | 51 | ||||
-rw-r--r-- | plugins/tests/repology.json | 5 | ||||
-rw-r--r-- | plugins/tests/repology.yml | 6 |
4 files changed, 63 insertions, 0 deletions
diff --git a/ansible.cfg b/ansible.cfg index d975cc0..56c18a0 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -5,6 +5,7 @@ interpreter_python = auto_silent jinja2_extensions = jinja2.ext.do,jinja2.ext.i18n roles_path = roles/ +library = /usr/share/ansible:plugins/modules [ssh_connection] pipelining = True 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() diff --git a/plugins/tests/repology.json b/plugins/tests/repology.json new file mode 100644 index 0000000..fabd124 --- /dev/null +++ b/plugins/tests/repology.json @@ -0,0 +1,5 @@ +{ + "ANSIBLE_MODULE_ARGS": { + "package": "firefox" + } +} diff --git a/plugins/tests/repology.yml b/plugins/tests/repology.yml new file mode 100644 index 0000000..fabf019 --- /dev/null +++ b/plugins/tests/repology.yml @@ -0,0 +1,6 @@ +- name: Test repology + hosts: localhost + tasks: + + - repology: + package: "firefox" |