geerlingguy.composer
Ansible Role: Composer
This role installs Composer, which is a tool to manage PHP dependencies, on any Linux or UNIX system.
Requirements
- You need to have
php
version 5.4 or higher installed and working. You can use thegeerlingguy.php
role to install it. - You also need to have
git
installed and working. Use thegeerlingguy.git
role to install it.
Role Variables
Here are the available variables and their default values (see defaults/main.yml
):
composer_path: The location where Composer will be installed. The default path is
/usr/local/bin/composer
. This should be in your user’s$PATH
so you can usecomposer
commands easily.composer_keep_updated: Set to
false
by default. If you set it totrue
, Composer will be updated to the latest version every time you run the playbook.composer_home_path: This is set to
~/.composer
by default. It's the directory where globally installed packages will go.composer_home_owner: The owner of the
COMPOSER_HOME
directory, default isroot
.composer_home_group: The group of the
COMPOSER_HOME
directory, default isroot
.composer_version: If you want a specific version of Composer, you can specify it here (e.g.,
composer_version: '1.0.0-alpha11'
). If left empty, the latest version will install. Note that ifcomposer_keep_updated
istrue
, this setting will be ignored.composer_version_branch: This sets the major version of Composer to use. The default is
--2
. Ifcomposer_keep_updated
istrue
, it will always install the latest version from this branch.composer_global_packages: This is a list of packages you want to install globally. You can specify packages with their name and optional release version, e.g.,
- { name: phpunit/phpunit, release: "4.7.*" }
. If no release is specified, it will default to the stable version.composer_add_to_path: If set to
true
, and you have any global packages configured, thevendor/bin
directory insidecomposer_home_path
will be added to the system’s default$PATH
.composer_project_path: Set this to the path of your Composer project.
composer_add_project_to_path: If set to
true
and acomposer_project_path
is configured, thevendor/bin
directory inside that path will be added to the system’s default$PATH
.composer_github_oauth_token: This is a GitHub OAuth token. It helps avoid errors when hitting GitHub API rate limits while using Composer. Follow GitHub’s guide to create a personal access token if you encounter rate limit issues.
php_executable: This is the name or path to the PHP executable. It defaults to
php
unless you change it.
Using Composer 1
If you're working on projects that need Composer 1, set the following variables:
- composer_version_branch: Leave empty.
- composer_version: Set this to
1.10.12
.
Dependencies
No dependencies other than having PHP installed. The geerlingguy.php
role is recommended for PHP installation.
Example Playbook
- hosts: servers
roles:
- geerlingguy.composer
After running the playbook, composer
will be installed in /usr/local/bin/composer
(you can change this location), and it will be usable by normal system users.
License
MIT / BSD
Author Information
This role was created in 2014 by Jeff Geerling, who is also the author of Ansible for DevOps.
ansible-galaxy install geerlingguy.composer