Skip to content

Commit

Permalink
Merge pull request #7 from ansistrano/setup_step
Browse files Browse the repository at this point in the history
add a setup step
  • Loading branch information
ricardclau committed Nov 30, 2015
2 parents 3ed410d + fb55b4d commit bd422d8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
1 change: 1 addition & 0 deletions tasks/cleanup.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions tasks/empty.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}"
Expand Down
20 changes: 20 additions & 0 deletions tasks/setup.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 1 addition & 20 deletions tasks/symlink.yml
Original file line number Diff line number Diff line change
@@ -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 }}

0 comments on commit bd422d8

Please sign in to comment.