1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

sorcery: update only specified grimoires (#7091)

* sorcery: update only specified grimoires

* Update plugins/modules/sorcery.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Add a flag to omit listing new repositories before add/remove

* No need to append an empty string

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Vlad Glagolev 2023-08-12 00:56:56 -07:00 committed by GitHub
parent fe3eec0122
commit f7176df480
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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'):