From f7176df4801baa4c081e08116b042acc6c5c7b7f Mon Sep 17 00:00:00 2001 From: Vlad Glagolev Date: Sat, 12 Aug 2023 00:56:56 -0700 Subject: [PATCH] sorcery: update only specified grimoires (#7091) * sorcery: update only specified grimoires * Update plugins/modules/sorcery.py Co-authored-by: Felix Fontein * Add a flag to omit listing new repositories before add/remove * No need to append an empty string --------- Co-authored-by: Felix Fontein --- plugins/modules/sorcery.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/modules/sorcery.py b/plugins/modules/sorcery.py index b6ed07cfb9..4fcf46a052 100644 --- a/plugins/modules/sorcery.py +++ b/plugins/modules/sorcery.py @@ -255,9 +255,11 @@ def codex_fresh(codex, module): return True -def codex_list(module): +def codex_list(module, skip_new=False): """ List valid grimoire collection. """ + params = module.params + codex = {} cmd_scribe = "%s index" % SORCERY['scribe'] @@ -276,6 +278,10 @@ def codex_list(module): if match: codex[match.group('grim')] = match.group('ver') + # return only specified grimoires unless requested to skip new + if params['repository'] and not skip_new: + codex = dict((x, codex.get(x, NA)) for x in params['name']) + if not codex: module.fail_json(msg="no grimoires to operate on; add at least one") @@ -337,6 +343,9 @@ def update_codex(module): cmd_scribe = "%s update" % SORCERY['scribe'] + if params['repository']: + cmd_scribe += ' %s' % ' '.join(codex.keys()) + rc, stdout, stderr = module.run_command(cmd_scribe) if rc != 0: @@ -485,7 +494,7 @@ def manage_grimoires(module): grimoires = params['name'] url = params['repository'] - codex = codex_list(module) + codex = codex_list(module, True) if url == '*': if params['state'] in ('present', 'latest', 'absent'):