ansistrano / deploy

Ansible role to deploy scripting applications like PHP, Python, Ruby, etc. in a capistrano style
https://ansistrano.com
MIT License
2.37k stars 343 forks source link

Create softlinks for shared paths #275

Closed duythien closed 6 years ago

duythien commented 6 years ago

Hello Ansistano is great but recently I try to create share directory to check log, then I get an error below

TASK [carlosbuenosvinos.ansistrano-deploy : ANSISTRANO | Ensure shared paths targets are absent] *******************************************************************************
ok: [web01] => (item=var/logs)

TASK [carlosbuenosvinos.ansistrano-deploy : ANSISTRANO | Create softlinks for shared paths and files] **************************************************************************
failed: [web01] (item=var/logs) => {"failed": true, "item": "var/logs", "msg": "src file does not exist, use \"force=yes\" if you really want to create the link: /srv/www/releases/20180101034820Z/var/../../../shared/var/logs", "path": "/srv/www/releases/20180101034820Z/var/logs", "src": "../../../shared/var/logs", "state": "absent"}
    to retry, use: --limit @/Users/phanbook/github/DocumentRoot/ansible/deploy.retry

PLAY RECAP *********************************************************************************************************************************************************************
web01                      : ok=17   changed=7    unreachable=0    failed=1   

Here my config deploy file

 - hosts: web
   become: true
   vars:
    #ansistrano_deploy_from: "{{ playbook_dir }}/../web"
    ansistrano_deploy_to: "/srv/www"
    release_var_path: "{{ ansistrano_release_path.stdout }}/var"
    ansistrano_current_dir: "app"
    ansistrano_current_via: "symlink"
    ansistrano_version_dir: "releases" # Releases folder name
    ansistrano_keep_releases: 3
    ansistrano_deploy_via: git
     # Variables used in the Git deployment strategy
    ansistrano_git_repo: git@github.com:gsviec/aws001.git  # Location of the git repository
    ansistrano_git_branch: master # What version of the repository to check out. This can be the full 40-character SHA-1 hash, the literal string HEAD, a branch name, or a tag name
    ansistrano_git_repo_tree: "" # If specified the subtree of the repository to deploy
    #: "/Users/phanbook/.ssh/id_rsa" # If specified this file is copied over and used as the identity key for the git commands, path is relative to the playbook in which it is used
    ansistrano_git_identity_key_path: "/Users/phanbook/.ssh/id_rsa"
    ansistrano_shared_paths:
        - var/logs

    #ansistrano_git_identity_key_remote_path: "{{ lookup('env', 'ANSIBLE_GIT_KEY')|default('~/.ssh/id_rsa') }}" # If specified this file on the remote server is used as the identity key for the git commands, remote path is absolute
    #ansistrano_after_symlink_tasks_file: "{{ playbook_dir }}/deploy/before-update-code-tasks.yml"
    ansistrano_after_symlink_shared_tasks_file: "{{ playbook_dir }}/deploy/after-symlink-shared.yml"
   roles:
    - { role: carlosbuenosvinos.ansistrano-deploy }

And file after-symlink-shared.yml,

- name: Setup directory permissions for var/
  file:
    path: "{{ release_var_path }}"
    state: directory
    mode: 0777
    recurse: true
    # We need it because logs are symlinks now
    follow: yes

Anyway I have refer the article https://knpuniversity.com/screencast/ansistrano/shared-optimizations

ricardclau commented 6 years ago

If you want to create var/logs, var subfolder needs to exist inside shared folder (in your case that would be /srv/www/shared/var/logs), as it will not create the full path.

We are aware of this limitation, sorry about it, you can create a hook to ensure the var folder exists inside shared (If you look at our tests, we have a very similar example to this at https://github.com/ansistrano/deploy/blob/master/test/rsync.yml#L16:L30). Once this is done, you can probably remove the 0777 step as well once you set the proper permissions

duythien commented 6 years ago

@ricardclau Thanks I fix it now :)