# Rmtree failed: [Errno 13] Permission denied at Finalize the deploy

**URL:** https://discourse.roots.io/t/rmtree-failed-errno-13-permission-denied-at-finalize-the-deploy/11123
**Category:** trellis
**Created:** 2017-12-12T11:54:24Z
**Posts:** 5

## Post 1 by @richardwilis — 2017-12-12T11:54:24Z

Trellis @ Head #913  
Bedrock 1.8.5  
Sage 9 @ Head #1981

When I deploy (on a previous successfully deployed site) I suddenly receive this error:

```
System info:
  Ansible 2.4.0.0; Linux
  Trellis at "Enable Virtualbox ioapic option"
---------------------------------------------------
rmtree failed: [Errno 13] Permission denied: '/srv/www/mysite.
com/releases/20171209222749/web/app/themes/mytheme/
vendor/autoload.php'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_1Si1Lt/ansible_module_deploy_helper.py", line 340, in delete_path
    shutil.rmtree(path, ignore_errors=False)
  File "/usr/lib/python2.7/shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "/usr/lib/python2.7/shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "/usr/lib/python2.7/shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "/usr/lib/python2.7/shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "/usr/lib/python2.7/shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "/usr/lib/python2.7/shutil.py", line 252, in rmtree
    onerror(os.remove, fullname, sys.exc_info())
  File "/usr/lib/python2.7/shutil.py", line 250, in rmtree
    os.remove(fullname)
OSError: [Errno 13] Permission denied: '/srv/www/mysite.com/releases/20171209222749/web/app/themes/mytheme/vendor/autoload.php'

fatal: [my.ip]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "attributes": null, 
            "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/mytheme.com", 
            "regexp": null, 
            "release": "20171212123959", 
            "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", 
            "unsafe_writes": null
        }
    }
}
```

---

## Post 2 by @ben — 2017-12-12T15:41:08Z

Topic subject is unrelated to the actual error you received (please look a little closer)

> [@Deployment fails with Errno 13 rmtree - it’s always permissions!](https://discourse.roots.io/t/deployment-fails-with-errno-13-rmtree-it-s-always-permissions/6771):
>
> I’m running into a permissions problem on deployment: rmtree failed: [Errno 13] Permission denied: '/srv/www/ysgoltrewen/releases/20160425202926/web/app/plugins/sitepress- multilingual-cms/templates/wpml-mail/language-switcher.twig' fatal: [46.101.72.245]: FAILED! =\> {"changed": false, "failed": true} I’ve recursively [changed the permissions](http://codex.wordpress.org/Hardening_WordPress#File_Permissions) on /srv/www/ysgoltrewen/releases/ using the commands: find ./releases -type d -exec chmod 775 {} \; find ./releases -type f -exec chmod 644 {} \; Now I…

---

## Post 3 by @richardwilis — 2017-12-12T18:49:29Z

Scusa, fixed the subject line.

I’ve read the attached thread. I haven’t manually changed any permissions on the remote server or manually uploaded plugins, as seems to be the issue there.

However I had sneaked in a remote composer update or two before utilizing the build-before hook. Guess something went wrong there, perhaps a sudo.

---

## Post 4 by @runofthemill — 2017-12-12T21:56:26Z

I’ve run into this a few times before - if a prior deploy failed, Ansible will be unable to remove it (the release folder) during a subsequent deploy.

Looking at the path referenced, I’d guess your deploy on 12/09/2017 @ 22:27:49 didn’t complete, but the folder is still there.

SSH into the machine, and run `rm -rf /srv/www/mysite.com/releases/20171209222749/` - you should also run `rm -rf /srv/www/mysite.com/releases/20171212123959/` since the deploy failed on that too, so eventually you’ll run into the same issue when Trellis is trying to remove this release.

---

## Post 5 by @robrecord — 2023-05-10T13:09:39Z

This is still “a thing” 4½ years later so I wonder if it’s worth us creating a a way for ansible to remove a failed deploy. Happy to have a look myself if I get time, but just leaving the thought here.
