Search code examples
ansibleansible-2.xvagrant-provision

ERROR: composer is not a legal parameter in an Ansible task or handler


Hi I've been trying to make ansible run composer install to install all the content in my composer.json inside my laravel file. But I'm getting this error ERROR: composer is not a legal parameter in an Ansible task or handler I'm not sure what's causing this. Below are the content of my playbook.

---
- name: Install PHP5+
  apt: name={{ item }} update_cache=yes state=latest
  with_items:
    - git
    - mcrypt
    - php5-cli
    - php5-curl
    - php5-fpm
    - php5-intl
    - php5-json
    - php5-mcrypt
    - php5-sqlite
    - sqlite3
  notify:
    - Reload Nginx
- name: install composer
  shell: curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
  args:
    creates: /usr/local/bin/composer
- composer:
    command: install
    working_dir: /path/to/project

Now if I do vagrant provision I'm getting the Composer is not a legal parameter. Basically I just wanted to run composer and tell composer to install all dependency inside my composer json

http://docs.ansible.com/ansible/composer_module.html


Solution

  • I will usually just use a role from Ansible Galaxy, such as geerlingguy.composer for such requirements.

    According to the Ansible Docs, the composer module is available from Ansible 1.6, but requires composer to be pre-installed on the executable path.

    Installing Composer is usually going to be a multi-step process, if you use the installer (from the geerlingguy.composer tasks/main.yml).

    • Check if Composer is installed.
    • Download Composer installer (with Ansible get_url).
    • Run Composer installer (via PHP executable).
    • Move Composer into globally-accessible location.
    • Update Composer to latest version (if configured).
    • Ensure composer directory exists.
    • Add GitHub OAuth token for Composer (if configured).

    Or, you can download the latest version, https://getcomposer.org/composer.phar or a tagged version make it executable and move it into an appropriate directory.