├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── defaults └── main.yml ├── meta └── main.yml ├── tasks ├── auth_json.yml ├── configure.yml ├── install.yml ├── main.yml ├── test.yml └── update.yml ├── templates └── .composer │ └── auth.json.j2 └── tests ├── Makefile ├── Vagrantfile ├── inventory ├── playbook.yml └── roles └── common └── tasks └── main.yml /.gitignore: -------------------------------------------------------------------------------- 1 | tests/.vagrant 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | language: python 4 | 5 | python: 6 | - 2.7 7 | 8 | install: 9 | - pip install ansible==1.5.0 10 | 11 | script: 12 | - cd tests 13 | - ansible-playbook -i inventory playbook.yml --syntax-check 14 | - ansible-playbook -i inventory playbook.yml --connection=local --sudo 15 | - > 16 | ansible-playbook -i inventory playbook.yml --connection=local --sudo 17 | | grep -q 'changed=0.*unreachable=0.*failed=0' 18 | && (echo 'Idempotence test: pass' && exit 0) 19 | || (echo 'Idempotence test: fail' && exit 1) 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2014-2015 Simon Constans 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ansible-role-composer 2 | 3 | [![License](https://img.shields.io/badge/License-MIT%20License-blue.svg)](https://github.com/kosssi/ansible-role-composer/blob/master/LICENSE) 4 | [![Build Status](https://travis-ci.org/kosssi/ansible-role-composer.svg?branch=master)](https://travis-ci.org/kosssi/ansible-role-composer) 5 | 6 | Installs Composer, the PHP Dependency Manager. 7 | 8 | ## Role Defaults Variables 9 | 10 | composer_path: /usr/local/bin/composer 11 | composer_update: true 12 | composer_update_day: 20 13 | 14 | The path where composer will be installed and available to your system. Should be in your user's `$PATH` so you can run 15 | commands simply with `composer` instead of the full path. 16 | 17 | You can also setup a global composer directory and make the bin directory available in the `$PATH` automatically by: 18 | 19 | composer_path_env: true 20 | composer_home_path: /opt/composer 21 | composer_home_owner: root 22 | composer_home_group: root 23 | composer_global_packages: 24 | phpunit/phpunit: "@stable" 25 | 26 | ## Auth.json 27 | 28 | ### Github OAuth token 29 | 30 | If your project use a lot of libraries from github, you may see next message during `composer install`: 31 | 32 | Could not fetch `...`, enter your GitHub credentials to go over the API rate limit 33 | A token will be created and stored in "~/.composer/auth.json", your password will never be stored 34 | To revoke access to this token you can visit https://github.com/settings/applications 35 | 36 | So your `composer install` can get stuck. 37 | 38 | To prevent that, you must configure github oauth token to go over the API rate limit. Visit https://github.com/settings/applications and generate personal access token and assign it to `composer_github_oauth` variable. 39 | 40 | composer_github_oauth: f03401aae1e276abb073f987c08a32410f462e73 41 | 42 | ### HTTP Basic auth 43 | 44 | You can provide HTTP Basic auth credentials to any repository like this: 45 | 46 | ``` 47 | composer_http_basic: 48 | repo.magento.com: 49 | username: 52fe41da9d8caa70538244c10f367d0a 50 | password: 238fe32d374a2573c4527bd45a7e6f54 51 | ``` 52 | 53 | ## Example Playbook 54 | 55 | roles: 56 | - { role: kosssi.composer } 57 | 58 | ## Tests 59 | 60 | If you have vagrant, you can test this role: 61 | 62 | cd tests 63 | vagrant up 64 | vagrant provision 65 | 66 | ## Special thanks to contributors 67 | 68 | * [jnakatsui](https://github.com/jnakatsui) 69 | * [Yosh](https://github.com/yoshz) 70 | * [Johnny Robeson](https://github.com/jrobeson) 71 | * [Sebastian Krebs](https://github.com/KingCrunch) 72 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | composer_path: /usr/local/bin/composer 4 | composer_update: true 5 | composer_update_day: 20 6 | composer_path_env: False 7 | #composer_home_path: /opt/composer 8 | composer_home_owner: root 9 | composer_home_group: root 10 | composer_global_packages: {} 11 | 12 | # Visit https://github.com/settings/applications 13 | # and generate personal access token 14 | composer_github_oauth: false 15 | composer_http_basic: false 16 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | galaxy_info: 4 | author: kosssi 5 | description: Install and Update Composer PHP Dependency Manager 6 | license: license MIT 7 | min_ansible_version: 1.5 8 | platforms: 9 | - name: Ubuntu 10 | versions: 11 | - all 12 | - name: Debian 13 | versions: 14 | - all 15 | - name: Fedora 16 | versions: 17 | - all 18 | - name: CentOS 19 | versions: 20 | - all 21 | - name: Redhat 22 | versions: 23 | - all 24 | categories: 25 | - packaging 26 | - web 27 | - php 28 | - composer 29 | dependencies: [] 30 | -------------------------------------------------------------------------------- /tasks/auth_json.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Configure github oauth token 4 | template: 5 | src: ".composer/auth.json.j2" 6 | dest: "{{ composer_home_path|default('~/.composer') }}/auth.json" 7 | when: composer_github_oauth != false or composer_http_basic != false 8 | -------------------------------------------------------------------------------- /tasks/configure.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Create composer home path 4 | file: path={{ composer_home_path|default('~/.composer') }} state=directory owner={{ composer_home_owner }} group={{ composer_home_group }} 5 | 6 | - name: Configure composer home path 7 | copy: dest=/etc/profile.d/composer-home.sh mode=0755 8 | content="export COMPOSER_HOME={{ composer_home_path}}\n" 9 | when: composer_home_path is defined 10 | 11 | - name: Configure composer path environment 12 | copy: dest=/etc/profile.d/composer-path.sh mode=0755 13 | content="export PATH=${PATH}:{{ composer_home_path|default('~/.composer') }}/vendor/bin\n" 14 | when: composer_path_env 15 | 16 | - name: Global require packages 17 | shell: COMPOSER_HOME={{ composer_home_path|default('~/.composer') }} 18 | composer global require {{ item.key }}:{{ item.value }} --no-progress 19 | creates={{ composer_home_path|default('~/.composer') }}/vendor/{{ item.key }} 20 | with_dict: '{{ composer_global_packages }}' 21 | when: composer_global_packages|length > 0 22 | -------------------------------------------------------------------------------- /tasks/install.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Download and install Composer into the target directory. 4 | get_url: 5 | url=https://getcomposer.org/composer.phar 6 | dest={{ composer_path }} 7 | mode=0755 8 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - include: install.yml 4 | - include: test.yml 5 | - include: configure.yml 6 | - include: auth_json.yml 7 | - include: update.yml 8 | when: composer_update == true 9 | -------------------------------------------------------------------------------- /tasks/test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Get stat of composer file 4 | stat: 5 | path="{{ composer_path }}" 6 | register: composer_stat 7 | 8 | - name: Test if composer file exist 9 | fail: 10 | msg="{{ composer_path }} isn't exist" 11 | when: composer_stat.stat.exists == false 12 | -------------------------------------------------------------------------------- /tasks/update.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Get date for composer update 4 | shell: 5 | date --date='{{ composer_update_day }} days ago' +'%s' 6 | register: composer_date 7 | changed_when: False 8 | 9 | - name: Update composer if necessary 10 | shell: 11 | "{{ composer_path }} selfupdate" 12 | when: composer_date.stdout|int > composer_stat.stat.mtime|int 13 | -------------------------------------------------------------------------------- /templates/.composer/auth.json.j2: -------------------------------------------------------------------------------- 1 | { 2 | {% if composer_http_basic %} 3 | "http-basic": { 4 | {% for repository,credentials in composer_http_basic.iteritems() %} 5 | {% if loop.index0 %},{% endif %} 6 | "{{ repository }}": { 7 | "username": "{{ credentials.username }}", 8 | "password": "{{ credentials.password }}" 9 | } 10 | {% endfor %} 11 | } 12 | {% endif %} 13 | {% if composer_http_basic and composer_http_basic %},{% endif %} 14 | {% if composer_github_oauth %} 15 | "github-oauth": { 16 | "github.com": "{{ composer_github_oauth }}" 17 | } 18 | {% endif %} 19 | } 20 | -------------------------------------------------------------------------------- /tests/Makefile: -------------------------------------------------------------------------------- 1 | test_ubuntu-14.04: 2 | VM_BOX='ubuntu/trusty64' vagrant up --provision 3 | VM_BOX='ubuntu/trusty64' vagrant provision 4 | VM_BOX='ubuntu/trusty64' vagrant destroy -f 5 | 6 | test_ubuntu-12.04: 7 | VM_BOX='hashicorp/precise64' vagrant up --provision 8 | VM_BOX='hashicorp/precise64' vagrant provision 9 | VM_BOX='hashicorp/precise64' vagrant destroy -f 10 | 11 | test_debian-7.5: 12 | VM_BOX='puphpet/debian75-x64' vagrant up --provision 13 | VM_BOX='puphpet/debian75-x64' vagrant provision 14 | VM_BOX='puphpet/debian75-x64' vagrant destroy -f 15 | -------------------------------------------------------------------------------- /tests/Vagrantfile: -------------------------------------------------------------------------------- 1 | $VM_BOX = ENV.has_key?('VM_BOX') ? ENV['VM_BOX'] : 'ubuntu/trusty64' 2 | 3 | Vagrant.configure('2') do |config| 4 | config.vm.box = $VM_BOX 5 | 6 | config.vm.provision :ansible do |ansible| 7 | ansible.playbook = 'playbook.yml' 8 | ansible.extra_vars = { ansible_ssh_user: 'vagrant', vagrant: true } 9 | 10 | ansible.verbose = 'v' 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /tests/inventory: -------------------------------------------------------------------------------- 1 | localhost 2 | -------------------------------------------------------------------------------- /tests/playbook.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - hosts: all 4 | sudo: true 5 | vars: 6 | composer_github_oauth: f03401aae1e276abb073f987c08a32410f462e73 7 | composer_http_basic: 8 | repo.magento.com: 9 | username: 52fe41da9d8caa70538244c10f367d0a 10 | password: 238fe32d374a2573c4527bd45a7e6f54 11 | roles: 12 | - { role: common, tags: apt } 13 | - { role: ../../ansible-role-composer, tags: composer } 14 | -------------------------------------------------------------------------------- /tests/roles/common/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Update Apt cache 4 | apt: 5 | update_cache=yes 6 | cache_valid_time=3600 7 | 8 | - name: Install php packages 9 | apt: 10 | pkg=php5 11 | state=present 12 | --------------------------------------------------------------------------------