mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
allow specify arguments for composer
This commit is contained in:
parent
8c8c63110e
commit
ae59ea7deb
1 changed files with 23 additions and 3 deletions
|
@ -36,6 +36,11 @@ options:
|
|||
- Composer command like "install", "update" and so on
|
||||
required: false
|
||||
default: install
|
||||
arguments:
|
||||
description:
|
||||
- Composer arguments like required package, version and so on
|
||||
required: false
|
||||
default: null
|
||||
working_dir:
|
||||
description:
|
||||
- Directory of your project ( see --working-dir )
|
||||
|
@ -102,6 +107,17 @@ notes:
|
|||
EXAMPLES = '''
|
||||
# Downloads and installs all the libs and dependencies outlined in the /path/to/project/composer.lock
|
||||
- composer: command=install working_dir=/path/to/project
|
||||
|
||||
- composer:
|
||||
command: "require my/package"
|
||||
working_dir: "/path/to/project"
|
||||
|
||||
# Clone project and install with all dependencies
|
||||
- composer:
|
||||
command: "create-project"
|
||||
arguments: "package/package /path/to/project ~1.0"
|
||||
working_dir: "/path/to/project"
|
||||
prefer_dist: "yes"
|
||||
'''
|
||||
|
||||
import os
|
||||
|
@ -116,6 +132,8 @@ def parse_out(string):
|
|||
return re.sub("\s+", " ", string).strip()
|
||||
|
||||
def has_changed(string):
|
||||
if string == "":
|
||||
return False
|
||||
return "Nothing to install or update" not in string
|
||||
|
||||
def get_available_options(module, command='install'):
|
||||
|
@ -128,16 +146,17 @@ def get_available_options(module, command='install'):
|
|||
command_help_json = json.loads(out)
|
||||
return command_help_json['definition']['options']
|
||||
|
||||
def composer_command(module, command, options=[]):
|
||||
def composer_command(module, command, arguments = "", options=[]):
|
||||
php_path = module.get_bin_path("php", True, ["/usr/local/bin"])
|
||||
composer_path = module.get_bin_path("composer", True, ["/usr/local/bin"])
|
||||
cmd = "%s %s %s %s" % (php_path, composer_path, command, " ".join(options))
|
||||
cmd = "%s %s %s %s %s" % (php_path, composer_path, command, " ".join(options), arguments)
|
||||
return module.run_command(cmd)
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
command = dict(default="install", type="str", required=False),
|
||||
arguments = dict(default="", type="str", required=False),
|
||||
working_dir = dict(aliases=["working-dir"], required=True),
|
||||
prefer_source = dict(default="no", type="bool", aliases=["prefer-source"]),
|
||||
prefer_dist = dict(default="no", type="bool", aliases=["prefer-dist"]),
|
||||
|
@ -152,6 +171,7 @@ def main():
|
|||
|
||||
# Get composer command with fallback to default
|
||||
command = module.params['command']
|
||||
arguments = module.params['arguments']
|
||||
available_options = get_available_options(module=module, command=command)
|
||||
|
||||
options = []
|
||||
|
@ -188,7 +208,7 @@ def main():
|
|||
if module.check_mode:
|
||||
options.append('--dry-run')
|
||||
|
||||
rc, out, err = composer_command(module, command, options)
|
||||
rc, out, err = composer_command(module, command, arguments, options)
|
||||
|
||||
if rc != 0:
|
||||
output = parse_out(err)
|
||||
|
|
Loading…
Reference in a new issue