-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michal Wojtowicz
committed
Dec 24, 2017
0 parents
commit dfeb0bb
Showing
4 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Ansible Role: Deployment | ||
|
||
An Ansible role that deploy your application just the same way like Capistrano. | ||
|
||
## What means _Capistrano way_? | ||
|
||
Capistrano is software written in Ruby, which allows you to deploy your application on remote node. | ||
Here is how it works: | ||
|
||
1. On remote node you should have in project workdir directories `/shared`, `/repository` and `/deployments`. | ||
2. In `/repository` directory there is a copy of your source repo (GIT/SVN etc.) | ||
3. When you do deploy, capistrano copies repository directory into `/deployments` dir. | ||
Name of copied directory is different - it's always current timestamp (like `/deployments/20171108123453`). | ||
4. Next step is to make symlinks of all directories/files from `/shared` directory into the new deployment directory. | ||
It allows you to share upload dir or logs directory between deployments. | ||
5. Last step is to create or change symlink `/current` to point to the latest deployment from `/deployments` | ||
|
||
## Requirements | ||
|
||
There aren't any requirements for this role. | ||
|
||
## Role variables | ||
|
||
Available variables are listed below, along with default values (see `defaults/main.yml`). | ||
|
||
##### Workdir for the role. Inside there will be deployed all applications. It can be also customised per project. | ||
|
||
deployment_default_workdir: "" | ||
|
||
##### Project owner and group. It can be also customised per project. | ||
|
||
deployment_default_owner: "" | ||
deployment_default_group: "" | ||
|
||
##### Project deployments data | ||
|
||
deployment_projects: [] | ||
|
||
##### Example of project deployed with almost all defaults | ||
deployment_projects: [] | ||
- name: project.name | ||
repository: [email protected]:some/repo | ||
|
||
##### Example of project deployed with all options customized | ||
deployment_projects: [] | ||
- name: project.name | ||
workdir: /var/www | ||
repository: [email protected]:some/repo | ||
version: "HEAD" | ||
owner: apache | ||
group: apache | ||
shared_files: | ||
- any/path/to/mount/in/dir/deployment/dir | ||
ssh_opts: "" | ||
|
||
## Dependencies | ||
|
||
None. | ||
|
||
## Example Playbook | ||
|
||
- hosts: webservers | ||
vars_files: | ||
- vars/main.yml | ||
roles: | ||
- { role: MWojtowicz.deployment } | ||
## License | ||
|
||
MIT / BSD | ||
|
||
## Author Information | ||
|
||
This role was created in 2017 by [Michal Wojtowicz](https://mwojtowicz.it/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
deployment_default_workdir: "" | ||
|
||
deployment_default_owner: "" | ||
deployment_default_group: "" | ||
|
||
deployment_projects: [] | ||
# - name: project.name | ||
# workdir: /var/www | ||
# repository: [email protected]:some/repo | ||
# version: "HEAD" | ||
# owner: apache | ||
# group: apache | ||
# shared_files: | ||
# - any/path/to/mount/in/dir/deployment/dir | ||
# ssh_opts: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
galaxy_info: | ||
author: Michał Wójtowicz <[email protected]> | ||
description: An Ansible role that deploy your application just the same way like Capistrano | ||
company: mwojtowicz.it | ||
|
||
license: MIT | ||
|
||
min_ansible_version: 2.4 | ||
|
||
github_branch: master | ||
|
||
galaxy_tags: | ||
- deployment | ||
- apache | ||
- capistrano | ||
|
||
platforms: | ||
- name: EL | ||
versions: | ||
- all | ||
- name: Debian | ||
versions: | ||
- all | ||
- name: Ubuntu | ||
versions: | ||
- all | ||
- name: Amazon | ||
versions: | ||
- all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
- name: "Ensure deployment workdir exists" | ||
file: | ||
path: "{{ item.workdir|default(deployment_default_workdir) }}" | ||
state: directory | ||
owner: "{{ item.owner|default(deployment_default_owner) }}" | ||
group: "{{ item.group|default(deployment_default_group) }}" | ||
with_items: "{{ deployment_projects }}" | ||
|
||
- name: "Create deployments directory" | ||
file: | ||
path: "{{ item.workdir|default(deployment_default_workdir) }}/{{ item.name }}/deployments" | ||
state: directory | ||
owner: "{{ item.owner|default(deployment_default_owner) }}" | ||
group: "{{ item.group|default(deployment_default_group) }}" | ||
with_items: "{{ deployment_projects }}" | ||
|
||
- name: "Create shared directory" | ||
file: | ||
path: "{{ item.workdir|default(deployment_default_workdir) }}/{{ item.name }}/shared" | ||
state: directory | ||
owner: "{{ item.owner|default(deployment_default_owner) }}" | ||
group: "{{ item.group|default(deployment_default_group) }}" | ||
with_items: "{{ deployment_projects }}" | ||
|
||
- name: "Clone git repository" | ||
git: | ||
repo: "{{ item.repository }}" | ||
dest: "{{ item.workdir|default(deployment_default_workdir) }}/{{ item.name }}/repository" | ||
force: yes | ||
ssh_opts: "{{ item.ssh_opts|default('') }}" | ||
version: "{{ item.version|default('HEAD') }}" | ||
with_items: "{{ deployment_projects }}" | ||
|
||
- name: "Register deployment timestamp" | ||
set_fact: | ||
deploymentDate: "{{lookup('pipe','date +%Y%m%d%H%M%S')}}" | ||
|
||
- name: "Create deployment" | ||
command: > | ||
/bin/cp -r | ||
{{ item.workdir|default(deployment_default_workdir) }}/{{ item.name }}/repository | ||
{{ item.workdir|default(deployment_default_workdir) }}/{{ item.name }}/deployments/{{ deploymentDate }} | ||
with_items: "{{ deployment_projects }}" | ||
|
||
- name: "Remove git tracking from deployment" | ||
command: > | ||
rm -rf {{ item.workdir|default(deployment_default_workdir) }}/{{ item.name }}/deployments/{{ deploymentDate }}/.git | ||
with_items: "{{ deployment_projects }}" | ||
|
||
- name: "Create symlinks to shared files & directories" | ||
file: | ||
src: "{{ item.0.workdir|default(deployment_default_workdir) }}/{{ item.0.name }}/shared/{{ item.1 }}" | ||
dest: "{{ item.0.workdir|default(deployment_default_workdir) }}/{{ item.0.name }}/deployments/{{ deploymentDate }}/{{ item.1 }}" | ||
state: link | ||
force: yes | ||
owner: "{{ item.0.owner|default(deployment_default_owner) }}" | ||
group: "{{ item.0.group|default(deployment_default_group) }}" | ||
with_subelements: | ||
- "{{ deployment_projects }}" | ||
- shared_files | ||
|
||
- name: "Current deployment symlink" | ||
file: | ||
src: "{{ item.workdir|default(deployment_default_workdir) }}/{{ item.name }}/deployments/{{ deploymentDate }}" | ||
dest: "{{ item.workdir|default(deployment_default_workdir) }}/{{ item.name }}/current" | ||
state: link | ||
owner: "{{ item.owner|default(deployment_default_owner) }}" | ||
group: "{{ item.group|default(deployment_default_group) }}" | ||
with_items: "{{ deployment_projects }}" |