Getting permissions error with CodeSniffer when deploying staging

Hi Everybody,

after updating my composer I tried to run a deploy on my staging server and got this error:

TASK [deploy : Finalize the deploy] ********************************************
System info:
  Ansible 2.0.2.0; Darwin
  Trellis at "Add connection-related cli options to ping command"
---------------------------------------------------
rmtree failed: [Errno 13] Permission denied: '/srv/www/rundumhamburg.com/rele
ases/20160526075423/vendor/squizlabs/php_codesniffer/CodeSniffer/Sniff.php'
fatal: [37.17.229.126]: FAILED! => {"changed": false, "failed": true}
	to retry, use: --limit @deploy.retry

have anyone seen this before? Any help here more than appreciated!

1 Like

I’ve been getting this too:

TASK [deploy : Finalize the deploy] ********************************************
System info:
  Ansible 2.0.2.0; Darwin
  Trellis at "Require Ansible 2.0.2 and remove deploy_helper"
---------------------------------------------------
rmtree failed: [Errno 13] Permission denied: '/srv/www/teamrubiconusa.org/rel
eases/20160615230557/vendor/squizlabs/php_codesniffer/README.md'
fatal: [138.197.60.5]: FAILED! => {"changed": false, "failed": true}
	to retry, use: --limit @deploy.retry

PLAY RECAP *********************************************************************
138.197.60.5               : ok=24   changed=7    unreachable=0    failed=1

I also made a change to composer, adding a new require. The composer.lock file is supposed to be committed and pushed as well, correct?

Tried again with -vvvv; here’s the output:

TASK [deploy : Finalize the deploy] ********************************************
task path: /www/projects/teamrubicon/tr2/trellis/roles/deploy/tasks/finalize.yml:5
<138.197.60.5> ESTABLISH SSH CONNECTION FOR USER: web
<138.197.60.5> SSH: EXEC ssh -C -vvv -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=web -o ConnectTimeout=10 -o ControlPath=/Users/jeremymiller/.ansible/cp/ansible-ssh-%h-%p-%r 138.197.60.5 '/bin/sh -c '"'"'( umask 22 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1466457273.67-180273956545401 `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-1466457273.67-180273956545401 `" )'"'"''
<138.197.60.5> PUT /var/folders/yj/201hb9l96zb8dw37n42n17bm0000gn/T/tmp8Ow6Kp TO /home/web/.ansible/tmp/ansible-tmp-1466457273.67-180273956545401/deploy_helper
<138.197.60.5> SSH: EXEC sftp -b - -C -vvv -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=web -o ConnectTimeout=10 -o ControlPath=/Users/jeremymiller/.ansible/cp/ansible-ssh-%h-%p-%r '[138.197.60.5]'
<138.197.60.5> ESTABLISH SSH CONNECTION FOR USER: web
<138.197.60.5> SSH: EXEC ssh -C -vvv -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=web -o ConnectTimeout=10 -o ControlPath=/Users/jeremymiller/.ansible/cp/ansible-ssh-%h-%p-%r -tt 138.197.60.5 '/bin/sh -c '"'"'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/web/.ansible/tmp/ansible-tmp-1466457273.67-180273956545401/deploy_helper; rm -rf "/home/web/.ansible/tmp/ansible-tmp-1466457273.67-180273956545401/" > /dev/null 2>&1'"'"''
System info:
  Ansible 2.0.2.0; Darwin
  Trellis at "Require Ansible 2.0.2 and remove deploy_helper"
---------------------------------------------------
rmtree failed: [Errno 13] Permission denied: '/srv/www/teamrubiconusa.org/rel
eases/20160615230557/vendor/squizlabs/php_codesniffer/README.md'
fatal: [138.197.60.5]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_args": {"backup": null, "clean": true, "content": null, "current_path": "current", "delimiter": null, "directory_mode": null, "follow": false, "force": null, "group": null, "keep_releases": 5, "mode": null, "owner": null, "path": "/srv/www/teamrubiconusa.org", "regexp": null, "release": "20160620211357", "releases_path": "releases", "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "shared_path": "shared", "src": null, "state": "finalize", "unfinished_filename": "DEPLOY_UNFINISHED"}, "module_name": "deploy_helper"}}
	to retry, use: --limit @deploy.retry

PLAY RECAP *********************************************************************
138.197.60.5               : ok=24   changed=7    unreachable=0    failed=1

And I checked out the logs in /var/logs; the only relevant logs came from syslog but don’t appear to really show much:

Jun 20 21:29:53 tr-us-production ansible-file: Invoked with directory_mode=None force=False remote_src=None path=/srv/www/teamrubiconusa.org/releases/20160620212922/web/app/uploads owner=None follow=False group=N
one state=link content=NOT_LOGGING_PARAMETER serole=None diff_peek=None setype=None selevel=None original_basename=None regexp=None validate=None src=/srv/www/teamrubiconusa.org/shared/uploads seuser=None recurse
=False delimiter=None mode=None backup=None
Jun 20 21:29:54 tr-us-production ansible-deploy_helper: Invoked with directory_mode=None force=None remote_src=None path=/srv/www/teamrubiconusa.org owner=None follow=False group=None keep_releases=5 setype=None
content=NOT_LOGGING_PARAMETER serole=None shared_path=shared releases_path=releases current_path=current state=finalize selevel=None regexp=None src=None unfinished_filename=DEPLOY_UNFINISHED seuser=None delimite
r=None mode=None clean=True release=20160620212922 backup=None
Jun 20 21:30:01 tr-us-production CRON[18569]: (web) CMD (curl -k -s ${WP_HOME}/wp/wp-cron.php > /dev/null 2>&1)
Jun 20 21:39:01 tr-us-production CRON[18619]: (root) CMD (  [ -x /usr/lib/php/sessionclean ] && /usr/lib/php/sessionclean)
Jun 20 21:45:01 tr-us-production CRON[18675]: (web) CMD (curl -k -s ${WP_HOME}/wp/wp-cron.php > /dev/null 2>&1)

While it “failed” finishing the deploy, everything actually did deploy as far as I can tell, so I’m not sure if it’s safe to continue deploying while I get the error.

That’s correct.

@runofthemill or @Bruno have either of you made any manual changes on the remote server to files?

Hi @swalkinshaw thanks for looking into this. No I didn’t make any manual changes on remote. projects deploys fine though this error doesn’t seem to break anything but is annoying…

I’ve changed the permissions on /uploads, since I copied via FTP and had to chown to www:web-user but aside from that no.

I pulled in all the updates to trellis, then re-provisioned the server, then deployed, but still getting the same issue.

If it’s possible it might be worthwhile to delete /srv/www and a new provision + deploy ensure it’s in a good state.

Warning: this would obviously result in a little downtime between the new deploys and make sure to back any uploads or anything else that isn’t in your repo.

It can’t really be a coincidence that you are both having problems with php_codesniffer though which is really strange.

1 Like

Yeah agreed, I don’t think it’s a coincidence. I may just remove it from require-dev and install globally on my system. But an actual fix might be telling trellis not to install anything in require-dev for staging/production?

Nevermind - I see the composer install command includes --no-dev so that’s not the problem…

Edit: after removing php_codesniffer and trying to deploy, I got the same error. But upon removing the offending release folder (from the error message) in /releases and deploying once more, the deploy finished successfully. @Bruno

Interesting… wonder why php_codesniffer ever got installed then.

Can’t speak to @bruno but I was using it to lint some theme code :sweat_smile:

Hi @runofthemill, thanks for your tests!! I will check it out and let you know.

1 Like

I had exactly the same error on deploying but the remote was actually updated, just a bit annoying and misleading. After earsing /srv/www completely, reprovisionning and re-deploying again each of my sites the error was completely gone.