deploy playbook was created

This commit is contained in:
Denis Fedoseev 2019-02-13 12:49:56 +03:00
parent 52b50e26f9
commit 6d3d1aa9a3
2 changed files with 75 additions and 0 deletions

72
deploy/deploy.yml Normal file
View file

@ -0,0 +1,72 @@
---
- name: Deploy service
hosts: web
vars:
service_unit_name: "shrlbe"
remote_user_name: "shrlbe"
src_path: ~/projects/shrl.be
dst_path: /srv/shrl.be/
local_archive: "/tmp/shrl.be.tgz"
tasks:
- name: Archive
archive:
path: "{{ src_path }}/*"
dest: "{{ local_archive }}"
exclude_path:
- "{{ src_path }}/deploy"
- "{{ src_path }}/.vscode"
- "{{ src_path }}/.git"
- "{{ src_path }}/shrl.*"
format: "gz"
remove: no
delegate_to: localhost
- name: stop service
service:
name: "{{ service_unit_name }}"
state: stopped
become: true
- name: copy zip
copy:
src: "{{ local_archive}}"
dest: "{{ local_archive}}"
remote_src: no
- name: Unarchive
unarchive:
src: "{{ local_archive }}"
dest: "{{ dst_path }}"
remote_src: yes
group: "{{ remote_user_name }}"
owner: "{{ remote_user_name }}"
mode: 0644
become: true
- name: Erase archive local
file:
path: "{{ local_archive }}"
state: absent
delegate_to: localhost
- name: Erase archive remote
file:
path: "{{ local_archive }}"
state: absent
- name: Set correct rights on the destination directory
file:
path: "{{ dst_path }}"
state: directory
owner: "{{ remote_user_name }}"
group: "{{ remote_user_name }}"
mode: 0755
recurse: yes
become: true
- name: restart service
service:
name: "{{ service_unit_name }}"
state: started
become: true

3
deploy/hosts.ini Normal file
View file

@ -0,0 +1,3 @@
[web]
shrl.be ansible_ssh_user=root