Skip to content

Instantly share code, notes, and snippets.

@hexylena
Created December 9, 2021 12:24
Show Gist options
  • Save hexylena/c60fe949dd76ce8e3116d2c745bfeb63 to your computer and use it in GitHub Desktop.
Save hexylena/c60fe949dd76ce8e3116d2c745bfeb63 to your computer and use it in GitHub Desktop.
Ansible Utils
#!/usr/bin/env python
# Author: Helena Rasche
# License: AGPL-3.0
import json
import requests
import yaml
import subprocess
with open('requirements.yml', 'r') as handle:
desired = yaml.safe_load(handle)
for role in desired:
if '://' in role['src']:
continue
if '.' not in role['version']:
continue
role_info = subprocess.check_output(['ansible-galaxy', 'role', 'info', role['src']]).decode('utf-8')
role_id = [x[x.index(':') + 2:].strip() for x in role_info.split('\n') if '\tid:' in x][0]
data = requests.get('https://galaxy.ansible.com/api/v1/roles/' + role_id + '/?format=json').json()
try:
oldv = role['version']
newv = data['summary_fields']['versions'][0]['name']
if oldv != newv:
print(f"{role['src']:<25s} {oldv} → {newv}")
except:
print(f"Error processing {role['src']}")
@hexylena
Copy link
Author

hexylena commented May 1, 2023

@cat-bro oh no 💀 if someone else is using this, then I guess I'll make this and the remove-non-mathinc deps into a proper utility at some point, pip insallable and all, since it also needs collection support. Let me know if you have any issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment