./deploy.sh fails

So yesterday I was able to provision an EC2 instance with the help of bedrock-ansible and this forum members :smile:

Today i was hoping to do a deploy but if i run
if i run cosmoscms-ansible rui$ ./deploy.sh staging cosmoscms.dev

PLAY [Deploy WP site] ********************************************************* 

GATHERING FACTS *************************************************************** 
ok: [ec2-54-155-45-59.eu-west-1.compute.amazonaws.com]

TASK: [deploy | Initialize] *************************************************** 
failed: [ec2-54-155-45-59.eu-west-1.compute.amazonaws.com] => {"failed": true, "parsed": false}
Traceback (most recent call last):
  File "/home/ubuntu/.ansible/tmp/ansible-tmp-1429136055.96-24660798247429/deploy_helper", line 2020, in <module>
    main()
  File "/home/ubuntu/.ansible/tmp/ansible-tmp-1429136055.96-24660798247429/deploy_helper", line 383, in main
    changes += deploy_helper.create_path(facts['releases_path'])
  File "/home/ubuntu/.ansible/tmp/ansible-tmp-1429136055.96-24660798247429/deploy_helper", line 276, in create_path
    os.makedirs(path)
  File "/usr/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/srv/www/cosmoscms.dev/releases'
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: auto-mux: Trying existing master
debug1: Control socket "/Users/rui/.ansible/cp/ansible-ssh-ec2-54-155-45-59.eu-west-1.compute.amazonaws.com-22-ubuntu" does not exist
debug1: Connecting to ec2-54-155-45-59.eu-west-1.compute.amazonaws.com [54.155.45.59] port 22.
debug1: fd 3 clearing O_NONBLOCK
debug1: Connection established.
debug1: identity file /Users/rui/cosmos-cms.com/staging.pem type -1
debug1: identity file /Users/rui/cosmos-cms.com/staging.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com zlib@openssh.com
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com zlib@openssh.com
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 42:ce:da:d1:ea:ad:c2:93:cd:fc:71:b0:29:12:e5:1d
debug1: Host 'ec2-54-155-45-59.eu-west-1.compute.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /Users/rui/.ssh/known_hosts:25
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/rui/cosmos-cms.com/staging.pem
debug1: read PEM private key done: type RSA
debug1: Enabling compression at level 6.
debug1: Authentication succeeded (publickey).
Authenticated to ec2-54-155-45-59.eu-west-1.compute.amazonaws.com ([54.155.45.59]:22).
debug1: setting up multiplex master socket
ControlPath "/Users/rui/.ansible/cp/ansible-ssh-ec2-54-155-45-59.eu-west-1.compute.amazonaws.com-22-ubuntu.3es4Y5DwRZcBCvbN" too long for Unix domain socket
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Requesting authentication agent forwarding.
debug1: Sending environment.
debug1: Sending env LANG = pt_PT.UTF-8
debug1: Sending command: /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1429136055.96-24660798247429/deploy_helper; rm -rf /home/ubuntu/.ansible/tmp/ansible-tmp-1429136055.96-24660798247429/ >/dev/null 2>&1'
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 1 clearing O_NONBLOCK
debug1: fd 2 clearing O_NONBLOCK
Connection to ec2-54-155-45-59.eu-west-1.compute.amazonaws.com closed.
Transferred: sent 3100, received 3660 bytes, in 0.7 seconds
Bytes per second: sent 4718.7, received 5571.1
debug1: Exit status 0
debug1: compress outgoing: raw data 731, compressed 468, factor 0.64
debug1: compress incoming: raw data 964, compressed 548, factor 0.57


FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/Users/rui/deploy.retry

ec2-54-155-45-59.eu-west-1.compute.amazonaws.com : ok=1    changed=0    unreachable=0    failed=1   

anyone knows what this output means?
thanks in advance

Well it should be obvious:

Permission denied: '/srv/www/cosmoscms.dev/releases'

The deploy playbook uses the web_user which by default is set to web.

See https://github.com/roots/bedrock-ansible/blob/ff967d15459280b4b1cdbed92c7c376cf6207038/group_vars/all#L15

And hereā€™s the deploy.yml playbook that uses it: https://github.com/roots/bedrock-ansible/blob/ff967d15459280b4b1cdbed92c7c376cf6207038/deploy.yml#L4

It looks like youā€™re running under the ubuntu user which is why it isnā€™t working. Did you edit that user in deploy.yml? Or maybe you overrode it in a hosts file?

1 Like

Yes in the hosts file iā€™ve set it to ubuntu. should i change it?

This is the content of my hosts/staging file:

   [web]
ec2-54-155-45-xx.eu-west-1.compute.amazonaws.com ansible_ssh_private_key_file=~/cosmos-cms.dev/staging.pem  ansible_ssh_user=ubuntu

[staging:children]
web

Wasnā€™t the issue in the last thread that you were using the user ā€œubuntoā€ and not ā€œubuntuā€?

bad copy pasting from me @kalenjohnson ā€¦ the ansible_ssh_user=ubuntu is on the hosts/staging file and not ubunto i will edit my last comment for accuracy

You should remove ansible_ssh_user entirely from your hosts files. Youā€™re better off just altering the user in server.yml here.

Removing ansible_ssh_user will also mean your deploy script will run as the correct user and hopefully fix your problems.

1 Like

A few more thoughtsā€¦ It looks like Ansible manages to connect as the user ubuntu, manages to gather facts, but then fails on the first task that tries to manipulate files. Iā€™m guessing it fails because those files are owned by the web_user specified in group_vars/all, like @swalkinshaw pointed out. If youā€™ve left web_user: web but are deploying as ubuntu, maybe thatā€™s the problem.

If for some reason you canā€™t use bedrock-ansibleā€™s defaults for users and need to change the users, try like @swalkinshaw suggested with the edit in server.yml, but you may also need to be sure that web_user in your group_vars/all matches the remote_user in deploy.yml (bedrock-ansibleā€™s defaults have them matching).

1 Like

Folow up:

just to say that now iā€™m able to deploy with ansible to my staging and production environments both on AWS EC2, Iā€™m also compiling locally my sage version with the tips iā€™ve found on https://github.com/roots/roots-example-project.com

After much trial and error with the ubunto user that is set by default . I just copy the ssh key from ubunto to root and all my problems were solved

Thank you all for your time and patience replying to my noob questions !!

1 Like

I cannot make this work either. Can you tell me how did you copy your SSH key form ubuntu to root?

ssh -i KEYPAIR.pem ubuntu@HOSTNAME   'sudo cp /home/ubuntu/.ssh/authorized_keys /root/.ssh/'

This is not recommended, but it may be a way to get existing EC2 automation code to continue working until you can upgrade to the sudo practices described here :