I have a VPS sever where I deploy frequently releases and the dir structure is that I have a current dir, what is a symlink to an actual release under a releases dir. How can I achieve, that only X ( in my case 3) releases stay in the releases dir, the rest can be deleted, to spare free HDD and because I don't need them any more. This setup is what capifony uses.
Something along this lines should work, where bin would be your symlinked directory :
- name: Set timestamp
set_fact: release_timestamp="{{ansible_date_time.epoch}}"
- name: Deploy code from repository
action: git repo={{repo_url}} dest={{app_dir}}/releases/{{release_timestamp}} remote={{repo_remote}} version={{branch}}
- name: Create symlink to bin folder
file: src={{app_dir}}/releases/{{release_timestamp}} dest={{app_dir}}/bin state=link
- name: List old releases and clean them up
shell: "ls -t {{app_dir}}/releases | tail -n +{{releases_to_keep + 1}}"
register: ls_output
- file: name={{app_dir}}/releases/{{ item }} state=absent
with_items: ls_output.stdout_lines
If you want to do rollback:
- name: Find the previous release
shell: "ls -t {{app_dir}}/releases | head -2 | tail -1"
register: ls_output
- name: Create symlink to previous release folder
file: src={{app_dir}}/releases/{{item}} dest={{app_dir}}/bin state=link
with_items: ls_output.stdout_lines
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With