Call custom script. I'm tired of fucking with Linode's collection..
This commit is contained in:
39
roles/inventory/linode/library/linode_inventory.py
Normal file
39
roles/inventory/linode/library/linode_inventory.py
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
import os
|
||||
import requests
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(argument_spec={})
|
||||
|
||||
token = os.getenv("LINODE_TOKEN")
|
||||
if not token:
|
||||
module.fail_json(msg="LINODE_TOKEN is not set")
|
||||
|
||||
response = requests.get("https://api.linode.com/v4/linode/instances", headers={
|
||||
"Authorization": f"Bearer {token}",
|
||||
"Content-Type": "application/json"
|
||||
})
|
||||
|
||||
if response.status_code != 200:
|
||||
module.fail_json(msg=f"Linode API error: {response.status_code}", details=response.text)
|
||||
|
||||
linodes = response.json().get("data", [])
|
||||
results = {
|
||||
"changed": False,
|
||||
"linodes": [
|
||||
{
|
||||
"name": l["label"],
|
||||
"ip": l["ipv4"][0] if l["ipv4"] else None,
|
||||
"region": l["region"],
|
||||
"tags": l["tags"],
|
||||
"type": l["type"]
|
||||
} for l in linodes
|
||||
]
|
||||
}
|
||||
|
||||
module.exit_json(**results)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user