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

Merge pull request #7476 from geschke/devel

implemented the missing "command" option, defaults to "install"...
This commit is contained in:
Michael DeHaan 2014-08-08 14:47:14 -04:00
commit ec37a44e94

View file

@ -28,6 +28,11 @@ version_added: "1.6"
description: description:
- Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you - Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you
options: options:
command:
description:
- Composer command like "install", "update" and so on
required: false
default: install
working_dir: working_dir:
description: description:
- Directory of your project ( see --working-dir ) - Directory of your project ( see --working-dir )
@ -85,7 +90,7 @@ notes:
EXAMPLES = ''' EXAMPLES = '''
# Downloads and installs all the libs and dependencies outlined in the /path/to/project/composer.lock # Downloads and installs all the libs and dependencies outlined in the /path/to/project/composer.lock
- composer: working_dir=/path/to/project - composer: command=install working_dir=/path/to/project
''' '''
import os import os
@ -97,16 +102,17 @@ def parse_out(string):
def has_changed(string): def has_changed(string):
return (re.match("Nothing to install or update", string) != None) return (re.match("Nothing to install or update", string) != None)
def composer_install(module, options): def composer_install(module, command, options):
php_path = module.get_bin_path("php", True, ["/usr/local/bin"]) php_path = module.get_bin_path("php", True, ["/usr/local/bin"])
composer_path = module.get_bin_path("composer", True, ["/usr/local/bin"]) composer_path = module.get_bin_path("composer", True, ["/usr/local/bin"])
cmd = "%s %s install %s" % (php_path, composer_path, " ".join(options)) cmd = "%s %s %s %s" % (php_path, composer_path, command, " ".join(options))
return module.run_command(cmd) return module.run_command(cmd)
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec = dict( argument_spec = dict(
command = dict(default="install", type="str", required=False),
working_dir = dict(aliases=["working-dir"], required=True), working_dir = dict(aliases=["working-dir"], required=True),
prefer_source = dict(default="no", type="bool", aliases=["prefer-source"]), prefer_source = dict(default="no", type="bool", aliases=["prefer-source"]),
prefer_dist = dict(default="no", type="bool", aliases=["prefer-dist"]), prefer_dist = dict(default="no", type="bool", aliases=["prefer-dist"]),
@ -129,6 +135,10 @@ def main():
if module.check_mode: if module.check_mode:
options.add("--dry-run") options.add("--dry-run")
# Get composer command with fallback to default
command = module.params['command']
del module.params['command'];
# Prepare options # Prepare options
for i in module.params: for i in module.params:
opt = "--%s" % i.replace("_","-") opt = "--%s" % i.replace("_","-")
@ -138,7 +148,7 @@ def main():
elif isinstance(p, (str)): elif isinstance(p, (str)):
options.add("%s=%s" % (opt, p)) options.add("%s=%s" % (opt, p))
rc, out, err = composer_install(module, options) rc, out, err = composer_install(module, command, options)
if rc != 0: if rc != 0:
output = parse_out(err) output = parse_out(err)