diff --git a/tasks/cleanup.yml b/tasks/cleanup.yml index 85ceccd..5a7f35d 100644 --- a/tasks/cleanup.yml +++ b/tasks/cleanup.yml @@ -1,3 +1,4 @@ +--- - name: ANSISTRANO | Remove rolled back version file: state=absent path={{ ansistrano_releases_path.stdout }}/{{ ansistrano_current_release_version.stdout }} when: ansistrano_remove_rolled_back diff --git a/tasks/empty.yml b/tasks/empty.yml index e69de29..ca79f30 100644 --- a/tasks/empty.yml +++ b/tasks/empty.yml @@ -0,0 +1,2 @@ +# This file is intentionally left empty and it is used in those Capistrano flow steps +# where you don't need to execute any custom tasks \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index e4f90fa..1b6b110 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -3,6 +3,10 @@ fail: msg="ansistrano_custom_tasks_path is not used anymore. Please, check the documentation at https://github.com/ansistrano/deploy" when: ansistrano_custom_tasks_path is defined +- include: "{{ ansistrano_before_setup_tasks_file | default('empty.yml') }}" +- include: setup.yml +- include: "{{ ansistrano_after_setup_tasks_file | default('empty.yml') }}" + - include: "{{ ansistrano_before_symlink_tasks_file | default('empty.yml') }}" - include: symlink.yml - include: "{{ ansistrano_after_symlink_tasks_file | default('empty.yml') }}" diff --git a/tasks/setup.yml b/tasks/setup.yml new file mode 100644 index 0000000..a427d68 --- /dev/null +++ b/tasks/setup.yml @@ -0,0 +1,20 @@ +--- +- name: ANSISTRANO | Get releases path + command: echo "{{ ansistrano_deploy_to }}/{{ ansistrano_version_dir }}" + register: ansistrano_releases_path + +- name: ANSISTRANO | Get number of releases + shell: echo `ls {{ ansistrano_releases_path.stdout }} -1t | wc -l` + register: ansistrano_versions_count + +- name: ANSISTRANO | Check if there is more than one release + fail: msg="Could not roll back the code because there is no prior release" + when: ansistrano_versions_count.stdout|int <= 1 + +- name: ANSISTRANO | Get current release version + shell: echo `ls {{ ansistrano_releases_path.stdout }} -1t | head -n 1` + register: ansistrano_current_release_version + +- name: ANSISTRANO | Get previous releases version + shell: echo `ls {{ ansistrano_releases_path.stdout }} -1t | head -n 2 | tail -n 1` + register: ansistrano_previous_release_version diff --git a/tasks/symlink.yml b/tasks/symlink.yml index 997d526..d0542a6 100644 --- a/tasks/symlink.yml +++ b/tasks/symlink.yml @@ -1,22 +1,3 @@ -- name: ANSISTRANO | Get releases path - command: echo "{{ ansistrano_deploy_to }}/{{ ansistrano_version_dir }}" - register: ansistrano_releases_path - -- name: ANSISTRANO | Get number of releases - shell: echo `ls {{ ansistrano_releases_path.stdout }} -1t | wc -l` - register: ansistrano_versions_count - -- name: ANSISTRANO | Check if there is more than one release - fail: msg="Could not roll back the code because there is no prior release" - when: ansistrano_versions_count.stdout|int <= 1 - -- name: ANSISTRANO | Get current release version - shell: echo `ls {{ ansistrano_releases_path.stdout }} -1t | head -n 1` - register: ansistrano_current_release_version - -- name: ANSISTRANO | Get previous releases version - shell: echo `ls {{ ansistrano_releases_path.stdout }} -1t | head -n 2 | tail -n 1` - register: ansistrano_previous_release_version - +--- - name: ANSISTRANO | Change web softlink from current release to previous one file: state=link path={{ ansistrano_deploy_to }}/{{ ansistrano_current_dir }} src={{ ansistrano_releases_path.stdout }}/{{ ansistrano_previous_release_version.stdout }}