homebrew: Add upgrade_options in upgrade_all (#24)

Handle upgrade options in upgrade_all state in homebrew module.

Fixes: #54541

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2020-03-27 15:41:27 +05:30 committed by GitHub
parent 4fba692c1b
commit c874089d1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 122 additions and 7 deletions

View file

@ -69,6 +69,11 @@ options:
aliases: ['options']
type: list
elements: str
upgrade_options:
description:
- Option flags to upgrade.
type: list
elements: str
notes:
- When used with a `loop:` each package will be processed individually,
it is much more efficient to pass the list directly to the `name` option.
@ -123,6 +128,11 @@ EXAMPLES = '''
name: foo
state: present
install_options: with-baz,enable-debug
- name: Use ignored-pinned option while upgrading all
homebrew:
upgrade_all: yes
upgrade_options: ignored-pinned
'''
import os.path
@ -359,14 +369,17 @@ class Homebrew(object):
def __init__(self, module, path, packages=None, state=None,
update_homebrew=False, upgrade_all=False,
install_options=None):
install_options=None, upgrade_options=None):
if not install_options:
install_options = list()
if not upgrade_options:
upgrade_options = list()
self._setup_status_vars()
self._setup_instance_vars(module=module, path=path, packages=packages,
state=state, update_homebrew=update_homebrew,
upgrade_all=upgrade_all,
install_options=install_options, )
install_options=install_options,
upgrade_options=upgrade_options,)
self._prep()
@ -536,10 +549,9 @@ class Homebrew(object):
self.changed = True
self.message = 'Homebrew packages would be upgraded.'
raise HomebrewException(self.message)
rc, out, err = self.module.run_command([
self.brew_path,
'upgrade',
])
cmd = [self.brew_path, 'upgrade'] + self.upgrade_options
rc, out, err = self.module.run_command(cmd)
if rc == 0:
if not out:
self.message = 'Homebrew packages already upgraded.'
@ -857,6 +869,11 @@ def main():
aliases=['options'],
type='list',
elements='str',
),
upgrade_options=dict(
default=None,
type='list',
elements='str',
)
),
supports_check_mode=True,
@ -895,9 +912,13 @@ def main():
install_options = ['--{0}'.format(install_option)
for install_option in p['install_options']]
p['upgrade_options'] = p['upgrade_options'] or []
upgrade_options = ['--{0}'.format(upgrade_option)
for upgrade_option in p['upgrade_options']]
brew = Homebrew(module=module, path=path, packages=packages,
state=state, update_homebrew=update_homebrew,
upgrade_all=upgrade_all, install_options=install_options)
upgrade_all=upgrade_all, install_options=install_options,
upgrade_options=upgrade_options)
(failed, changed, message) = brew.run()
if failed:
module.fail_json(msg=message)