In Bash I usually install Composer this way:

curl -sS https://getcomposer.org/installer -o composer-setup.php
php composer-setup.php --install-dir=/usr/local/bin --filename=composer

I tried to read in the Ansible Composer module documentation just for a hint on what is the recommended way to install Composer with Ansible but I found none.

I just want to make sure that each time I install Composer it will be installed by the latest installation-command aside from being continuously upgraded by Ansible from my machine via SSH.

How could I do it in a Ansible "state: latest" way (as common with Ansible's apt module)?

  • What’s wrong with having Ansible execute the two commands you provided to install Composer? – Peschke Dec 16 '18 at 3:31
  • Nothing enough wrong, I can do that with the command module but let's assume the unlikely happened and "tomorrow" the command will no longer be stable, how could I ensure I up2date with that command? – JohnDoea Dec 16 '18 at 3:47
  1. Use get_url to output https://getcomposer.org/installer to a file composer-setup.php, ideally in some directory, let's say /tmp

  2. Use command module to run php /tmp/composer-setup.php ... step

Or search Ansible Galaxy, and see if anyone else has done it.

  • AFAIK the command module is for custom code that never changes, very much like plain Bash with the default shell to be combined in Ansible (I actually wrote it on VSCODE offline). I should read about get_url as I'm new to Ansible, I never heard of it before, but should this be like a curl or wget altogether as well and the command would be transcribed in the future (if there'll be such need) by the Ansible community? – JohnDoea Dec 18 '18 at 0:50
  • Anyway, I'll check the Ansible Galaxy. – JohnDoea Dec 18 '18 at 0:50
  • 1
    I think the get_url calls a urllib library in Python, and might fallback to wget or curl – cricket_007 Dec 18 '18 at 1:52
  • Sorry man ! One last thing - I just started a very nice question here regarding this, I believe it might be interesting for you to look at anyway ! unix.stackexchange.com/questions/489630/… – JohnDoea Dec 18 '18 at 8:06


ansible-galaxy install geerlingguy.composer

This will add geerlingguy.composer to your roles, which you can then add to your playbook.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.