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

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
        }
    }
}
2 Likes

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

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.

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.

15 Likes

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.