|
|
@ -24,7 +24,7 @@ author: Andrew Dunham
|
|
|
|
short_description: Package manager for Homebrew
|
|
|
|
short_description: Package manager for Homebrew
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Manages Homebrew packages
|
|
|
|
- Manages Homebrew packages
|
|
|
|
version_added: "1.1"
|
|
|
|
version_added: "1.4"
|
|
|
|
options:
|
|
|
|
options:
|
|
|
|
name:
|
|
|
|
name:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
@ -42,6 +42,11 @@ options:
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
default: "no"
|
|
|
|
default: "no"
|
|
|
|
choices: [ "yes", "no" ]
|
|
|
|
choices: [ "yes", "no" ]
|
|
|
|
|
|
|
|
install_options:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- options flags to install a package
|
|
|
|
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
notes: []
|
|
|
|
notes: []
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
EXAMPLES = '''
|
|
|
|
EXAMPLES = '''
|
|
|
@ -49,6 +54,7 @@ EXAMPLES = '''
|
|
|
|
- homebrew: name=foo state=present update_homebrew=yes
|
|
|
|
- homebrew: name=foo state=present update_homebrew=yes
|
|
|
|
- homebrew: name=foo state=absent
|
|
|
|
- homebrew: name=foo state=absent
|
|
|
|
- homebrew: name=foo,bar state=absent
|
|
|
|
- homebrew: name=foo,bar state=absent
|
|
|
|
|
|
|
|
- homebrew: name=foo state=present install_options=with-baz,enable-debug
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -98,7 +104,7 @@ def remove_packages(module, brew_path, packages):
|
|
|
|
module.exit_json(changed=False, msg="package(s) already absent")
|
|
|
|
module.exit_json(changed=False, msg="package(s) already absent")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def install_packages(module, brew_path, packages):
|
|
|
|
def install_packages(module, brew_path, packages, options):
|
|
|
|
""" Installs one or more packages if not already installed. """
|
|
|
|
""" Installs one or more packages if not already installed. """
|
|
|
|
|
|
|
|
|
|
|
|
installed_count = 0
|
|
|
|
installed_count = 0
|
|
|
@ -109,6 +115,10 @@ def install_packages(module, brew_path, packages):
|
|
|
|
|
|
|
|
|
|
|
|
if module.check_mode:
|
|
|
|
if module.check_mode:
|
|
|
|
module.exit_json(changed=True)
|
|
|
|
module.exit_json(changed=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if options:
|
|
|
|
|
|
|
|
rc, out, err = module.run_command([brew_path, 'install', package, options])
|
|
|
|
|
|
|
|
else:
|
|
|
|
rc, out, err = module.run_command([brew_path, 'install', package])
|
|
|
|
rc, out, err = module.run_command([brew_path, 'install', package])
|
|
|
|
|
|
|
|
|
|
|
|
if not query_package(module, brew_path, package):
|
|
|
|
if not query_package(module, brew_path, package):
|
|
|
@ -121,13 +131,25 @@ def install_packages(module, brew_path, packages):
|
|
|
|
|
|
|
|
|
|
|
|
module.exit_json(changed=False, msg="package(s) already present")
|
|
|
|
module.exit_json(changed=False, msg="package(s) already present")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def generate_options_string(install_options):
|
|
|
|
|
|
|
|
if install_options is None:
|
|
|
|
|
|
|
|
return ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
options_str = ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for option in install_options:
|
|
|
|
|
|
|
|
options_str += ' --%s' % option
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return options_str.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
module = AnsibleModule(
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec = dict(
|
|
|
|
argument_spec = dict(
|
|
|
|
name = dict(aliases=["pkg"], required=True),
|
|
|
|
name = dict(aliases=["pkg"], required=True),
|
|
|
|
state = dict(default="present", choices=["present", "installed", "absent", "removed"]),
|
|
|
|
state = dict(default="present", choices=["present", "installed", "absent", "removed"]),
|
|
|
|
update_homebrew = dict(default="no", aliases=["update-brew"], type='bool')
|
|
|
|
update_homebrew = dict(default="no", aliases=["update-brew"], type='bool'),
|
|
|
|
|
|
|
|
install_options = dict(default=None, aliases=["options"], type='list')
|
|
|
|
),
|
|
|
|
),
|
|
|
|
supports_check_mode=True
|
|
|
|
supports_check_mode=True
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -142,7 +164,8 @@ def main():
|
|
|
|
pkgs = p["name"].split(",")
|
|
|
|
pkgs = p["name"].split(",")
|
|
|
|
|
|
|
|
|
|
|
|
if p["state"] in ["present", "installed"]:
|
|
|
|
if p["state"] in ["present", "installed"]:
|
|
|
|
install_packages(module, brew_path, pkgs)
|
|
|
|
opt = generate_options_string(p["install_options"])
|
|
|
|
|
|
|
|
install_packages(module, brew_path, pkgs, opt)
|
|
|
|
|
|
|
|
|
|
|
|
elif p["state"] in ["absent", "removed"]:
|
|
|
|
elif p["state"] in ["absent", "removed"]:
|
|
|
|
remove_packages(module, brew_path, pkgs)
|
|
|
|
remove_packages(module, brew_path, pkgs)
|
|
|
|