Add Arch updates and remove dynamic Linode inventories for now

This commit is contained in:
Kevin Thompson
2025-04-27 16:33:21 -05:00
parent 444205cdbb
commit 1f4f3aa1b9
5 changed files with 19 additions and 70 deletions

View File

@@ -1,47 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import requests
import json
def main():
linode_token = os.getenv("LINODE_API_TOKEN") or os.getenv("ANSIBLE_PASSWORD")
if not linode_token:
print("Error: LINODE_API_TOKEN or ANSIBLE_PASSWORD environment variable not set.", file=sys.stderr)
sys.exit(1)
headers = {"Authorization": f"Bearer {linode_token}"}
response = requests.get("https://api.linode.com/v4/linode/instances", headers=headers)
if response.status_code != 200:
print(f"Error fetching Linode instances: {response.status_code}", file=sys.stderr)
sys.exit(1)
linodes = response.json()["data"]
inventory = {
"all": {
"hosts": [],
"vars": {}
},
"_meta": {
"hostvars": {}
}
}
for linode in linodes:
hostname = linode["label"]
ipv4 = linode["ipv4"]
if hostname and ipv4:
public_ip = ipv4[0]
inventory["all"]["hosts"].append(hostname)
inventory["_meta"]["hostvars"][hostname] = {
"ansible_host": public_ip
}
print(json.dumps(inventory, indent=2))
if __name__ == "__main__":
main()

View File

@@ -1,21 +0,0 @@
---
- name: Run Linode dynamic inventory script
ansible.builtin.script: "{{ playbook_dir }}/roles/inventory/linode_inventory/files/linode_inventory.py"
register: linode_inventory_raw
changed_when: false
- name: Show raw script output
ansible.builtin.debug:
var: linode_inventory_raw.stdout
- name: Parse JSON inventory output
ansible.builtin.set_fact:
linode_inventory: "{{ linode_inventory_raw.stdout | from_json }}"
- name: Add Linode hosts dynamically
ansible.builtin.add_host:
name: "{{ item.key }}"
ansible_host: "{{ item.value.ansible_host }}"
groups: all
loop: "{{ linode_inventory['_meta']['hostvars'] | dict2items }}"