Skip to content

Commit 989ca76

Browse files
authored
Merge pull request #15 from rev112/rollback-to-version
Rollback to specific release version
2 parents ff92fd3 + c548026 commit 989ca76

File tree

6 files changed

+26
-21
lines changed

6 files changed

+26
-21
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ dist: trusty
44

55
matrix:
66
include:
7-
- env: ANSIBLE_VERSION=1.8.4
87
- env: ANSIBLE_VERSION=1.9.5
9-
- env: ANSIBLE_VERSION=2.1.0
8+
- env: ANSIBLE_VERSION=2.1.2
9+
- env: ANSIBLE_VERSION=2.2.1
1010

1111
before_install:
1212
- sudo apt-get -y install software-properties-common
@@ -24,4 +24,4 @@ script:
2424
- ansible-playbook -i inventory --connection=local --sudo -v test/test.yml
2525

2626
notifications:
27-
webhooks: https://galaxy.ansible.com/api/v1/notifications/
27+
webhooks: https://galaxy.ansible.com/api/v1/notifications/

README.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ Role Variables
104104
ansistrano_deploy_to: "/var/www/my-app" # Base path to deploy to.
105105
ansistrano_version_dir: "releases" # Releases folder name
106106
ansistrano_current_dir: "current" # Softlink name. You should rarely changed it.
107+
ansistrano_rollback_to_release: "" # If specified, the application will be rolled back to this release version; previous release otherwise.
107108
ansistrano_remove_rolled_back: yes # You can change this setting in order to keep the rolled back release in the server for later inspection
108109
ansistrano_allow_anonymous_stats: yes
109110

@@ -167,20 +168,7 @@ In order to rollback with Ansistrano, you need to set up the deployment and run
167168
168169
If you try to roll back with zero or one releases deployed, an error will be raised and no actions performed.
169170
170-
Variables you can tune in rollback role are less than in deploy one:
171-
172-
```yaml
173-
- vars:
174-
ansistrano_deploy_to: "/var/www/my-app" # Base path to deploy to.
175-
ansistrano_version_dir: "releases" # Releases folder name
176-
ansistrano_current_dir: "current" # Softlink name. You should rarely changed it.
177-
178-
# Hooks: custom tasks if you need them
179-
ansistrano_before_symlink_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-before-symlink-tasks.yml"
180-
ansistrano_after_symlink_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-after-symlink-tasks.yml"
181-
ansistrano_before_cleanup_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-before-cleanup-tasks.yml"
182-
ansistrano_after_cleanup_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-after-cleanup-tasks.yml"
183-
```
171+
Variables you can tune in rollback role are less than in deploy one, see [Role variables](#role-variables).
184172
185173
Multistage environment (devel, preprod, prod, etc.)
186174
---------------------------------------------------

defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ ansistrano_current_dir: "current"
1111
# Remove rolled back release?
1212
ansistrano_remove_rolled_back: yes
1313

14+
# Rollback to this release version (previous by default)
15+
ansistrano_rollback_to_release: ""
16+
1417
# Sends anonymous stats to the www.ansistrano.com servers
1518
# You can disallow it by just setting this parameter to "no" in your playbook
1619
ansistrano_allow_anonymous_stats: yes

meta/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
galaxy_info:
33
author: ansistrano
4-
description: Ansible role to roll back scripting applications like PHP, Python, Ruby, etc. in a Capistrano style
4+
description: Ansible role to rollback scripting applications like PHP, Python, Ruby, etc. in a Capistrano style
55
company: Ansistrano
66
license: MIT
7-
min_ansible_version: 1.6
7+
min_ansible_version: 1.9
88
platforms:
99
- name: EL
1010
versions:

tasks/setup.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,24 @@
1616
shell: echo `ls -1t {{ ansistrano_releases_path.stdout }} | head -n 1`
1717
register: ansistrano_current_release_version
1818

19+
- stat:
20+
path: "{{ ansistrano_releases_path.stdout }}/{{ ansistrano_rollback_to_release }}"
21+
register: stat_rollback_release_version
22+
when: ansistrano_rollback_to_release != ""
23+
24+
- name: ANSISTRANO | Check that the provided rollback release exists
25+
fail:
26+
msg: "Specified rollback version does not exist"
27+
when: ansistrano_rollback_to_release != "" and (stat_rollback_release_version.stat.exists is not defined or stat_rollback_release_version.stat.isdir == False)
28+
1929
- name: ANSISTRANO | Get previous releases version
2030
shell: echo `ls -1t {{ ansistrano_releases_path.stdout }} | head -n 2 | tail -n 1`
2131
register: ansistrano_previous_release_version
2232

33+
- name: ANSISTRANO | Get rollback release version
34+
set_fact:
35+
ansistrano_rollback_release_version: "{{ ansistrano_rollback_to_release if ansistrano_rollback_to_release != '' else ansistrano_previous_release_version.stdout }}"
36+
2337
- name: ANSISTRANO | Get release path
24-
command: echo "{{ ansistrano_releases_path.stdout }}/{{ ansistrano_previous_release_version.stdout }}"
38+
command: echo "{{ ansistrano_releases_path.stdout }}/{{ ansistrano_rollback_release_version }}"
2539
register: ansistrano_release_path

tasks/symlink.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
file:
44
state: link
55
path: "{{ ansistrano_deploy_to }}/{{ ansistrano_current_dir }}"
6-
src: "./{{ ansistrano_version_dir }}/{{ ansistrano_previous_release_version.stdout }}"
6+
src: "./{{ ansistrano_version_dir }}/{{ ansistrano_rollback_release_version }}"

0 commit comments

Comments
 (0)