Add Arch updates and remove dynamic Linode inventories for now
This commit is contained in:
11
roles/infrastructure/arch_update/meta/main.yml
Normal file
11
roles/infrastructure/arch_update/meta/main.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
galaxy_info:
|
||||
author: Kevin M. Thompson (phlux)
|
||||
description: Update all packages on Arch systems
|
||||
license: MIT
|
||||
min_ansible_version: 2.9
|
||||
platforms:
|
||||
- name: Arch
|
||||
versions:
|
||||
- all
|
||||
dependencies: []
|
8
roles/infrastructure/arch_update/tasks/main.yml
Normal file
8
roles/infrastructure/arch_update/tasks/main.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
- name: Update package database
|
||||
ansible.builtin.command: pacman -Sy --noconfirm
|
||||
become: yes
|
||||
|
||||
- name: Update all packages
|
||||
ansible.builtin.command: pacman -Su --noconfirm
|
||||
become: yes
|
@@ -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()
|
@@ -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 }}"
|
||||
|
Reference in New Issue
Block a user