diff --git a/isoft.ansistrano/LICENSE b/isoft.ansistrano/LICENSE new file mode 100644 index 0000000..3e76097 --- /dev/null +++ b/isoft.ansistrano/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Carlos Buenosvinos + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/isoft.ansistrano/README.md b/isoft.ansistrano/README.md new file mode 100644 index 0000000..fb6a058 --- /dev/null +++ b/isoft.ansistrano/README.md @@ -0,0 +1,354 @@ +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. + +History +------- + +[Capistrano](http://capistranorb.com/) is a remote server automation tool and it's currently in Version 3. [Version 2.0](https://github.com/capistrano/capistrano/tree/legacy-v2) was originally thought in order to deploy RoR applications. With additional plugins, you were able to deploy non Rails applications such as PHP and Python, with different deployment strategies, stages and much more. I loved Capistrano v2. I have used it a lot. I developed a plugin for it. + +Capistrano 2 was a great tool and it still works really well. However, it is not maintained anymore since the original team is working in v3. This new version does not have the same set of features so it is less powerful and flexible. Besides that, other new tools are becoming easier to use in order to deploy applications, such as Ansible. + +So, I have decided to stop using Capistrano because v2 is not maintained, v3 does not have enough features, and I can do everything Capistrano was doing with Ansible. If you are looking for alternatives, check Fabric or Chef Solo. + +Project name +------------ + +Ansistrano comes from Ansible + Capistrano, easy, isn't it? + +Early adopters +-------------- + +If you were an early adopter, you should know we have broken BC by moving from using `ansistrano_custom_tasks_path` to individual and specific files per step. See "Role Variables". **The role displays a warning if the variable is defined and although your old playbooks may still run with no errors, you will see that your code is uploaded but custom tasks are not run.** + +Who is using Ansistrano? +------------------------ + +Is Ansistrano ready to be used? Here are some companies currently using it: + +* AtrĂ¡palo: https://github.com/atrapalo (9K global alexa ranking) +* Another Place Productions: http://www.anotherplaceproductions.com + +If you are also using it, please let us know via a PR to this document. + +Requirements +------------ + +In order to deploy your apps with Ansistrano, you will need: + +* Ansible in your deployer machine + +Installation +------------ + +Ansistrano is an Ansible role distributed globally using [Ansible Galaxy](https://galaxy.ansible.com/). In order to install Ansistrano role you can use the following command. + +``` +$ ansible-galaxy install carlosbuenosvinos.ansistrano-deploy carlosbuenosvinos.ansistrano-rollback +``` + +Update +------ + +If you want to update the role, you need to pass **--force** parameter when installing. Please, check the following command: + +``` +$ ansible-galaxy install --force carlosbuenosvinos.ansistrano-deploy carlosbuenosvinos.ansistrano-rollback +``` + +Features +-------- + +* Rollback in seconds (with ansistrano.rollback role) +* Customize your deployment with hooks before and after critical steps +* Save disk space keeping a maximum fixed releases in your hosts +* Choose between SCP (push), RSYNC (push) or GIT (pull) deployment strategies + +Main workflow +------------- + +Ansistrano deploys applications following the Capistrano flow. + +* Setup phase: Creates the folder structure to hold your releases +* Code update phase: Puts the new release into your hosts +* Symlink phase: After deploying the new release into your hosts, this step changes the `current` softlink to new the release +* Cleanup phase: Removes any old version based in the `ansistrano_keep_releases` parameter (see "Role Variables") + +![Ansistrano Flow](https://raw.githubusercontent.com/ansistrano/deploy/master/docs/ansistrano-flow.png) + +Role Variables +-------------- + +```yaml +- vars: + ansistrano_deploy_from: "./" # Where my local project is + ansistrano_deploy_to: "/var/www/my-app" # Base path to deploy to. + ansistrano_version_dir: "releases" # Releases folder name + ansistrano_current_dir: "current" # Softlink name. You should rarely changed it. + ansistrano_shared_paths: [] # Shared paths to symlink to release dir + ansistrano_keep_releases: 0 # Releases to keep after a new deployment. See "Pruning old releases". + ansistrano_deploy_via: "rsync" # Method used to deliver the code to the server. Options are copy, rsync or git + ansistrano_rsync_extra_params: "" # Extra parameters to use when deploying with rsync + ansistrano_git_repo: git@github.com:USERNAME/REPO.git # Location of the git repository + ansistrano_git_branch: master # Branch to use when deploying + + # Hooks: custom tasks if you need them + ansistrano_before_setup_tasks_file: "{{ playbook_dir }}//my-before-setup-tasks.yml" + ansistrano_after_setup_tasks_file: "{{ playbook_dir }}//my-after-setup-tasks.yml" + ansistrano_before_update_code_tasks_file: "{{ playbook_dir }}//my-before-update-code-tasks.yml" + ansistrano_after_update_code_tasks_file: "{{ playbook_dir }}//my-after-update-code-tasks.yml" + ansistrano_before_symlink_tasks_file: "{{ playbook_dir }}//my-before-symlink-tasks.yml" + ansistrano_after_symlink_tasks_file: "{{ playbook_dir }}//my-after-symlink-tasks.yml" + ansistrano_before_cleanup_tasks_file: "{{ playbook_dir }}//my-before-cleanup-tasks.yml" + ansistrano_after_cleanup_tasks_file: "{{ playbook_dir }}//my-after-cleanup-tasks.yml" +``` + +`{{ playbook_dir }}` is an Ansible variable that holds the path to the current playbook. + +Deploying +--------- + +In order to deploy with Ansistrano, you need to perform some steps: + +* Create a new `hosts` file. Check [ansible inventory documentation](http://docs.ansible.com/intro_inventory.html) if you need help. This file will identify all the hosts where to deploy to. For multistage environments check "Multistage environments" +* Create a new playbook for deploying your app, for example, deploy.yml +* Include carlosbuenosvinos.ansible-deploy role +* Set up role variables (see "Role Variables") +* Run the deployment playbook + +```ansible-playbook -i hosts deploy.yml``` + +If everything has been set up properly, this command will create the following approximate directory structure on your server. Check how the hosts folder structure would look like after one, two and three deployments. + +``` +-- /var/www/my-app.com +|-- current -> /var/www/my-app.com/releases/20100509145325 +|-- releases +| |-- 20100509145325 +|-- shared +``` + +``` +-- /var/www/my-app.com +|-- current -> /var/www/my-app.com/releases/20100509150741 +|-- releases +| |-- 20100509150741 +| |-- 20100509145325 +|-- shared +``` + +``` +-- /var/www/my-app.com +|-- current -> /var/www/my-app.com/releases/20100512131539 +|-- releases +| |-- 20100512131539 +| |-- 20100509150741 +| |-- 20100509145325 +|-- shared +``` + +Rollbacking +----------- + +In order to rollback with Ansistrano, you need to set up the deployment and run the rollback playbook. + +```ansible-playbook -i hosts rollback.yml``` + +If you try to rollback with zero or one releases deployed, an error will be raised and no actions performed. + +Variables you can tune in rollback role are less than in deploy one: + +```yaml +- vars: + ansistrano_deploy_to: "/var/www/my-app" # Base path to deploy to. + ansistrano_version_dir: "releases" # Releases folder name + ansistrano_current_dir: "current" # Softlink name. You should rarely changed it. + + # Hooks: custom tasks if you need them + ansistrano_before_symlink_tasks_file: "{{ playbook_dir }}//my-before-symlink-tasks.yml" + ansistrano_after_symlink_tasks_file: "{{ playbook_dir }}//my-after-symlink-tasks.yml" + ansistrano_before_cleanup_tasks_file: "{{ playbook_dir }}//my-before-cleanup-tasks.yml" + ansistrano_after_cleanup_tasks_file: "{{ playbook_dir }}//my-after-cleanup-tasks.yml" +``` + +Multistage environment (devel, preprod, prod, etc.) +--------------------------------------------------- + +If you want to deploy to different environments such as devel, preprod and prod, it's recommended to create different hosts files. When done, you can specify a different host file when running the deployment playbook using the **-i** parameter. On every host file, you can specify different users, password, connection parameters, etc. + +```ansible-playbook -i hosts_devel deploy.yml``` + +```ansible-playbook -i hosts_preprod deploy.yml``` + +```ansible-playbook -i hosts_prod deploy.yml``` + +Hooks: Custom tasks +------------------- + +You will typically need to reload your webserver after the `Symlink` step, or download your dependencies before `Code update` or even do it in production before the `Symlink`. So, in order to perform your custom tasks you have some hooks that Ansistrano will execute before and after each of the main 3 steps. **This is the main benefit against other similar deployment roles.** + +``` +-- /my-local-machine/my-app.com +|-- hosts +|-- deploy.yml +|-- my-custom-tasks +| |-- before-code-update.yml +| |-- after-code-update.yml +| |-- before-symlink.yml +| |-- after-symlink.yml +| |-- before-cleanup.yml +| |-- after-cleanup.yml +``` + +For example, in order to restart apache after `Symlink` step, we'll add in the `after-symlink.yml` + +``` +- name: Restart Apache + service: name=httpd state=reloaded +``` + +* **Q: Where would you add sending email notification after a deployment?** +* **Q: (for PHP and Symfony developers) Where would you clean the cache?** + +You can specify a custom tasks file for before and after every step using `ansistrano_before_*_tasks_file` and `ansistrano_after_*_tasks_file` role variables. See "Role Variables" for more information. + +Variables in custom tasks +------------------------- + +When writing your custom tasks files you may need some variables that Ansistrano makes available to you: + +* ```{{ ansistrano_timestamp.stdout }}```: Timestamp for the current deployment +* ```{{ ansistrano_release_path.stdout }}```: Path to current deployment release (probably the one you are going to use the most) +* ```{{ ansistrano_releases_path.stdout }}```: Path to releases folder +* ```{{ ansistrano_shared_path.stdout }}```: Path to shared folder (where common releases assets can be stored) + +Pruning old releases +-------------------- + +In continuous delivery environments, you will possibly have a high number of releases in production. Maybe you have tons of space and you don't mind, but it's common practice to keep just a custom number of releases. + +After the deployment, if you want to remove old releases just set the `ansistrano_keep_releases` variable to the total number of releases you want to keep. + +Let's see three deployments with an `ansistrano_keep_releases: 2` configuration: + +``` +-- /var/www/my-app.com +|-- current -> /var/www/my-app.com/releases/20100509145325 +|-- releases +| |-- 20100509145325 +|-- shared +``` + +``` +-- /var/www/my-app.com +|-- current -> /var/www/my-app.com/releases/20100509150741 +|-- releases +| |-- 20100509150741 +| |-- 20100509145325 +|-- shared +``` + +``` +-- /var/www/my-app.com +|-- current -> /var/www/my-app.com/releases/20100512131539 +|-- releases +| |-- 20100512131539 +| |-- 20100509150741 +|-- shared +``` + +See how the release `20100509145325` has been removed. + +Example Playbook +---------------- + +In the folder, `example` you can check an example project that shows how to deploy with Ansistrano. In order to run it, you should: + +``` +$ cd example +$ ansible-playbook -i hosts deploy.yml +``` + +Sample projects +--------------- + +We have added Ansistrano support for other projects we are working on. + +* LastWishes: Domain-Driven Design PHP Sample App: https://github.com/dddinphp/last-wishes + +As an example, see the execution log of the LastWishes deployment: + +``` +PLAY [Deploy last wishes app to my server] ************************************ + +GATHERING FACTS *************************************************************** +ok: [quepimquepam.com] + +TASK: [carlosbuenosvinos.ansistrano-deploy | Ensure deployment base path exists] *** +ok: [quepimquepam.com] + +TASK: [carlosbuenosvinos.ansistrano-deploy | Ensure releases folder exists] *** +ok: [quepimquepam.com] + +TASK: [carlosbuenosvinos.ansistrano-deploy | Ensure shared elements folder exists] *** +ok: [quepimquepam.com] + +TASK: [carlosbuenosvinos.ansistrano-deploy | Get release timestamp] *********** +changed: [quepimquepam.com] + +TASK: [carlosbuenosvinos.ansistrano-deploy | Get release path] **************** +changed: [quepimquepam.com] + +TASK: [carlosbuenosvinos.ansistrano-deploy | Get releases path] *************** +changed: [quepimquepam.com] + +TASK: [carlosbuenosvinos.ansistrano-deploy | Get shared path (in rsync case)] *** +changed: [quepimquepam.com] + +TASK: [carlosbuenosvinos.ansistrano-deploy | Rsync application files to remote shared copy (in rsync case)] *** +changed: [quepimquepam.com -> 127.0.0.1] + +TASK: [carlosbuenosvinos.ansistrano-deploy | Deploy existing code to servers] *** +changed: [quepimquepam.com] + +TASK: [carlosbuenosvinos.ansistrano-deploy | Deploy existing code to remote servers] *** +skipping: [quepimquepam.com] + +TASK: [carlosbuenosvinos.ansistrano-deploy | Update remote repository] ******** +skipping: [quepimquepam.com] + +TASK: [carlosbuenosvinos.ansistrano-deploy | Export a copy of the repo] ******* +skipping: [quepimquepam.com] + +TASK: [carlosbuenosvinos.ansistrano-deploy | Deploy code from to servers] ***** +skipping: [quepimquepam.com] + +TASK: [carlosbuenosvinos.ansistrano-deploy | Copy release version into REVISION file] *** +changed: [quepimquepam.com] + +TASK: [carlosbuenosvinos.ansistrano-deploy | Touches up the release code] ***** +changed: [quepimquepam.com] + +TASK: [carlosbuenosvinos.ansistrano-deploy | Change softlink to new release] *** +changed: [quepimquepam.com] + +TASK: [carlosbuenosvinos.ansistrano-deploy | Reload Apache] ******************* +changed: [quepimquepam.com] + +TASK: [carlosbuenosvinos.ansistrano-deploy | Clean up releases] *************** +skipping: [quepimquepam.com] + +PLAY RECAP ******************************************************************** +quepimquepam.com : ok=14 changed=10 unreachable=0 failed=0 +``` + +License +------- + +MIT + +Other resources +--------------- + +* [Thoughts on deploying with Ansible](http://www.future500.nl/articles/2014/07/thoughts-on-deploying-with-ansible/) diff --git a/isoft.ansistrano/defaults/main.yml b/isoft.ansistrano/defaults/main.yml new file mode 100644 index 0000000..6b581e6 --- /dev/null +++ b/isoft.ansistrano/defaults/main.yml @@ -0,0 +1,28 @@ +--- +# Path where the code to deploy is +ansistrano_deploy_from: "{{ playbook_dir }}" + +# Path where the code must be deployed to +ansistrano_deploy_to: "/var/www/my-app" + +# Folder name for the releases +ansistrano_version_dir: "releases" + +# Softlink name for the current release +ansistrano_current_dir: "current" + +# Shared paths to symlink to release dir +ansistrano_shared_paths: [] + +# Number of releases to keep in your hosts, if 0, unlimited releases will be kept +ansistrano_keep_releases: 0 + +# Deployment strategies variables +ansistrano_deploy_via: "rsync" + +## GIT pull strategy +ansistrano_git_repo: git@github.com:USERNAME/REPO.git +ansistrano_git_branch: master + +## RSYNC push strategy +ansistrano_rsync_extra_params: "" diff --git a/isoft.ansistrano/docs/ansistrano-flow-sumup.png b/isoft.ansistrano/docs/ansistrano-flow-sumup.png new file mode 100644 index 0000000..eb52b7e Binary files /dev/null and b/isoft.ansistrano/docs/ansistrano-flow-sumup.png differ diff --git a/isoft.ansistrano/docs/ansistrano-flow.png b/isoft.ansistrano/docs/ansistrano-flow.png new file mode 100644 index 0000000..e2d5476 Binary files /dev/null and b/isoft.ansistrano/docs/ansistrano-flow.png differ diff --git a/isoft.ansistrano/docs/figure.md b/isoft.ansistrano/docs/figure.md new file mode 100644 index 0000000..fa9abbf --- /dev/null +++ b/isoft.ansistrano/docs/figure.md @@ -0,0 +1 @@ +http://yuml.me/edit/f85f1ffd diff --git a/isoft.ansistrano/example/my-app/config/deploy/tasks/after-symlink.yml b/isoft.ansistrano/example/my-app/config/deploy/tasks/after-symlink.yml new file mode 100644 index 0000000..370b621 --- /dev/null +++ b/isoft.ansistrano/example/my-app/config/deploy/tasks/after-symlink.yml @@ -0,0 +1 @@ +- service: name=httpd state=reloaded diff --git a/isoft.ansistrano/example/my-app/deploy.yml b/isoft.ansistrano/example/my-app/deploy.yml new file mode 100644 index 0000000..a70846b --- /dev/null +++ b/isoft.ansistrano/example/my-app/deploy.yml @@ -0,0 +1,10 @@ +--- +- name: Deploy example app to my-server.com + hosts: all + vars: + ansistrano_deploy_from: "./" + ansistrano_deploy_to: "/var/www/my-app.com" + ansistrano_after_symlink_tasks_file: "{{ playbook_dir }}/config/deploy/tasks/after-symlink.yml" + ansistrano_keep_releases: 2 + roles: + - { role: carlosbuenosvinos.ansistrano-deploy } diff --git a/isoft.ansistrano/example/my-app/hosts b/isoft.ansistrano/example/my-app/hosts new file mode 100644 index 0000000..ae3a275 --- /dev/null +++ b/isoft.ansistrano/example/my-app/hosts @@ -0,0 +1 @@ +my-server.com ansible_ssh_user=root diff --git a/isoft.ansistrano/example/my-app/index.html b/isoft.ansistrano/example/my-app/index.html new file mode 100644 index 0000000..1564327 --- /dev/null +++ b/isoft.ansistrano/example/my-app/index.html @@ -0,0 +1 @@ +This is the main file of the project, I know it's not too much, but it will :) diff --git a/isoft.ansistrano/example/my-app/rollback.yml b/isoft.ansistrano/example/my-app/rollback.yml new file mode 100644 index 0000000..87f39ea --- /dev/null +++ b/isoft.ansistrano/example/my-app/rollback.yml @@ -0,0 +1,8 @@ +--- +- name: Rollback example app to my-server.com + hosts: all + vars: + ansistrano_deploy_to: "/var/www/my-app.com" + ansistrano_after_symlink_tasks_file: "{{ playbook_dir }}/config/deploy/tasks/after-symlink.yml" + roles: + - { role: carlosbuenosvinos.ansistrano-deploy } diff --git a/isoft.ansistrano/meta/main.yml b/isoft.ansistrano/meta/main.yml new file mode 100644 index 0000000..29d3d2f --- /dev/null +++ b/isoft.ansistrano/meta/main.yml @@ -0,0 +1,45 @@ +--- +galaxy_info: + author: ansistrano + description: Ansible role to deploy scripting applications like PHP, Python, Ruby, etc. in a Capistrano style + company: Ansistrano + license: MIT + min_ansible_version: 1.6 + platforms: + - name: EL + versions: + - all + - name: GenericUNIX + versions: + - all + - name: Fedora + versions: + - all + - name: opensuse + versions: + - all + - name: Amazon + versions: + - all + - name: GenericBSD + versions: + - all + - name: FreeBSD + versions: + - all + - name: Ubuntu + versions: + - all + - name: SLES + versions: + - all + - name: GenericLinux + versions: + - all + - name: Debian + versions: + - all + categories: + - cloud + - web +dependencies: [] diff --git a/isoft.ansistrano/tasks/cleanup.yml b/isoft.ansistrano/tasks/cleanup.yml new file mode 100644 index 0000000..dd14ec9 --- /dev/null +++ b/isoft.ansistrano/tasks/cleanup.yml @@ -0,0 +1,7 @@ +--- +# Clean up releases +- name: ANSISTRANO | Clean up releases + shell: ls -1dt {{ ansistrano_releases_path.stdout }}/* | tail -n +$(({{ ansistrano_keep_releases }} + 1)) | xargs rm -rf + when: ansistrano_keep_releases > 0 + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" diff --git a/isoft.ansistrano/tasks/empty.yml b/isoft.ansistrano/tasks/empty.yml new file mode 100644 index 0000000..ca79f30 --- /dev/null +++ b/isoft.ansistrano/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/isoft.ansistrano/tasks/main.yml b/isoft.ansistrano/tasks/main.yml new file mode 100644 index 0000000..6ab85b1 --- /dev/null +++ b/isoft.ansistrano/tasks/main.yml @@ -0,0 +1,40 @@ +--- +- name: ANSISTRANO | Check BC for early adopters + 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 + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" + +- name: ANSISTRANO | Execute "Before Setup" Tasks + include: "{{ ansistrano_before_setup_tasks_file | default('empty.yml') }}" + +- include: setup.yml + +- name: ANSISTRANO | Execute "After Setup" Tasks + include: "{{ ansistrano_after_setup_tasks_file | default('empty.yml') }}" + +- name: ANSISTRANO | Execute "Before Update Code" Tasks + include: "{{ ansistrano_before_update_code_tasks_file | default('empty.yml') }}" + +- include: update-code.yml + +- name: ANSISTRANO | Execute "After Update Code" Tasks + include: "{{ ansistrano_after_update_code_tasks_file | default('empty.yml') }}" + +- include: symlink_shared.yml + +- name: ANSISTRANO | Execute "Before Symlink" Tasks + include: "{{ ansistrano_before_symlink_tasks_file | default('empty.yml') }}" + +- include: symlink_new_release.yml + +- name: ANSISTRANO | Execute "After Symlink" Tasks + include: "{{ ansistrano_after_symlink_tasks_file | default('empty.yml') }}" + +- name: ANSISTRANO | Execute "Before Cleanup" Tasks + include: "{{ ansistrano_before_cleanup_tasks_file | default('empty.yml') }}" + +- include: cleanup.yml + +- name: ANSISTRANO | Execute "After Cleanup" Tasks + include: "{{ ansistrano_after_cleanup_tasks_file | default('empty.yml') }}" diff --git a/isoft.ansistrano/tasks/setup.yml b/isoft.ansistrano/tasks/setup.yml new file mode 100644 index 0000000..cb906cb --- /dev/null +++ b/isoft.ansistrano/tasks/setup.yml @@ -0,0 +1,16 @@ +--- +# Setup folders +- name: ANSISTRANO | Ensure deployment base path exists + file: state=directory recurse=yes path={{ ansistrano_deploy_to }} + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" + +- name: ANSISTRANO | Ensure releases folder exists + file: state=directory recurse=yes path={{ ansistrano_deploy_to }}/{{ ansistrano_version_dir }} + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" + +- name: ANSISTRANO | Ensure shared elements folder exists + file: state=directory recurse=yes path={{ ansistrano_deploy_to }}/shared + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" diff --git a/isoft.ansistrano/tasks/symlink_new_release.yml b/isoft.ansistrano/tasks/symlink_new_release.yml new file mode 100644 index 0000000..e9f5458 --- /dev/null +++ b/isoft.ansistrano/tasks/symlink_new_release.yml @@ -0,0 +1,5 @@ +# Performs symlink exchange +- name: ANSISTRANO | Change softlink to new release + file: state=link path={{ ansistrano_deploy_to }}/{{ ansistrano_current_dir }} src={{ ansistrano_release_path.stdout }} + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" diff --git a/isoft.ansistrano/tasks/symlink_shared.yml b/isoft.ansistrano/tasks/symlink_shared.yml new file mode 100644 index 0000000..4593be5 --- /dev/null +++ b/isoft.ansistrano/tasks/symlink_shared.yml @@ -0,0 +1,7 @@ +--- +# Symlinks shared paths +- name: ANSISTRANO | Create softlinks for shared paths + file: state=link force=yes path={{ ansistrano_release_path.stdout }}/{{ item }} src={{ ansistrano_deploy_to }}/shared/{{ item }} + with_items: ansistrano_shared_paths + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" \ No newline at end of file diff --git a/isoft.ansistrano/tasks/update-code.yml b/isoft.ansistrano/tasks/update-code.yml new file mode 100644 index 0000000..2b62c12 --- /dev/null +++ b/isoft.ansistrano/tasks/update-code.yml @@ -0,0 +1,53 @@ +--- +# Update code deployment step +- name: ANSISTRANO | Get release timestamp + command: date +%Y%m%d%H%M%S + register: ansistrano_timestamp + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" + +- name: ANSISTRANO | Get release path + command: echo "{{ ansistrano_deploy_to }}/{{ ansistrano_version_dir }}/{{ ansistrano_timestamp.stdout }}" + register: ansistrano_release_path + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" + +- name: ANSISTRANO | Get releases path + command: echo "{{ ansistrano_deploy_to }}/{{ ansistrano_version_dir }}" + register: ansistrano_releases_path + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" + +- name: ANSISTRANO | RSYNC | Deploy using Rsync strategy + include: update-code/rsync.yml + when: ansistrano_deploy_via == 'rsync' + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" + +- name: ANSISTRANO | SCP | Deploy using SCP strategy + include: update-code/copy.yml + when: ansistrano_deploy_via == 'copy' + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" + +- name: ANSISTRANO | GIT | Deploy using Git strategy + include: update-code/git.yml + when: ansistrano_deploy_via == 'git' + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" + +- name: ANSISTRANO | TarGz | Deploy using TarGz strategy + include: update-code/targz.yml + when: ansistrano_deploy_via == 'targz' + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" + +- name: ANSISTRANO | Copy release version into REVISION file + shell: echo {{ ansistrano_timestamp.stdout }} > {{ ansistrano_release_path.stdout }}/REVISION + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" + +- name: ANSISTRANO | Touches up the release code + file: path={{ ansistrano_release_path.stdout }} state=directory recurse=yes mode="g+w" + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" diff --git a/isoft.ansistrano/tasks/update-code/copy.yml b/isoft.ansistrano/tasks/update-code/copy.yml new file mode 100644 index 0000000..8c14121 --- /dev/null +++ b/isoft.ansistrano/tasks/update-code/copy.yml @@ -0,0 +1,5 @@ +--- +- name: ANSISTRANO | SCP | Deploy existing code to remote servers + copy: src={{ ansistrano_deploy_from }} dest={{ ansistrano_release_path.stdout }} + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" diff --git a/isoft.ansistrano/tasks/update-code/git.yml b/isoft.ansistrano/tasks/update-code/git.yml new file mode 100644 index 0000000..31b90ed --- /dev/null +++ b/isoft.ansistrano/tasks/update-code/git.yml @@ -0,0 +1,17 @@ +--- +- name: ANSISTRANO | GIT | Update remote repository + git: repo={{ ansistrano_git_repo }} dest={{ ansistrano_deploy_to }}/shared version={{ ansistrano_git_branch }} accept_hostkey=true update=yes + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" + +- name: ANSISTRANO | GIT | Export a copy of the repo + command: git checkout-index -f -a --prefix="{{ ansistrano_release_path.stdout }}/" + args: + chdir: "{{ ansistrano_deploy_to }}/shared" + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" + +- name: ANSISTRANO | GIT | Deploy git stored code to servers + git: repo={{ ansistrano_deploy_from }} dest={{ ansistrano_release_path.stdout }} accept_hostkey=true + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" diff --git a/isoft.ansistrano/tasks/update-code/rsync.yml b/isoft.ansistrano/tasks/update-code/rsync.yml new file mode 100644 index 0000000..ed5073c --- /dev/null +++ b/isoft.ansistrano/tasks/update-code/rsync.yml @@ -0,0 +1,16 @@ +--- +- name: ANSISTRANO | RSYNC | Get shared path (in rsync case) + command: echo "{{ ansistrano_deploy_to }}/shared/.shared-copy" + register: ansistrano_shared_path + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" + +- name: ANSISTRANO | RSYNC | Rsync application files to remote shared copy + synchronize: src={{ ansistrano_deploy_from }} dest={{ ansistrano_shared_path.stdout }} recursive=yes delete=yes archive=yes compress=yes rsync_opts={{ ansistrano_rsync_extra_params }} + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" + +- name: ANSISTRANO | RSYNC | Deploy existing code to servers + command: cp -pr {{ ansistrano_shared_path.stdout }} {{ ansistrano_release_path.stdout }} + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" diff --git a/isoft.ansistrano/tasks/update-code/targz.yml b/isoft.ansistrano/tasks/update-code/targz.yml new file mode 100644 index 0000000..14aebb6 --- /dev/null +++ b/isoft.ansistrano/tasks/update-code/targz.yml @@ -0,0 +1,10 @@ +--- +- name: Creates release directory + file: path={{ ansistrano_release_path.stdout }} state=directory + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}" + +- name: ANSISTRANO | TarGz | Deploy existing code to remote servers + unarchive: src={{ ansistrano_deploy_from }} dest={{ ansistrano_release_path.stdout }} + sudo: yes + sudo_user: "{{ansistrano_deploy_user}}"