community.general.composer module – Dependency Manager for PHP

Note

This module is part of the community.general collection (version 4.8.3).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general.

To use it in a playbook, specify: community.general.composer.

Synopsis

  • 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.

Requirements

The below requirements are needed on the host that executes this module.

  • php

  • composer installed in bin path (recommended /usr/local/bin) or specified in composer_executable

Parameters

Parameter

Comments

apcu_autoloader

aliases: apcu-autoloader

boolean

Uses APCu to cache found/not-found classes

Alias apcu-autoloader has been deprecated and will be removed in community.general 5.0.0.

Choices:

  • no ← (default)

  • yes

arguments

string

Composer arguments like required package, version and so on.

classmap_authoritative

aliases: classmap-authoritative

boolean

Autoload classes from classmap only.

Implicitely enable optimize_autoloader.

Recommended especially for production, but can take a bit of time to run.

Alias classmap-authoritative has been deprecated and will be removed in community.general 5.0.0.

Choices:

  • no ← (default)

  • yes

command

string

Composer command like “install”, “update” and so on.

Default: “install”

composer_executable

path

added in 3.2.0 of community.general

Path to composer executable on the remote host, if composer is not in PATH or a custom composer is needed.

executable

aliases: php_path

path

Path to PHP Executable on the remote host, if PHP is not in PATH.

global_command

aliases: global-command

boolean

Runs the specified command globally.

Alias global-command has been deprecated and will be removed in community.general 5.0.0.

Choices:

  • no ← (default)

  • yes

ignore_platform_reqs

aliases: ignore-platform-reqs

boolean

Ignore php, hhvm, lib-* and ext-* requirements and force the installation even if the local machine does not fulfill these.

Alias ignore-platform-reqs has been deprecated and will be removed in community.general 5.0.0.

Choices:

  • no ← (default)

  • yes

no_dev

aliases: no-dev

boolean

Disables installation of require-dev packages (see –no-dev).

Alias no-dev has been deprecated and will be removed in community.general 5.0.0.

Choices:

  • no

  • yes ← (default)

no_plugins

aliases: no-plugins

boolean

Disables all plugins ( see –no-plugins ).

Alias no-plugins has been deprecated and will be removed in community.general 5.0.0.

Choices:

  • no ← (default)

  • yes

no_scripts

aliases: no-scripts

boolean

Skips the execution of all scripts defined in composer.json (see –no-scripts).

Alias no-scripts has been deprecated and will be removed in community.general 5.0.0.

Choices:

  • no ← (default)

  • yes

optimize_autoloader

aliases: optimize-autoloader

boolean

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.

Alias optimize-autoloader has been deprecated and will be removed in community.general 5.0.0.

Choices:

  • no

  • yes ← (default)

prefer_dist

aliases: prefer-dist

boolean

Forces installation from package dist even for dev versions (see –prefer-dist).

Alias prefer-dist has been deprecated and will be removed in community.general 5.0.0.

Choices:

  • no ← (default)

  • yes

prefer_source

aliases: prefer-source

boolean

Forces installation from package sources when possible (see –prefer-source).

Alias prefer-source has been deprecated and will be removed in community.general 5.0.0.

Choices:

  • no ← (default)

  • yes

working_dir

aliases: working-dir

path

Directory of your project (see –working-dir). This is required when the command is not run globally.

Will be ignored if global_command=true.

Alias working-dir has been deprecated and will be removed in community.general 5.0.0.

Notes

Note

  • 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 issues.

Examples

- name: Download and installs all libs and dependencies outlined in the /path/to/project/composer.lock
  community.general.composer:
    command: install
    working_dir: /path/to/project

- name: Install a new package
  community.general.composer:
    command: require
    arguments: my/package
    working_dir: /path/to/project

- name: Clone and install a project with all dependencies
  community.general.composer:
    command: create-project
    arguments: package/package /path/to/project ~1.0
    working_dir: /path/to/project
    prefer_dist: yes

- name: Install a package globally
  community.general.composer:
    command: require
    global_command: yes
    arguments: my/package

Authors

  • Dimitrios Tydeas Mengidis (@dmtrs)

  • René Moser (@resmo)