Last active
December 17, 2019 07:50
-
-
Save simon04/9b0f130eec03d8fcf57769d54bc6df57 to your computer and use it in GitHub Desktop.
Lists outdated win_chocolatey versions of Ansible tasks/roles
This file contains hidden or 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
import xml.etree.ElementTree as ET | |
import glob | |
import urllib.request | |
import yaml | |
from ansible.playbook.helpers import load_list_of_tasks | |
def get_latest_version(id): | |
url = f'https://chocolatey.org/api/v2/Packages()?$filter=(Id%20eq%20%27{id}%27)%20and%20IsLatestVersion' | |
xml = ET.parse(urllib.request.urlopen(url)) | |
return xml.findtext('.//{http://schemas.microsoft.com/ado/2007/08/dataservices}Version') | |
def handle_task(task): | |
args = task.dump_attrs()['args'] | |
if 'name' in args and 'version' in args: | |
latest = get_latest_version(args['name']) | |
if 'pinned' in args and args['pinned'] == 'yes': | |
pass | |
elif args['version'] != latest: | |
print('-', args['name'], args['version'], '=>', latest) | |
for file in glob.glob('roles/*/tasks/*yml'): | |
print(file) | |
with open(file) as fh: | |
for task in load_list_of_tasks(yaml.load(fh, Loader=yaml.BaseLoader), None): | |
handle_task(task) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment