1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-02 10:26:22 +00:00

[PR #11689/a4bba992 backport][stable-12] composer - make create-project idempotent, add force parameter (#11700)

composer - make `create-project` idempotent, add `force` parameter (#11689)

* composer - make create-project idempotent, add force parameter

Adds a check for an existing composer.json in working_dir before running
create-project, so the task is skipped rather than failing on second run.
A new force parameter allows bypassing this check when needed.

Fixes #725.



* changelog fragment: rename to PR number, add PR URL



---------


(cherry picked from commit a4bba99203)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
patchback[bot] 2026-03-27 21:34:35 +01:00 committed by GitHub
parent 1a1056099c
commit de180d01e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 97 additions and 7 deletions

View file

@ -98,6 +98,14 @@ options:
these.
default: false
type: bool
force:
description:
- When O(command) is V(create-project), the module checks whether a V(composer.json) already
exists in O(working_dir) and skips the command if it does, making the task idempotent.
- Set to V(true) to always run the command regardless.
default: false
type: bool
version_added: 12.6.0
composer_executable:
type: path
description:
@ -139,6 +147,7 @@ EXAMPLES = r"""
arguments: my/package
"""
import os
import re
import shlex
@ -212,6 +221,7 @@ def main():
optimize_autoloader=dict(default=True, type="bool"),
classmap_authoritative=dict(default=False, type="bool"),
ignore_platform_reqs=dict(default=False, type="bool"),
force=dict(default=False, type="bool"),
composer_executable=dict(type="path"),
),
required_if=[("global_command", False, ["working_dir"])],
@ -257,6 +267,12 @@ def main():
option = f"--{option}"
options.append(option)
working_dir = module.params["working_dir"]
if command == "create-project" and not module.params["force"]:
if working_dir and os.path.exists(os.path.join(working_dir, "composer.json")):
module.exit_json(changed=False, msg="composer.json already exists in working_dir, skipping create-project")
if module.check_mode:
if "dry-run" in available_options:
options.append("--dry-run")