Created
October 5, 2023 23:49
-
-
Save wrouesnel/a1109559533b05894ccf30cf4fe4abc3 to your computer and use it in GitHub Desktop.
Ansible lookup plugin which retreives the list of Jetbrains products
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import absolute_import, division, print_function | |
__metaclass__ = type | |
try: | |
from __main__ import display | |
except ImportError: | |
from ansible.utils.display import Display | |
display = Display() | |
import requests | |
from ansible.plugins.lookup import LookupBase | |
DOCUMENTATION = """ | |
lookup: jetbrains_products | |
author: Will Rouesnel <[email protected]> | |
version_added: '8.0' | |
short_description: lookup and return a dictionary of Jetbrains products | |
description: | |
- This lookup queries the Jetbrains website to lookup product information. | |
example: | |
- "{{ lookup('jetbrains_products') }}" | |
""" | |
class LookupModule(LookupBase): | |
def run(self, terms, variables=None, **kwargs): | |
names = terms[0] | |
response = requests.get("https://data.services.jetbrains.com/products") | |
data = response.json() | |
# Format the data into a useful return | |
result = {} | |
result["by_name"] = { item["name"].lower():item for item in data } | |
return [result] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment