Ansistrano (Ansible + Capistrano): Quick Start
In this post, I am going to try Ansistrano to deploy a file on a web server.
(See this post this post for detail about Ansible)
what is Ansistrano?
"ansistrano.deploy and ansistrano.rollback are Ansible roles to easily manage the deployment process for scripting applications such as PHP, Python and Ruby. It's an Ansible port for Capistrano." (https://github.com/ansistrano/deploy)
install
% ansible-galaxy install ansistrano.deploy ansistrano.rollback
create test file
% mkdir -p public_html
% echo 'hello' > public_html/index.html
deploy
% vim playbook.yml
---
- name: deploy code
hosts: webservers
become: true
vars:
ansistrano_deploy_from: "{{ playbook_dir }}/public_html/"
ansistrano_deploy_to: "/var/www/my-app"
ansistrano_keep_releases: 3
ansistrano_deploy_via: "rsync"
roles:
- ansistrano.deploy
See https://github.com/ansistrano/deploy for the vars to customize as needed.
Run the playbook.
% ansible-playbook playbook.yml
On the server side, the directories and files are created in Capistorano way.
$ tree /var/www/my-app/
/var/www/my-app/
|-- current -> ./releases/20210531110928Z
|-- releases
| `-- 20210531110928Z
| |-- index.html
| `-- REVISION
`-- shared
If you run it again, you can see the new directory is created under releases and the simlink has been redirected.
% ansible-playbook playbook.yml
$ tree /var/www/my-app/
/var/www/my-app/
|-- current -> ./releases/20210531111245Z
|-- releases
| |-- 20210531110928Z
| | |-- index.html
| | `-- REVISION
| `-- 20210531111245Z
| |-- index.html
| `-- REVISION
`-- shared
rollback
% vim rollback.yml
---- name: rollback deploymenthosts: webserversbecome: truevars:ansistrano_deploy_to: "/var/www/my-app"roles:- ansistrano.rollback
% ansible-playbook rollback.yml
$ tree /var/www/my-app//var/www/my-app/
|-- current -> ./releases/20210531110928Z
|-- releases
| `-- 20210531110928Z
| |-- index.html
| `-- REVISION
`-- shared
Comments
Post a Comment