GithubHelp home page GithubHelp logo

ansistrano / deploy Goto Github PK

View Code? Open in Web Editor NEW
2.4K 64.0 337.0 598 KB

Ansible role to deploy scripting applications like PHP, Python, Ruby, etc. in a capistrano style

Home Page: https://ansistrano.com

License: MIT License

YAML 100.00%
deployment-strategy ansible ansible-roles deployment capistrano rollback hooks deploy deployer deployments

deploy's Introduction

Ansistrano

Build Status Total Deployments Year Deployments Month Deployments Today Deployments

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 is a remote server automation tool and it's currently in Version 3. Version 2.0 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?

Ansistrano anonymous usage stats

There is an optional step in Ansistrano that sends a HTTP request to our servers. Unfortunately, the metrics we can get from Ansible Galaxy are limited so this is one of the few ways we have to measure how many active users we really have.

We only use this data for usage statistics but anyway, if you are not comfortable with this, you can disable this extra step by setting ansistrano_allow_anonymous_stats to false in your playbooks.

Who is using Ansistrano?

Is Ansistrano ready to be used? Here are some companies currently using it:

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
  • rsync on the target machine if you are using either the rsync, rsync_direct, or git deployment strategy or if you are using ansistrano_current_via = rsync

Installation

Ansistrano is an Ansible role distributed globally using Ansible Galaxy. In order to install Ansistrano role you can use the following command.

$ ansible-galaxy install ansistrano.deploy 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 ansistrano.deploy 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, RSYNC, GIT, SVN, HG, HTTP Download or S3 GET deployment strategies (optional unarchive step included)

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

Role Variables

vars:
  ansistrano_deploy_from: "{{ playbook_dir }}/" # Where my local project is (relative or absolute path)
  ansistrano_deploy_to: "/var/www/my-app" # Base path to deploy to.
  ansistrano_version_dir: "releases" # Releases folder name
  ansistrano_shared_dir: "shared" # Shared folder name
  ansistrano_current_dir: "current" # Softlink name. You should rarely changed it.
  ansistrano_current_via: "symlink" # Deployment strategy who code should be deployed to current path. Options are symlink or rsync
  ansistrano_keep_releases: 0 # Releases to keep after a new deployment. See "Pruning old releases".

  # Arrays of directories and files to be shared.
  # The following arrays of directories and files will be symlinked to the current release directory after the 'update-code' step and its callbacks
  # Notes:
  # * Paths are relative to the shared directory (no starting /)
  # * If your items are in a subdirectory, write the entire path to each shared directory
  #
  # Example:
  # ansistrano_shared_paths:
  #   - path/to/first-dir
  #   - path/next-dir
  # ansistrano_shared_files:
  #   - my-file.txt
  #   - path/to/file.txt
  ansistrano_shared_paths: []
  ansistrano_shared_files: []


  # Shared paths and basedir shared files creation.
  # By default the shared paths directories and base directories for shared files are created automatically if not exists. But in some scenarios those paths could be symlinks to another directories in the filesystem, and the deployment process would fails. With these variables you can disable the involved tasks. If you have two or three shared paths, and don't need creation only for some of them, you always could disable the automatic creation and add a custom task in a hook.
  ansistrano_ensure_shared_paths_exist: yes
  ansistrano_ensure_basedirs_shared_files_exist: yes
  
  # Deployment strategy - method used to deliver code. Options are copy, download, git, rsync, rsync_direct, svn, or s3. 
  ansistrano_deploy_via: rsync 
  # Copy, download and s3 have an optional step to unarchive the downloaded file which can be used by adding _unarchive. 
  # The rsync_direct strategy omits a file copy on the target offering a slight speed increase if you are deploying to shared hosts, are experiancing bad file-performance, or serve static assets from the same host you deploy your app to and rsync many files.
  # You can check all the options inside tasks/update-code folder!
  
  ansistrano_allow_anonymous_stats: yes

  # Variables used in the rsync/rsync_direct deployment strategy
  ansistrano_rsync_extra_params: "" # Extra parameters to use when deploying with rsync in a single string. Although Ansible allows an array this can cause problems if we try to add multiple --include args as it was reported in https://github.com/ansistrano/deploy/commit/e98942dc969d4e620313f00f003a7ea2eab67e86
  ansistrano_rsync_set_remote_user: yes # See [ansible synchronize module](http://docs.ansible.com/ansible/synchronize_module.html). Options are yes, no.
  ansistrano_rsync_path: "" # See [ansible synchronize module](http://docs.ansible.com/ansible/synchronize_module.html). By default is "sudo rsync", it can be overwriten with (example): "sudo -u user rsync".
  ansistrano_rsync_use_ssh_args: no # See [ansible synchronize module](http://docs.ansible.com/ansible/synchronize_module.html). If set yes, use the ssh_args specified in ansible.cfg.

  # Variables used in the Git deployment strategy
  ansistrano_git_repo: [email protected]:USERNAME/REPO.git # Location of the git repository
  ansistrano_git_branch: master # What version of the repository to check out. This can be the full 40-character SHA-1 hash, the literal string HEAD, a branch name, or a tag name
  ansistrano_git_repo_tree: "" # If specified the subtree of the repository to deploy
  ansistrano_git_identity_key_path: "" # If specified this file is copied over and used as the identity key for the git commands, path is relative to the playbook in which it is used
  ansistrano_git_identity_key_remote_path: "" # If specified this file on the remote server is used as the identity key for the git commands, remote path is absolute
  ansistrano_git_identity_key_shred: true # Shred identity key by default but can be overloaded to false if you encounter the following issue (https://github.com/ansistrano/deploy/issues/357)
  # Optional variables, omitted by default
  ansistrano_git_refspec: ADDITIONAL_GIT_REFSPEC # Additional refspec to be used by the 'git' module. Uses the same syntax as the 'git fetch' command.
  ansistrano_git_ssh_opts: "-o StrictHostKeyChecking=no" # Additional ssh options to be used in Git
  ansistrano_git_depth: 1 # Additional history truncated to the specified number or revisions
  ansistrano_git_executable: /opt/local/bin/git # Path to git executable to use. If not supplied, the normal mechanism for resolving binary paths will be used.

  # Variables used in the SVN deployment strategy
  # Please note there was a bug in the subversion module in Ansible 1.8.x series (https://github.com/ansible/ansible-modules-core/issues/370) so it is only supported from Ansible 1.9
  ansistrano_svn_repo: https://svn.company.com/project # Location of the svn repository
  ansistrano_svn_branch: trunk # What branch from the repository to check out.
  ansistrano_svn_revision: HEAD # What revision from the repository to check out.
  ansistrano_svn_username: user # SVN authentication username
  ansistrano_svn_password: Pa$$word # SVN authentication password
  ansistrano_svn_environment: {} # Dict with environment variables for svn tasks (https://docs.ansible.com/ansible/playbooks_environment.html)

  # Variables used in the HG deployment strategy
  ansistrano_hg_repo: https://[email protected]/USERNAME/REPO # Location of the hg repo
  ansistrano_hg_branch: default # Any branch identifier that works with hg -r, so named branch, bookmark, commit hash...

  # Variables used in the download deployment strategy
  ansistrano_get_url: https://github.com/someproject/somearchive.tar.gz
  ansistrano_download_force_basic_auth: false # no default as this is only supported from Ansible 2.0
  ansistrano_download_headers: "" # no default as this is only supported from Ansible 2.0

  # Variables used in the S3 deployment strategy
  ansistrano_s3_bucket: s3bucket
  ansistrano_s3_object: s3object.tgz # Add the _unarchive suffix to the ansistrano_deploy_via if your object is a package (ie: s3_unarchive)
  ansistrano_s3_region: eu-west-1
  ansistrano_s3_rgw: false # must be Ansible >= 2.2. use Ceph RGW for S3 compatible cloud providers
  ansistrano_s3_url: http://rgw.example.com # when use Ceph RGW, set url
  # Optional variables, omitted by default
  ansistrano_s3_aws_access_key: YOUR_AWS_ACCESS_KEY
  ansistrano_s3_aws_secret_key: YOUR_AWS_SECRET_KEY
  ansistrano_s3_ignore_nonexistent_bucket: false
  
  # Variables used in the GCS deployment strategy
  ansistrano_gcs_bucket: gcsbucket
  ansistrano_gcs_object: gcsobject.tgz # Add the _unarchive suffix to the ansistrano_deploy_via if your object is a package (ie: s3_unarchive)
  ansistrano_gcs_region: eu-west-1 # https://cloud.google.com/storage/docs/bucket-locations
  # Optional variables, omitted by default
  ansistrano_gcs_access_key: YOUR_GCS_ACCESS_KEY # navigate to Cloud console > Storage > Settings > Interoperability
  ansistrano_gcs_secret_key: YOUR_GCS_SECRET_KEY

  # Hooks: custom tasks if you need them
  ansistrano_before_setup_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-before-setup-tasks.yml"
  ansistrano_after_setup_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-after-setup-tasks.yml"
  ansistrano_before_update_code_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-before-update-code-tasks.yml"
  ansistrano_after_update_code_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-after-update-code-tasks.yml"
  ansistrano_before_symlink_shared_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-before-symlink-shared-tasks.yml"
  ansistrano_after_symlink_shared_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-after-symlink-shared-tasks.yml"
  ansistrano_before_symlink_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-before-symlink-tasks.yml"
  ansistrano_after_symlink_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-after-symlink-tasks.yml"
  ansistrano_before_cleanup_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-before-cleanup-tasks.yml"
  ansistrano_after_cleanup_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/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 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
  • Set up role variables (see Role Variables)
  • Include the ansistrano.deploy role as part of a play
  • 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

Serial deployments

To prevent different timestamps when deploying to several servers using the serial option, you should set the ansistrano_release_version variable.

ansible-playbook -i hosts -e "ansistrano_release_version=`date -u +%Y%m%d%H%M%SZ`" deploy.yml

Rolling back

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:

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.
  ansistrano_rollback_to_release: "" # If specified, the application will be rolled back to this release version; previous release otherwise.
  ansistrano_remove_rolled_back: yes # You can change this setting in order to keep the rolled back release in the server for later inspection
  ansistrano_allow_anonymous_stats: yes

  # Hooks: custom tasks if you need them
  ansistrano_rollback_before_setup_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-rollback-before-setup-tasks.yml"
  ansistrano_rollback_after_setup_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-rollback-after-setup-tasks.yml"
  ansistrano_rollback_before_symlink_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-rollback-before-symlink-tasks.yml"
  ansistrano_rollback_after_symlink_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-rollback-after-symlink-tasks.yml"
  ansistrano_rollback_before_cleanup_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-rollback-before-cleanup-tasks.yml"
  ansistrano_rollback_after_cleanup_tasks_file: "{{ playbook_dir }}/<your-deployment-config>/my-rollback-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_release_path.stdout }}: Path to current deployment release (probably the one you are going to use the most)
  • {{ ansistrano_releases_path }}: Path to releases folder
  • {{ ansistrano_shared_path }}: Path to shared folder (where common releases assets can be stored)
  • {{ ansistrano_release_version }}: Relative directory name for the release (by default equals to the current timestamp in UTC timezone)

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 a small application with Ansistrano.

In order to run it, you will need to have Vagrant and the ansistrano roles installed. Please check https://www.vagrantup.com for more information about Vagrant and our Installation section.

$ cd example/my-playbook
$ vagrant up
$ ansible-playbook -i hosts deploy.yml

And after running these commands, the index.html located in the my-app folder will be deployed to both vagrant boxes

In order to test the rollback playbook, you will need to run deploy.yml at least twice (so that there is something to rollback to). And once this is done, you only need to run

$ ansible-playbook -i hosts rollback.yml

You can check more advanced examples inside the test folder which are run against Travis-CI

Sample projects

We have added Ansistrano support for other projects we are working on.

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: [ansistrano.deploy | Ensure deployment base path exists] ***
ok: [quepimquepam.com]

TASK: [ansistrano.deploy | Ensure releases folder exists] ***
ok: [quepimquepam.com]

TASK: [ansistrano.deploy | Ensure shared elements folder exists] ***
ok: [quepimquepam.com]

TASK: [ansistrano.deploy | Get release timestamp] ***********
changed: [quepimquepam.com]

TASK: [ansistrano.deploy | Get release path] ****************
changed: [quepimquepam.com]

TASK: [ansistrano.deploy | Get releases path] ***************
changed: [quepimquepam.com]

TASK: [ansistrano.deploy | Get shared path (in rsync case)] ***
changed: [quepimquepam.com]

TASK: [ansistrano.deploy | Rsync application files to remote shared copy (in rsync case)] ***
changed: [quepimquepam.com -> 127.0.0.1]

TASK: [ansistrano.deploy | Deploy existing code to servers] ***
changed: [quepimquepam.com]

TASK: [ansistrano.deploy | Deploy existing code to remote servers] ***
skipping: [quepimquepam.com]

TASK: [ansistrano.deploy | Update remote repository] ********
skipping: [quepimquepam.com]

TASK: [ansistrano.deploy | Export a copy of the repo] *******
skipping: [quepimquepam.com]

TASK: [ansistrano.deploy | Deploy code from to servers] *****
skipping: [quepimquepam.com]

TASK: [ansistrano.deploy | Copy release version into REVISION file] ***
changed: [quepimquepam.com]

TASK: [ansistrano.deploy | Touches up the release code] *****
changed: [quepimquepam.com]

TASK: [ansistrano.deploy | Change softlink to new release] ***
changed: [quepimquepam.com]

TASK: [ansistrano.deploy | Reload Apache] *******************
changed: [quepimquepam.com]

TASK: [ansistrano.deploy | Clean up releases] ***************
skipping: [quepimquepam.com]

PLAY RECAP ********************************************************************
quepimquepam.com           : ok=14   changed=10   unreachable=0    failed=0

They're talking about us

License

MIT

Other resources

deploy's People

Contributors

ajgarlag avatar aurelienlavorel avatar bocharsky-bw avatar cameronlockey avatar carlosbuenosvinos avatar cbrunnkvist avatar christopherdavenport avatar dgsuarez avatar evank avatar ewypych avatar fjros avatar hedii avatar hitsumabushi avatar javierbeaumont avatar jonathansanchez avatar jordicasadevall avatar lordoffreaks avatar lumbendil avatar mangelsnc avatar martinezdelariva avatar maxgalbu avatar mblaschke avatar ricardclau avatar shanedroid avatar shannara avatar syhe avatar tersmitten avatar theunic avatar vkill avatar zahna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deploy's Issues

Ansistrano and git problem

I'm trying to use ansistrano with git repository but ansistrano fails.

The error is like:

failed: [staging.server.com] => {"cmd": "/usr/bin/git ls-remote /vagrant/deploy -h refs/heads/HEAD", "failed": true, "rc": 128}
stderr: fatal: '/vagrant/deploy' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

where the /vagrant/deploy is automatically substituted from the ansistrano_deploy_from = './'.

The responsible command is the last one here (https://github.com/ansistrano/deploy/blob/master/tasks/update-code/git.yml#L10):


---
- 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

- 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"

- name: ANSISTRANO | GIT | Deploy git stored code to servers
  git: repo={{ ansistrano_deploy_from }} dest={{ ansistrano_release_path.stdout }} accept_hostkey=true

Even if I use the full repository path as the value of ansistrano_deploy_from ansistrano will fail complaining about already existing destination path.

Shouldn't the third command be removed? Seems that the second command does the same thing using the updated repository (faster than cloning).

Timestamp improvements

I think that if you deploy to several hosts in parallel, all should have the same release timestamp, so the task that registers the timestamp shoud be delegated to the local host.

But if we do this, when the deployment is launched from hosts in different timezones the generated timestamps can be confusing, so I think the release timestamp should be generated with the UTC timezone.

What do you think about?

mode="g+w" breaks code on some servers in update-code.yml

You are forcing mode="g+w" in the last step of update-code.yml which breaks code on servers that require a umask of 0022. Is this really required? In theory rsync and cp -pr will create the proper permission based on the umask settings on the target server. Perhaps this was added to work around a bad umask setting?

file: path={{ ansistrano_release_path.stdout }} state=directory recurse=yes mode="g+w"

should be:

file: path={{ ansistrano_release_path.stdout }} state=directory recurse=yes

Clone to build directory for push strategies

Hi,

when you use a push strategie like rsync or scp in capistrano it will checkout the project to a .build folder and push this to the deploy target.

At the moment we use the current local files and push them to the deploy target. There is one big drawback on this behaviour. You cant deploy a specific branch.

Is the intended to be like this or is there a way to get the "original" behaviour of capistrano?

Custom task callbacks not take effect.

This is my dir with default custom task location

├── custom-tasks
│   ├── after-cleanup.yml
│   ├── after-code-update.yml
│   ├── after-symlink.yml
│   ├── before-cleanup.yml
│   ├── before-code-update.yml
│   └── before-symlink.yml

any task in these ymls takes no effect.

Is there something wrong with my configuration?

Git error

I get this when i try to test this in local... in this step:

TASK: [carlosbuenosvinos.ansistrano-deploy | ANSISTRANO | GIT | Deploy git stored code to servers] ***

failed: [myapp.local] => {"cmd": "/usr/bin/git clone --origin origin --recursive /srv/www/myapp.local /srv/www/myapp.deploy/releases/20150xxxxxxx", "failed": true, "rc": 128}
stderr: fatal: destination path '/srv/www/myapp.deploy/releases/20150xxxxxx' already exists and is not an empty directory.

msg: fatal: destination path '/srv/www/myapp.deploy/releases/20150xxxxxxxxx' already exists and is not an empty directory.

FATAL: all hosts have already failed -- aborting

broken develop

Hey guys, great job.

master branch is broken atm:

vagrant@vagrant-ubuntu-trusty-64:/vagrant/playbooks/ansistrano/deploy/example/topgear$ ansible-playbook -i hosts deploy.yml
ERROR: Syntax Error while loading YAML script, /vagrant/playbooks/ansistrano/deploy/example/topgear/roles/local-ansistrano/tasks/symlink-shared.yml
Note: The error may actually appear before this position: line 13, column 39

    path: "{{ ansistrano_release_path.stdout }}/{{ item }}"
    src: "{{ item | regex_replace('[^\/]*', '..') }}/../shared/{{ item }}"
                                      ^
We could be wrong, but this one looks like it might be an issue with
missing quotes.  Always quote template expression brackets when they
start a value. For instance:

    with_items:
      - {{ foo }}

Should be written as:

    with_items:
      - "{{ foo }}"

The 1.4.1 works fine, the issue seems to be in symlink-shared.yml,

state:link maybe?

Cheers

Copying & deploying old git commit

We're deploying our code using ansistrano and tasks/update-code/git.yml #ANSISTRANO | GIT | Update remote repository uses a commit hash from 2 days ago.

Is this an ansible git module thing? Any ideas where to look? What other info do you need?

debug output:

ok: [127.0.0.1] => {
    "var": {
        "git_commit": {
            "after": "86cd..", # this commit is 2 days old
            "before": "86cd..", # same exact commit
            "changed": false,
            "invocation": {
                "module_args": "",
                "module_name": "git"
            }
        }
    }
}

Thank you!!

Option to use relative symbolic link

I think an option to use a relative symbolic link would be useful.

I am trying to mount my source code as a volume in docker. Right now my deployment folder looks like this:

/home/deploy/ansistrano/
    releases/
        2015021000/
        2015021100/
        2015021200/
    current -> /home/deploy/ansistrano/releases/2015021200

Mount it with docker like this:

$ docker run -it -v /home/deploy/ansistrano:/srv/myapp my_web_image

The structure in the container is:

/srv/myapp/
    releases/
        2015021000/
        2015021100/
        2015021200/
    current -> /home/deploy/ansistrano/releases/2015021200

But obviously /home/deploy/ansistrano/releases/2015021200 does not exist. But if I was able to deploy using a structure like this:

/home/deploy/ansistrano/
    releases/
        2015021000/
        2015021100/
        2015021200/
    current -> ./releases/2015021200

Then I could make it work.

What do you think?

Tar files before deployment

Right now the hook system provides a way to create a tarball, which can be deployed in order to prevent the overhead of multiple files.

Do you have any thoughts on implementing this as an option in combination with any of the deployment strategies?

I'm willing to pitch in.

Add s3 deployment strategy

I have been thinking about adding the s3 deployment strategy.

The main difference between the git, rsync and copy strategies is that although you would be able to do a recursive ls in S3 it is far more common to generate artifacts (usually as compressed files) in their CI servers.

However, those artifacts could also be deb / rpm packages, so I wonder if it good be good to add an extra variable apart from the s3_bucket and s3_object being like s3_object_type or similar.

Thoughts?

Rollback role missing

Hi, this looks great, but I can't find the rollback role. Is it still published?

Thanks

Redundant "name:" keys for includes only add cruft

Tasks that include: can have a name, but that name acts purely as a comment and is never displayed anywhere by Ansible. You're better of with a (ugh!) real comment if its intent isn't clear enough.

Example:

- name: ANSISTRANO | Execute "After Setup" Tasks
  include: "{{ ansistrano_after_setup_tasks_file | default('empty.yml') }}"

acts identical to:

- include: "{{ ansistrano_after_setup_tasks_file | default('empty.yml') }}"

Fatal error when creating softlink to the new release

Hi. After pr #97 , I think something broke the symlink generation

TASK: [carlosbuenosvinos.ansistrano-deploy | ANSISTRANO | Change softlink to new release] *** 
failed: [stan] => {"failed": true, "gid": 0, "group": "root", "mode": "0755", "owner": "root", "path": "/var/my-deploy-path/current", "size": 4096, "src": "./releases/20160325115923Z", "state": "directory", "uid": 0}
msg: src file does not exist, use "force=yes" if you really want to create the link: /var/my-deploy-path/current/./releases/20160325115923Z

FATAL: all hosts have already failed -- aborting

looks like it is trying to create the current symlink starting from path /var/my-deploy-path/current instead of /var/my-deploy-path.

Vars in my setup is the following:

    ansistrano_deploy_to: /var/my-deploy-path
    ansistrano_keep_releases: 5
    ansistrano_deploy_via: git
    ansistrano_git_repo: [email protected]
    ansistrano_git_branch: master

Extra information: I currently have no current symlink already in the folder, so this would be my first release. Don't know if this is useful.

Am I the only one experiencing this issue?

Add some common hooks to the role?

Perhaps we could add some common hooks like the Symfony cleaning cache and assets installation so that people can optionally use them.

In the end, if someone is using Symfony with for instance no AsseticBundle will surely be able to still these hooks as a starting point.

default variable

hey folks, another one. Not sure if that's expected (I'm just testing ansistrano), but
ansistrano_deploy_via: "git"

does not get picked up unless you write it in deploy.yml.

I understand that this variable should be changed in main.yml instead, right?

I'm writing a short tutorial to make that work under Drupal, any help, tip, advice would be very welcome.

Thanks.

failing include when the ansistrano_custom_tasks_path is not set

If the variable ansistrano_custom_tasks_path is not set at the playbook level, the include statement fails with:

ERROR: file could not read: /path/ansible/roles/carlosbuenosvinos.ansistrano-deploy/tasks/{{ ansistrano_custom_tasks_path }}/before-update-code.yml

I believe this is because the include: statement is run when the playbook is parsed - before the default variables are loaded - so the default value is never used.

Does it work for you?

Deploy user

Are there any plans on specifying a deploy user to deploy the code as? Right now it is being deployed as root because I need to specify sudo: true in the playbook.

I am open to implement such an option.

cleanup

shell: ls -1dt {{ ansistrano_releases_path.stdout }}/* | tail -n +{{ ansistrano_keep_releases | int + 1 }} | xargs rm -rf

should be changed to keep_releases num + num of days (mtime). the way it does it now, it will delete all+1 the folders after N deployments

Issue with Ansible 2.0 - set_fact failing

Hey guys Ive been using Ansistrano and Ansible for a while now and I absolutely love it. I had Ansible installed on Ubuntu via the official PPA and apparently Ansible updated to the latest 2.0 version today and it seems to have broken Ansistrano. All of my deployment scripts are now failing at this stage:

TASK [carlosbuenosvinos.ansistrano-deploy : set_fact] **************************
fatal: [app1.wrlweb.com]: FAILED! => {"failed": true, "msg": "ERROR! template error while templating string: unexpected 'end of template'"}

I tried updating Ansistrano and that didn't seem to help. I had to roll back to Ansible 1.9.4 in order to get it to work.

Hook between symlink files and symlink release

I think we need one more hook between the symlink:shared task and the symlink:release task.

When you symlink something like the parameters.yml in a Symfony project, you need this when running the composer install command. But with the current hooks i can either call the command before symlinking (with missing parameters.yml) or after symlinking, but then i already have the new release as current.

When you have a look at the Capistrano flow, you will the there are two steps for symlinking: http://capistranorb.com/documentation/getting-started/flow/

deploy:updating
    git:create_release
    deploy:symlink:shared

deploy:publishing
    deploy:symlink:release

I think this is a much more flexible solution. What do you think? I can make a PR.

Too much redundant output

TASK: [carlosbuenosvinos.ansistrano-deploy | ANSISTRANO | Ensure deployment base path exists] *** 
...
TASK: [carlosbuenosvinos.ansistrano-deploy | ANSISTRANO | RSYNC | Get shared path (in rsync case)] *** 
...
TASK: [carlosbuenosvinos.ansistrano-deploy | ANSISTRANO | GIT | Ensure GIT deployment key is up to date] *** 

Don't you agree it be better use of terminal real estate if this was instead something like:

TASK: [carlosbuenosvinos.ansistrano-deploy | Ensure deployment base path exists] *** 
...
TASK: [carlosbuenosvinos.ansistrano-deploy | deploy_via: rsync | Get shared path] *** 
...
TASK: [carlosbuenosvinos.ansistrano-deploy | deploy_via: git | Ensure deployment key is up to date] *** 

or is there a particular reason for all the repetition and uppercasing that I don't know of? :)

Start tagging the project

One of my biggest concerns before merging all the interesting stuff people propose is BC breaks

We should start tagging the project, and encourage people to specify the latest stable tag when they install this role unless they are advanced users and want to test the new features in the master branch.

Thoughts?

ansistrano_git_repo always empty

the repo paramter to the git command is empty although this role sets a default. setting a custom value in the vars: section does not help. anybody else experiencing this?

- hosts: web
  vars:
    ansistrano_deploy_via: git
  roles:
    - carlosbuenosvinos.ansistrano-deploy
<127.0.0.1> REMOTE_MODULE git version=master dest=/var/www/my-app/repo repo=

failed: [web01] => {"cmd": "/usr/bin/git ls-remote '' -h refs/heads/master", "failed": true, "rc": 128}
stderr: ERROR: Repository not found.
fatal: The remote end hung up unexpectedly

msg: ERROR: Repository not found.
fatal: The remote end hung up unexpectedly

FATAL: all hosts have already failed -- aborting

i would expect this

failed: [web01] => {"cmd": "/usr/bin/git ls-remote '[email protected]:USERNAME/REPO.git' -h refs/heads/master", "failed": true, "rc": 128}
stderr: ERROR: Repository not found.
fatal: The remote end hung up unexpectedly

Two warnings for 1.3.0

Hi there,

Thanks for Ansistrano, loving it so far. Just wanted to report that in combination with Ansible 2.0.0, a few warnings came up:

I realize these aren't critical, but maybe it helps!

Add support for git submodules

In git.yml there's no support for cloning git submodules. This can be fixed by setting recursive=yes in the git ansible module, but I'm not sure if there's any side effects to just adding that in.

Also, git checkout-index doesn't seem to be submodule aware so using it to copy over the git repository doesn't work with submodules.

Update current release only

Sorry, if I missed this feature, but from reading the docs, I couldn't find a simple update role.
What should I do if I want to update the current release from version control? I don't want to go through usual release process, create a timestamp folder, etc. I need to update my current version if there are only minor changes required, like missing assets, typos, etc.
So, is there a way to do this with ansistrano?

Using files/templates in hooks

I would like to be able to copy files/templates as part of ansistrano hooks. In previous versions of ansible and ansistano, I was able to create a files or templates directory relative to the hook file yml. I could then use those files without specific the directory name just like in a role.

Now I have updated to Ansible 2 and the latest version of ansistrano and this is no longer possible. If you specify the file or template like you would in a role, ansible looks for the file in the playbook root directory and then returns an error as it is not found.

I like to create a separate directory for deploys which contains the hook files and any application specific files/templates and then use my normal roles for provisioning. Do you have suggestions?

This is the directory structure I used to use

deploy.yml
group_vars
roles
deploy
├── appname
│   ├── files
│   │   └── fileshere
│   ├── tasks
│   │   ├── after_setup.yml
│   │   ├── after_symlink.yml
│   │   └── after_update_code.yml
│   └── templates
│       ├── templateshere

deploy.yml would contain config like this:

ansistrano_after_update_code_tasks_file: "{{ playbook_dir }}/deploy/appname/tasks/after_update_code.yml"

The playbook with ansistrano config would be at the same level as the deploy directory. In one of the hook files, I could reference a template or file the same way as a role. This does not work anymore.

Sparse Checkout Deploys

My current directory structure looks something like this:

--- root
--- ansible
--- app

The goal is to keep the entire directory as part of the git repository. However, upon deployment, Ansistrano Deploy currently uses the entire repository. I only want to use the contents of the "root/app" directory. Would it be possible to add support for sparse checkouts, while using the git deployment method?

how to patch a project?

Example:
source file list: index.php app.php
dist file list: index.php image app.php

The source is pre-production env and the dist is production env, because the image folder maybe store large images and I can not put it on my pre-production env. if i update the app.php file and then deploy my source to dist, My image folder should be moved to older release folder. How to round this situation?

Shared symlink fails

Commit c002a86 is breaking all of our deployments:

ansistrano_shared_paths:
 - html/fileadmin
 - html/typo3conf/l10n

results in

failed: [XXXXX] => (item=html/fileadmin) => {"failed": true, "invocation": {"module_args": {"backup": null, "content": null, "delimiter": null, "diff_peek": null, "directory_mode": null, "follow": false, "force": false, "group": null, "mode": null, "original_basename": null, "owner": null, "path": "/XXXXX/releases/20160323104405Z/html/fileadmin", "recurse": false, "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": "../../shared/html/fileadmin", "state": "link", "validate": null}, "module_name": "file"}, "item": "html/fileadmin", "msg": "src file does not exist, use \"force=yes\" if you really want to create the link: /XXXXX/releases/20160323104405Z/html/../../shared/html/fileadmin", "path": "/XXXXX/releases/20160323104405Z/html/fileadmin", "src": "../../shared/html/fileadmin", "state": "absent"}
failed: [XXXXX] => (item=html/typo3conf/l10n) => {"failed": true, "invocation": {"module_args": {"backup": null, "content": null, "delimiter": null, "diff_peek": null, "directory_mode": null, "follow": false, "force": false, "group": null, "mode": null, "original_basename": null, "owner": null, "path": "//XXXXX//releases/20160323104405Z/html/typo3conf/l10n", "recurse": false, "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": "../../shared/html/typo3conf/l10n", "state": "link", "validate": null}, "module_name": "file"}, "item": "html/typo3conf/l10n", "msg": "src file does not exist, use \"force=yes\" if you really want to create the link: //XXXXX//releases/20160323104405Z/html/typo3conf/../../shared/html/typo3conf/l10n", "path": "//XXXXX//releases/20160323104405Z/html/typo3conf/l10n", "src": "../../shared/html/typo3conf/l10n", "state": "absent"}

Relative release symlink is ok, only linking of shared directories is failing.

How to make use of shared folder to persist logs

I am using ansistrano for deployment using rsync method. Ansistrano rsync the code in shared folder and than make a new release out of it. However, my logs in current/logs/production.log are getting cleared after deployment. How to persist the logs and what is the use of shared directory other than having persistance of logs and other config files.

rsync ask password

i set in hosts variable ansible_ssh_user and ansible_ssh_pass, all ok, but on
TASK: [carlosbuenosvinos.ansistrano-deploy | ANSISTRANO | RSYNC | Rsync application files to remote shared copy] *** ansistrano ask me password from host

Calling roles in the hooks

While developing my deploy playbook using ansistrano I found the following issue:

In my "after code update" hook I would need to be able to call some roles, as well as regular tasks. And I need them in a certain order. But as long as I know it's not possible to do that from an included tasks file.

Am I right?

If that's true, wouldn't it be awesome to convert the hooks to roles instead of simple include files? That would allow the freedom to have the hooks depend on roles, as well as simple executing a list of tasks.

Is it doable?

Can I use ansistrano as multiple roles?

I want to deploy multiple contents (e.g. api, batch, console) to same host.

If ansistrano's variables are not top level parameters (e.g. ansistrano.ansistrano_deploy_to), I can write as described below.
But ansistrano's variables are top level parameters (e.g. ansistrano_deploy_to) now.

Can I use ansistrano as multiple roles in the current implementation?

site.yml


---
- hosts: all-in-one-server
  vars_files:
    - vars/all/main.yml
  roles:
    - { role: carlosbuenosvinos.ansistrano-deploy, ansistrano: "{{ ansistrano.api }}" }
    - { role: carlosbuenosvinos.ansistrano-deploy, ansistrano: "{{ ansistrano.batch}}" }
    - { role: carlosbuenosvinos.ansistrano-deploy, ansistrano: "{{ ansistrano.console }}" }

- hosts: api-server
  vars_files:
    - vars/all/main.yml
  roles:
    - { role: carlosbuenosvinos.ansistrano-deploy, ansistrano: "{{ ansistrano.api }}" }

vars/all/main.yml

ansistrano:
  api:
    ansistrano_deploy_to: /path/to/api
    ansistrano_git_repo: ...
    ....
  batch:
    ansistrano_deploy_to: /path/to/batch
    ansistrano_git_repo: ...
    ....
  console:
    ansistrano_deploy_to: /path/to/console
    ansistrano_git_repo: ...
    ....

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.