Created
February 8, 2019 00:20
-
-
Save rromanchuk/af3cce7f078bd576847a318f3ec1e280 to your computer and use it in GitHub Desktop.
Example ansible deploy with webpacker
This file contains hidden or 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
- name: Bundle install with --deploy | |
bundler: | |
state: present | |
deployment_mode: yes | |
chdir: "{{ ansistrano_release_path.stdout }}" | |
executable: /home/ubuntu/.rbenv/shims/bundle | |
- name: Running pending migrations | |
shell: $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate | |
run_once: true | |
args: | |
chdir: "{{ ansistrano_release_path.stdout }}" | |
- name: Precompiling assets | |
shell: $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile | |
args: | |
chdir: "{{ ansistrano_release_path.stdout }}" | |
######################################### | |
- name: restart puma | |
become: yes | |
service: | |
name: puma.service | |
state: restarted | |
when: (inventory_hostname in groups['tag_Role_web']|default([])) or (inventory_hostname in groups['tag_Role_web_worker']|default([])) | |
- name: start nginx | |
become: yes | |
service: | |
name: nginx | |
state: started | |
when: (inventory_hostname in groups['tag_Role_web']|default([])) or (inventory_hostname in groups['tag_Role_web_worker']|default([])) | |
- name: restart sidekiq | |
become: yes | |
service: | |
name: sidekiq | |
state: restarted | |
when: (inventory_hostname in groups['tag_Role_worker']|default([])) or (inventory_hostname in groups['tag_Role_web_worker']|default([])) | |
- name: restart shoryuken | |
become: yes | |
service: | |
name: shoryuken | |
state: restarted | |
when: (inventory_hostname in groups['tag_Role_worker']|default([])) or (inventory_hostname in groups['tag_Role_web_worker']|default([])) |
This file contains hidden or 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
- name: Deploy rails application | |
hosts: tag_Role_web:tag_Role_worker:tag_Role_base:tag_Role_web_worker | |
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_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_ensure_shared_paths_exist: yes | |
ansistrano_ensure_basedirs_shared_files_exist: yes | |
## Run | |
ansistrano_after_cleanup_tasks_file: "{{ playbook_dir }}/deploy-tasks/after-cleanup-tasks.yml" | |
ansistrano_shared_paths: | |
- log # log -> ../../shared/log | |
- tmp # tmp -> ../../shared/tmp | |
- vendor # vendor -> ../../shared/vendor | |
- public/assets # For rails asset pipeline | |
- public/packs # For webpacker | |
- node_modules # For webpacker node_modules -> ../../shared/node_modules | |
ansistrano_shared_files: | |
# Rails key file, not checked in, but managed in shared/config/master.key https://www.engineyard.com/blog/rails-encrypted-credentials-on-rails-5.2 | |
- config/master.key # {{current]}/config/master.key -> ../../../shared/config/master.key | |
pre_tasks: | |
- name: Make shared directories | |
become: yes | |
file: path={{deploy_directory}}/shared/{{item}} state=directory owner=ubuntu group=ubuntu | |
with_items: | |
- tmp | |
- tmp/pids | |
- tmp/cache | |
- tmp/sockets | |
- log | |
- public | |
- public/packs | |
- vendor | |
- vendor/bundle | |
- bin | |
- config | |
- config/puma | |
- assets | |
- node_modules # Webpacker | |
roles: | |
- carlosbuenosvinos.ansistrano-deploy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you're deploying with webpacker, be sure to include
node_modules
andpublic/packs
, these are new directories that are easy to forget if you coming from rails asset pipeline, if you forget you are going to have a very bad time deploying.rails/webpacker@7c6e3cc#diff-00e64a8af4dd5116b95476a6691792dcR80