-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathuclalib_ansible_capdeploy.yml
134 lines (115 loc) · 4.72 KB
/
uclalib_ansible_capdeploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
---
- name: uclalib_ansible_capdeploy.yml
hosts: all
tasks:
- name: Ensure ansible user is defined
set_fact:
ansible_username: "{{ ansible_user | default('ansible') }}"
- name: Ensure capistrano deploy user is defined
set_fact:
cap_user: "{{ capistrano_user | default('deploy') }}"
- name: Ensure capistrano base path is defined
set_fact:
cap_base: "{{ capistrano_base | default('/opt') }}"
- name: Set feature flag for capistrano deploy
set_fact:
cap_feature_flag: "{{ feature_flag | default('empty') }}"
- name: Determine if content ingest rake process is running
command: >
pgrep -fau {{ cap_user }} rake
ignore_errors: true
changed_when: false
register: ingest_rake_process
- name: Aborted
fail:
msg: "Content ingest is in progress - code deploy stopped."
when: ingest_rake_process.rc == 0
- name: deploy
block:
- name: Obtain a fresh clone of the project's git repository
become: true
become_user: "{{ ansible_username }}"
git:
repo: "{{ git_repo_url }}"
dest: "/home/{{ ansible_username }}/{{ project_name }}"
version: "{{ git_repo_branch }}"
- name: Get bundled-with version
command:
cmd: sed -n '/BUNDLED WITH/{n;p;}' Gemfile.lock # noqa command-instead-of-module
chdir: "/home/{{ ansible_username }}/{{ project_name }}"
changed_when: false
check_mode: false
register: bundler_version
- name: Install Versioned Bundler
gem:
name: bundler
version: '{{ bundler_version.stdout | trim }}'
force: true
state: present
user_install: false
- name: Install required project gems
bundler:
state: present
chdir: "/home/{{ ansible_username }}/{{ project_name }}"
- name: Execute capistrano deployment of project
become: true
become_user: "{{ ansible_username }}"
shell: >
ssh-agent sh -c 'ssh-add; BRANCH={{ git_repo_branch }} PATH=/home/ansible/.local/bin:/home/ansible/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin bundle exec cap localhost deploy'
args:
chdir: /home/{{ ansible_username }}/{{ project_name }}
changed_when: true
when: cap_feature_flag == 'empty'
- name: Execute capistrano deployment of project with feature flag
become: true
become_user: "{{ ansible_username }}"
shell: >
ssh-agent sh -c 'ssh-add; BRANCH={{ git_repo_branch }} FEATURE_FLAG={{ cap_feature_flag }} bundle exec cap localhost deploy'
args:
chdir: /home/{{ ansible_username }}/{{ project_name }}
changed_when: true
when: cap_feature_flag != 'empty'
- name: Remove existing/default robots.txt file
file:
path: "{{ cap_base }}/{{ project_name }}/current/public/robots.txt"
state: "absent"
become: true
become_user: "{{ capistrano_user }}"
- name: Allow search engine crawling of this site
file:
src: "{{ cap_base }}/{{ project_name }}/current/public/robots_allow.txt"
path: "{{ cap_base }}/{{ project_name }}/current/public/robots.txt"
state: "link"
become: true
become_user: "{{ capistrano_user }}"
when: allow_web_crawl == "yes"
- name: Disallow search engine crawling of this site
file:
src: "{{ cap_base }}/{{ project_name }}/current/public/robots_disallow.txt"
path: "{{ cap_base }}/{{ project_name }}/current/public/robots.txt"
state: "link"
become: true
become_user: "{{ capistrano_user }}"
when: allow_web_crawl == "no"
- name: Enable Stack Tracing
lineinfile:
path: '{{ cap_base }}/{{ project_name }}/current/config/environments/production.rb'
line: '\1true'
regexp: '(\s*config.consider_all_requests_local\s*=\s*)false'
backrefs: true
state: present
become: true
become_user: "{{ capistrano_user }}"
when:
- (allow_stack_trace|default('false')) | bool
- (stack_trace|default('false')) | bool
- name: Restart Apache HTTPD to reload passenger application
systemd:
name: httpd
state: restarted
become: true
always: # deploy block
- name: Clean-up ansible user project deploy directory
file:
path: "/home/{{ ansible_username }}/{{ project_name }}"
state: absent