Enable to use greedy checks for outdated casks (#40799)
* Enable to use greedy checks for outdated casks When using brew cask outdated to check if an installed cask is outdated or not, brew cask will skip casks that have auto_updates set to true or version: latest. This means that Ansible tasks using the homebrew_cask module to upgrade packages installed by brew cask will miss upgrading such packages. However such packages can still be managed by brew cask so we need to be able detect such packages. This can be done with the --greedy flag passed to brew cask outdated as this will also include such packages that are outdated. This commit adds a greedy parameter to the homebrew_cask module to enable upgrading such packages using Ansible tasks with the homebrew_cask module. The default behavior preserves the same behavior as today. Example usage would be: - homebrew_cask: name: 1password state: upgraded update_homebrew: yes greedy: yes * Fix test issues * Add extra comma to match style
This commit is contained in:
parent
16fb74ffb3
commit
f71ad4e315
1 changed files with 34 additions and 8 deletions
|
@ -74,6 +74,14 @@ options:
|
||||||
type: bool
|
type: bool
|
||||||
default: 'no'
|
default: 'no'
|
||||||
version_added: "2.5.0"
|
version_added: "2.5.0"
|
||||||
|
greedy:
|
||||||
|
description:
|
||||||
|
- upgrade casks that auto update; passes --greedy to brew cask
|
||||||
|
outdated when checking if an installed cask has a newer version
|
||||||
|
available
|
||||||
|
type: bool
|
||||||
|
default: 'no'
|
||||||
|
version_added: "2.7.0"
|
||||||
'''
|
'''
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
- homebrew_cask:
|
- homebrew_cask:
|
||||||
|
@ -112,6 +120,11 @@ EXAMPLES = '''
|
||||||
state: upgraded
|
state: upgraded
|
||||||
install_options: force
|
install_options: force
|
||||||
|
|
||||||
|
- homebrew_cask:
|
||||||
|
name: 1password
|
||||||
|
state: upgraded
|
||||||
|
greedy: True
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
|
@ -335,7 +348,8 @@ class HomebrewCask(object):
|
||||||
|
|
||||||
def __init__(self, module, path=path, casks=None, state=None,
|
def __init__(self, module, path=path, casks=None, state=None,
|
||||||
update_homebrew=False, install_options=None,
|
update_homebrew=False, install_options=None,
|
||||||
accept_external_apps=False, upgrade_all=False):
|
accept_external_apps=False, upgrade_all=False,
|
||||||
|
greedy=False):
|
||||||
if not install_options:
|
if not install_options:
|
||||||
install_options = list()
|
install_options = list()
|
||||||
self._setup_status_vars()
|
self._setup_status_vars()
|
||||||
|
@ -343,7 +357,8 @@ class HomebrewCask(object):
|
||||||
state=state, update_homebrew=update_homebrew,
|
state=state, update_homebrew=update_homebrew,
|
||||||
install_options=install_options,
|
install_options=install_options,
|
||||||
accept_external_apps=accept_external_apps,
|
accept_external_apps=accept_external_apps,
|
||||||
upgrade_all=upgrade_all, )
|
upgrade_all=upgrade_all,
|
||||||
|
greedy=greedy, )
|
||||||
|
|
||||||
self._prep()
|
self._prep()
|
||||||
|
|
||||||
|
@ -406,12 +421,17 @@ class HomebrewCask(object):
|
||||||
if not self.valid_cask(self.current_cask):
|
if not self.valid_cask(self.current_cask):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
rc, out, err = self.module.run_command([
|
cask_is_outdated_command = (
|
||||||
self.brew_path,
|
[
|
||||||
'cask',
|
self.brew_path,
|
||||||
'outdated',
|
'cask',
|
||||||
self.current_cask,
|
'outdated',
|
||||||
])
|
]
|
||||||
|
+ (['--greedy'] if self.greedy else [])
|
||||||
|
+ [self.current_cask]
|
||||||
|
)
|
||||||
|
|
||||||
|
rc, out, err = self.module.run_command(cask_is_outdated_command)
|
||||||
|
|
||||||
return out != ""
|
return out != ""
|
||||||
|
|
||||||
|
@ -697,6 +717,10 @@ def main():
|
||||||
aliases=["upgrade"],
|
aliases=["upgrade"],
|
||||||
type='bool',
|
type='bool',
|
||||||
),
|
),
|
||||||
|
greedy=dict(
|
||||||
|
default=False,
|
||||||
|
type='bool',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
)
|
)
|
||||||
|
@ -724,6 +748,7 @@ def main():
|
||||||
|
|
||||||
update_homebrew = p['update_homebrew']
|
update_homebrew = p['update_homebrew']
|
||||||
upgrade_all = p['upgrade_all']
|
upgrade_all = p['upgrade_all']
|
||||||
|
greedy = p['greedy']
|
||||||
p['install_options'] = p['install_options'] or []
|
p['install_options'] = p['install_options'] or []
|
||||||
install_options = ['--{0}'.format(install_option)
|
install_options = ['--{0}'.format(install_option)
|
||||||
for install_option in p['install_options']]
|
for install_option in p['install_options']]
|
||||||
|
@ -735,6 +760,7 @@ def main():
|
||||||
install_options=install_options,
|
install_options=install_options,
|
||||||
accept_external_apps=accept_external_apps,
|
accept_external_apps=accept_external_apps,
|
||||||
upgrade_all=upgrade_all,
|
upgrade_all=upgrade_all,
|
||||||
|
greedy=greedy,
|
||||||
)
|
)
|
||||||
(failed, changed, message) = brew_cask.run()
|
(failed, changed, message) = brew_cask.run()
|
||||||
if failed:
|
if failed:
|
||||||
|
|
Loading…
Reference in a new issue