composer: fix escape working_dir (#22363)
* composer: fix escaping of path working_dir * composer: fix pep8
This commit is contained in:
parent
c71b15a696
commit
e0d38fb137
2 changed files with 60 additions and 62 deletions
|
@ -32,82 +32,87 @@ author:
|
||||||
short_description: Dependency Manager for PHP
|
short_description: Dependency Manager for PHP
|
||||||
version_added: "1.6"
|
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:
|
command:
|
||||||
version_added: "1.8"
|
version_added: "1.8"
|
||||||
description:
|
description:
|
||||||
- Composer command like "install", "update" and so on
|
- Composer command like "install", "update" and so on.
|
||||||
required: false
|
required: false
|
||||||
default: install
|
default: install
|
||||||
arguments:
|
arguments:
|
||||||
version_added: "2.0"
|
version_added: "2.0"
|
||||||
description:
|
description:
|
||||||
- Composer arguments like required package, version and so on
|
- Composer arguments like required package, version and so on.
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
working_dir:
|
working_dir:
|
||||||
description:
|
description:
|
||||||
- Directory of your project ( see --working-dir )
|
- Directory of your project (see --working-dir).
|
||||||
required: true
|
required: true
|
||||||
default: null
|
default: null
|
||||||
aliases: [ "working-dir" ]
|
aliases: [ "working-dir" ]
|
||||||
prefer_source:
|
prefer_source:
|
||||||
description:
|
description:
|
||||||
- Forces installation from package sources when possible ( see --prefer-source )
|
- Forces installation from package sources when possible (see --prefer-source).
|
||||||
required: false
|
required: false
|
||||||
default: "no"
|
default: false
|
||||||
choices: [ "yes", "no" ]
|
choices: [ true, false]
|
||||||
aliases: [ "prefer-source" ]
|
aliases: [ "prefer-source" ]
|
||||||
prefer_dist:
|
prefer_dist:
|
||||||
description:
|
description:
|
||||||
- Forces installation from package dist even for dev versions ( see --prefer-dist )
|
- Forces installation from package dist even for dev versions (see --prefer-dist).
|
||||||
required: false
|
required: false
|
||||||
default: "no"
|
default: false
|
||||||
choices: [ "yes", "no" ]
|
choices: [ true, false]
|
||||||
aliases: [ "prefer-dist" ]
|
aliases: [ "prefer-dist" ]
|
||||||
no_dev:
|
no_dev:
|
||||||
description:
|
description:
|
||||||
- Disables installation of require-dev packages ( see --no-dev )
|
- Disables installation of require-dev packages (see --no-dev).
|
||||||
required: false
|
required: false
|
||||||
default: "yes"
|
default: true
|
||||||
choices: [ "yes", "no" ]
|
choices: [ true, false]
|
||||||
aliases: [ "no-dev" ]
|
aliases: [ "no-dev" ]
|
||||||
no_scripts:
|
no_scripts:
|
||||||
description:
|
description:
|
||||||
- Skips the execution of all scripts defined in composer.json ( see --no-scripts )
|
- Skips the execution of all scripts defined in composer.json (see --no-scripts).
|
||||||
required: false
|
required: false
|
||||||
default: "no"
|
default: false
|
||||||
choices: [ "yes", "no" ]
|
choices: [ true, false]
|
||||||
aliases: [ "no-scripts" ]
|
aliases: [ "no-scripts" ]
|
||||||
no_plugins:
|
no_plugins:
|
||||||
description:
|
description:
|
||||||
- Disables all plugins ( see --no-plugins )
|
- Disables all plugins ( see --no-plugins ).
|
||||||
required: false
|
required: false
|
||||||
default: "no"
|
default: false
|
||||||
choices: [ "yes", "no" ]
|
choices: [ true, false]
|
||||||
aliases: [ "no-plugins" ]
|
aliases: [ "no-plugins" ]
|
||||||
optimize_autoloader:
|
optimize_autoloader:
|
||||||
description:
|
description:
|
||||||
- Optimize autoloader during autoloader dump ( see --optimize-autoloader ). Convert PSR-0/4 autoloading to classmap to get a faster autoloader. This is recommended especially for production, but can take a bit of time to run so it is currently not done by default.
|
- Optimize autoloader during autoloader dump (see --optimize-autoloader).
|
||||||
|
- Convert PSR-0/4 autoloading to classmap to get a faster autoloader.
|
||||||
|
- Recommended especially for production, but can take a bit of time to run so it is currently not done by default.
|
||||||
required: false
|
required: false
|
||||||
default: "yes"
|
default: true
|
||||||
choices: [ "yes", "no" ]
|
choices: [ true, false]
|
||||||
aliases: [ "optimize-autoloader" ]
|
aliases: [ "optimize-autoloader" ]
|
||||||
ignore_platform_reqs:
|
ignore_platform_reqs:
|
||||||
version_added: "2.0"
|
version_added: "2.0"
|
||||||
description:
|
description:
|
||||||
- Ignore php, hhvm, lib-* and ext-* requirements and force the installation even if the local machine does not fulfill these.
|
- Ignore php, hhvm, lib-* and ext-* requirements and force the installation even if the local machine does not fulfill these.
|
||||||
required: false
|
required: false
|
||||||
default: "no"
|
default: false
|
||||||
choices: [ "yes", "no" ]
|
choices: [ true, false]
|
||||||
aliases: [ "ignore-platform-reqs" ]
|
aliases: [ "ignore-platform-reqs" ]
|
||||||
requirements:
|
requirements:
|
||||||
- php
|
- php
|
||||||
- composer installed in bin path (recommended /usr/local/bin)
|
- composer installed in bin path (recommended /usr/local/bin)
|
||||||
notes:
|
notes:
|
||||||
- Default options that are always appended in each execution are --no-ansi, --no-interaction and --no-progress if available.
|
- Default options that are always appended in each execution are --no-ansi, --no-interaction and --no-progress if available.
|
||||||
- We received reports about issues on macOS if composer was installed by Homebrew. Please use the official install method to avoid it.
|
- We received reports about issues on macOS if composer was installed by Homebrew. Please use the official install method to avoid issues.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
|
@ -129,25 +134,18 @@ EXAMPLES = '''
|
||||||
prefer_dist: yes
|
prefer_dist: yes
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
try:
|
|
||||||
import json
|
|
||||||
except ImportError:
|
|
||||||
try:
|
|
||||||
import simplejson as json
|
|
||||||
except ImportError:
|
|
||||||
# Let snippet from module_utils/basic.py return a proper error in this case
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def parse_out(string):
|
def parse_out(string):
|
||||||
return re.sub("\s+", " ", string).strip()
|
return re.sub("\s+", " ", string).strip()
|
||||||
|
|
||||||
|
|
||||||
def has_changed(string):
|
def has_changed(string):
|
||||||
return "Nothing to install or update" not in string
|
return "Nothing to install or update" not in string
|
||||||
|
|
||||||
|
|
||||||
def get_available_options(module, command='install'):
|
def get_available_options(module, command='install'):
|
||||||
# get all available options from a composer command using composer help to json
|
# get all available options from a composer command using composer help to json
|
||||||
rc, out, err = composer_command(module, "help %s --format=json" % command)
|
rc, out, err = composer_command(module, "help %s --format=json" % command)
|
||||||
|
@ -155,28 +153,30 @@ def get_available_options(module, command='install'):
|
||||||
output = parse_out(err)
|
output = parse_out(err)
|
||||||
module.fail_json(msg=output)
|
module.fail_json(msg=output)
|
||||||
|
|
||||||
command_help_json = json.loads(out)
|
command_help_json = module.from_json(out)
|
||||||
return command_help_json['definition']['options']
|
return command_help_json['definition']['options']
|
||||||
|
|
||||||
def composer_command(module, command, arguments = "", options=[]):
|
|
||||||
php_path = module.get_bin_path("php", True, ["/usr/local/bin"])
|
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"])
|
composer_path = module.get_bin_path("composer", True, ["/usr/local/bin"])
|
||||||
cmd = "%s %s %s %s %s" % (php_path, composer_path, command, " ".join(options), arguments)
|
cmd = "%s %s %s %s %s" % (php_path, composer_path, command, " ".join(options), arguments)
|
||||||
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),
|
command=dict(default="install", type="str", required=False),
|
||||||
arguments = dict(default="", type="str", required=False),
|
arguments=dict(default="", type="str", required=False),
|
||||||
working_dir = dict(aliases=["working-dir"], required=True),
|
working_dir=dict(type="path", aliases=["working-dir"], required=True),
|
||||||
prefer_source = dict(default="no", type="bool", aliases=["prefer-source"]),
|
prefer_source=dict(default=False, type="bool", aliases=["prefer-source"]),
|
||||||
prefer_dist = dict(default="no", type="bool", aliases=["prefer-dist"]),
|
prefer_dist=dict(default=False, type="bool", aliases=["prefer-dist"]),
|
||||||
no_dev = dict(default="yes", type="bool", aliases=["no-dev"]),
|
no_dev=dict(default=True, type="bool", aliases=["no-dev"]),
|
||||||
no_scripts = dict(default="no", type="bool", aliases=["no-scripts"]),
|
no_scripts=dict(default=False, type="bool", aliases=["no-scripts"]),
|
||||||
no_plugins = dict(default="no", type="bool", aliases=["no-plugins"]),
|
no_plugins=dict(default=False, type="bool", aliases=["no-plugins"]),
|
||||||
optimize_autoloader = dict(default="yes", type="bool", aliases=["optimize-autoloader"]),
|
optimize_autoloader=dict(default=True, type="bool", aliases=["optimize-autoloader"]),
|
||||||
ignore_platform_reqs = dict(default="no", type="bool", aliases=["ignore-platform-reqs"]),
|
ignore_platform_reqs=dict(default=False, type="bool", aliases=["ignore-platform-reqs"]),
|
||||||
),
|
),
|
||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
@ -203,17 +203,17 @@ def main():
|
||||||
option = "--%s" % option
|
option = "--%s" % option
|
||||||
options.append(option)
|
options.append(option)
|
||||||
|
|
||||||
options.extend(['--working-dir', os.path.abspath(module.params['working_dir'])])
|
options.extend(['--working-dir', "'%s'" % module.params['working_dir']])
|
||||||
|
|
||||||
option_params = {
|
option_params = {
|
||||||
'prefer_source': 'prefer-source',
|
'prefer_source': 'prefer-source',
|
||||||
'prefer_dist': 'prefer-dist',
|
'prefer_dist': 'prefer-dist',
|
||||||
'no_dev': 'no-dev',
|
'no_dev': 'no-dev',
|
||||||
'no_scripts': 'no-scripts',
|
'no_scripts': 'no-scripts',
|
||||||
'no_plugins': 'no_plugins',
|
'no_plugins': 'no_plugins',
|
||||||
'optimize_autoloader': 'optimize-autoloader',
|
'optimize_autoloader': 'optimize-autoloader',
|
||||||
'ignore_platform_reqs': 'ignore-platform-reqs',
|
'ignore_platform_reqs': 'ignore-platform-reqs',
|
||||||
}
|
}
|
||||||
|
|
||||||
for param, option in option_params.items():
|
for param, option in option_params.items():
|
||||||
if module.params.get(param) and option in available_options:
|
if module.params.get(param) and option in available_options:
|
||||||
|
@ -231,9 +231,8 @@ def main():
|
||||||
else:
|
else:
|
||||||
# Composer version > 1.0.0-alpha9 now use stderr for standard notification messages
|
# Composer version > 1.0.0-alpha9 now use stderr for standard notification messages
|
||||||
output = parse_out(out + err)
|
output = parse_out(out + err)
|
||||||
module.exit_json(changed=has_changed(output), msg=output, stdout=out+err)
|
module.exit_json(changed=has_changed(output), msg=output, stdout=out + err)
|
||||||
|
|
||||||
|
|
||||||
# import module snippets
|
|
||||||
from ansible.module_utils.basic import *
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -158,7 +158,6 @@ lib/ansible/modules/network/snmp_facts.py
|
||||||
lib/ansible/modules/notification/hall.py
|
lib/ansible/modules/notification/hall.py
|
||||||
lib/ansible/modules/notification/sendgrid.py
|
lib/ansible/modules/notification/sendgrid.py
|
||||||
lib/ansible/modules/notification/sns.py
|
lib/ansible/modules/notification/sns.py
|
||||||
lib/ansible/modules/packaging/language/composer.py
|
|
||||||
lib/ansible/modules/packaging/language/maven_artifact.py
|
lib/ansible/modules/packaging/language/maven_artifact.py
|
||||||
lib/ansible/modules/packaging/os/apt.py
|
lib/ansible/modules/packaging/os/apt.py
|
||||||
lib/ansible/modules/packaging/os/apt_key.py
|
lib/ansible/modules/packaging/os/apt_key.py
|
||||||
|
|
Loading…
Reference in a new issue