Add upgrade_all
option to homebrew module.
This commit is contained in:
parent
ac6792356c
commit
3b38077246
1 changed files with 42 additions and 4 deletions
|
@ -44,6 +44,12 @@ options:
|
|||
required: false
|
||||
default: "no"
|
||||
choices: [ "yes", "no" ]
|
||||
upgrade_all:
|
||||
description:
|
||||
- upgrade all homebrew packages
|
||||
required: false
|
||||
default: no
|
||||
choices: [ "yes", "no" ]
|
||||
install_options:
|
||||
description:
|
||||
- options flags to install a package
|
||||
|
@ -56,7 +62,7 @@ EXAMPLES = '''
|
|||
- homebrew: name=foo state=present
|
||||
- homebrew: name=foo state=present update_homebrew=yes
|
||||
- homebrew: name=foo state=latest update_homebrew=yes
|
||||
- homebrew: update_homebrew=yes upgrade=yes
|
||||
- homebrew: update_homebrew=yes upgrade_all=yes
|
||||
- homebrew: name=foo state=head
|
||||
- homebrew: name=foo state=linked
|
||||
- homebrew: name=foo state=absent
|
||||
|
@ -289,12 +295,14 @@ class Homebrew(object):
|
|||
# /class properties -------------------------------------------- }}}
|
||||
|
||||
def __init__(self, module, path=None, packages=None, state=None,
|
||||
update_homebrew=False, install_options=None):
|
||||
update_homebrew=False, upgrade_all=False,
|
||||
install_options=None):
|
||||
if not install_options:
|
||||
install_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, )
|
||||
|
||||
self._prep()
|
||||
|
@ -418,6 +426,9 @@ class Homebrew(object):
|
|||
if self.update_homebrew:
|
||||
self._update_homebrew()
|
||||
|
||||
if self.upgrade_all:
|
||||
self._upgrade_all()
|
||||
|
||||
if self.packages:
|
||||
if self.state == 'installed':
|
||||
return self._install_packages()
|
||||
|
@ -458,6 +469,27 @@ class Homebrew(object):
|
|||
raise HomebrewException(self.message)
|
||||
# /updated ------------------------------- }}}
|
||||
|
||||
# _upgrade_all --------------------------- {{{
|
||||
def _upgrade_all(self):
|
||||
rc, out, err = self.module.run_command([
|
||||
self.brew_path,
|
||||
'upgrade',
|
||||
])
|
||||
if rc == 0:
|
||||
if not out:
|
||||
self.message = 'Homebrew packages already upgraded.'
|
||||
|
||||
else:
|
||||
self.changed = True
|
||||
self.message = 'Homebrew upgraded.'
|
||||
|
||||
return True
|
||||
else:
|
||||
self.failed = True
|
||||
self.message = err.strip()
|
||||
raise HomebrewException(self.message)
|
||||
# /_upgrade_all -------------------------- }}}
|
||||
|
||||
# installed ------------------------------ {{{
|
||||
def _install_current_package(self):
|
||||
if not self.valid_package(self.current_package):
|
||||
|
@ -741,6 +773,11 @@ def main():
|
|||
aliases=["update-brew"],
|
||||
type='bool',
|
||||
),
|
||||
upgrade_all=dict(
|
||||
default="no",
|
||||
aliases=["upgrade"],
|
||||
type='bool',
|
||||
),
|
||||
install_options=dict(
|
||||
default=None,
|
||||
aliases=['options'],
|
||||
|
@ -765,7 +802,7 @@ def main():
|
|||
state = p['state']
|
||||
if state in ('present', 'installed'):
|
||||
state = 'installed'
|
||||
if state in ('head'):
|
||||
if state in ('head', ):
|
||||
state = 'head'
|
||||
if state in ('latest', 'upgraded'):
|
||||
state = 'upgraded'
|
||||
|
@ -777,13 +814,14 @@ def main():
|
|||
state = 'absent'
|
||||
|
||||
update_homebrew = p['update_homebrew']
|
||||
upgrade_all = p['upgrade_all']
|
||||
p['install_options'] = p['install_options'] or []
|
||||
install_options = ['--{0}'.format(install_option)
|
||||
for install_option in p['install_options']]
|
||||
|
||||
brew = Homebrew(module=module, path=path, packages=packages,
|
||||
state=state, update_homebrew=update_homebrew,
|
||||
install_options=install_options)
|
||||
upgrade_all=upgrade_all, install_options=install_options)
|
||||
(failed, changed, message) = brew.run()
|
||||
if failed:
|
||||
module.fail_json(msg=message)
|
||||
|
|
Loading…
Reference in a new issue