0
votes

I'm working on Ansible playbook. When provisioning on a vagrant machine, it goes well, without errors. Right now I'm on a trouble on the step where composer is installed programatically.

install-composer.sh (This script has been taken from Composer Page)

#!/bin/sh

EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)"
echo $EXPECTED_SIGNATURE;
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
echo $ACTUAL_SIGNATURE; <- Here is empty!

if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
    >&2 echo 'ERROR: Invalid installer signature'
    rm composer-setup.php
    exit 1
fi

php composer-setup.php --quiet
RESULT=$?
rm composer-setup.php
exit $RESULT

The EC2 is a Ubuntu 16.04 instance, on vagrant as well.

Playbook task where i'm getting the error:

 - name: Download Composer
      script: scripts/install_composer.sh
      register: composer_setup
      #when: not composer_stat.stat.exists
      tags:
        - deploy

And the full error with --verbose:

TASK [Download Composer] ******************************************************* fatal: [18.203.185.87]: FAILED! => {"changed": true, "failed": true, "rc": 1, "stderr": "Shared connection to 18.203.185.87 closed.\r\n", "stdout": "a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1\r\n/home/ubuntu/.ansible/tmp/ansible-tmp-1566333565.4-174304924088429/install_composer.sh: 5: /home/ubuntu/.ansible/tmp/ansible-tmp-1566333565.4-174304924088429/install_composer.sh: php: not found\r\n/home/ubuntu/.ansible/tmp/ansible-tmp-1566333565.4-174304924088429/install_composer.sh: 6: /home/ubuntu/.ansible/tmp/ansible-tmp-1566333565.4-174304924088429/install_composer.sh: php: not found\r\n\r\nERROR: Invalid installer signature\r\nrm: cannot remove 'composer-setup.php': No such file or directory\r\n", "stdout_lines": ["a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1", "/home/ubuntu/.ansible/tmp/ansible-tmp-1566333565.4-174304924088429/install_composer.sh: 5: /home/ubuntu/.ansible/tmp/ansible-tmp-1566333565.4-174304924088429/install_composer.sh: php: not found", "/home/ubuntu/.ansible/tmp/ansible-tmp-1566333565.4-174304924088429/install_composer.sh: 6: /home/ubuntu/.ansible/tmp/ansible-tmp-1566333565.4-174304924088429/install_composer.sh: php: not found", "", "ERROR: Invalid installer signature", "rm: cannot remove 'composer-setup.php': No such file or directory"]} changed:

[192.168.33.10] => {"changed": true, "rc": 0, "stderr": "Shared connection to 192.168.33.10 closed.\r\n", "stdout":

"a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1\r\na5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1\r\n", "stdout_lines": ["a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1", "a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1"]}

Any idea why this line is returning empty on ec2?

"$(php -r "echo hash_file('sha384', 'composer-setup.php');")"

Thanks!

2

2 Answers

2
votes

My first guess is that your EC2 instance doesn't have access to the internet. Can you verify this? The verbose logs indicate that the composer-setup.php file does not exist when you're trying to hash it. You should try downloading that file using the current copy() method, then doing something like:

TESTSTUFF="$(php -r "echo file_exists('composer-setup.php') ? 'FILE EXISTS' : 'FILE DOES NOT EXIST';")"
echo $TESTSTUFF

If the file does not exist, try to download a different file from somewhere, such as a dummy test file from here.

All of the signs point to the file not existing, which can caused by an array of issues. But, the most likely are:

  • No internet access on EC2 (Can you ping 8.8.8.8?)
  • Improper permissions to execute php
  • Improper permissions to write to the destination filesystem
1
votes

After Trying what Aaron Said, I saw that php was not correctly installed(not installed at all)

I was executing:

ansible-playbook ansible/playbook.yml -i ansible/hosts.ini -t deploy --ask-vault-pass --verbose

Note the tag deploy, so in here it is suposed that php was installed. All had to do was remove -t deploy from my command!