-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaybook.yml
More file actions
248 lines (207 loc) · 6.77 KB
/
playbook.yml
File metadata and controls
248 lines (207 loc) · 6.77 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
- hosts: 127.0.0.1
connection: local
vars_prompt:
- name: "ansible_become_pass"
prompt: "[sudo] password for {{ lookup('env','USER') }}"
- name: "ssh_key_passphrase"
prompt: "Please enter id_rsa SSH key passphrase"
- name: "git_username"
prompt: "Please enter a global git username"
- name: "git_email"
prompt: "Please enter a global git email"
tasks:
- name: Source .profile
expect:
command: /bin/bash -c "source /home/{{ lookup('env','USER') }}/.profile"
responses:
passphrase: "{{ ssh_key_passphrase }}\n"
no_log: true
# - name: Source .profile
# shell: source ~/.profile
# args:
# executable: /bin/bash
- name: Ensure wsl.conf exists
become: yes
copy:
content: ""
dest: /etc/wsl.conf
force: no
group: root
owner: root
mode: 0644
- name: Update wsl.conf
become: yes
blockinfile:
path: /etc/wsl.conf
block: "{{ wsl_conf }}"
- name: Ensure .gitconfig exists
copy:
content: ""
dest: ~/.gitconfig
force: no
mode: 0644
- name: Update .gitconfig
blockinfile:
path: /home/{{ lookup('env','USER') }}/.gitconfig
block: "{{ gitconfig }}"
- name: Set git username
shell: "git config --global user.name \"{{ git_username }}\""
when: git_username|length > 0
- name: Set git email
shell: "git config --global user.email \"{{ git_email }}\""
when: git_email|length > 0
- name: Check if ~/.ssh exists
stat:
path: ~/.ssh
register: ssh_check
- name: Check if ~/.ssh/id_rsa key exists
stat:
path: ~/.ssh/id_rsa
register: ssh_key_check
- name: Check if $WINHOME/.ssh exists
stat:
path: "{{ lookup('env','WINHOME') }}/.ssh"
register: winssh_check
- name: Check if $WINHOME/.ssh/id_rsa exists
stat:
path: "{{ lookup('env','WINHOME') }}/.ssh/id_rsa"
register: winssh_key_check
- name: "No SSH keys exist in $WINHOME or ~/.ssh"
when: not winssh_key_check.stat.exists and not ssh_key_check.stat.exists
block:
- name: "No SSH keys exist in $WINHOME or ~/.ssh :: Create SSH key in ~/.ssh"
no_log: true
user:
name: "{{ lookup('env','USER') }}"
generate_ssh_key: yes
ssh_key_passphrase: "{{ ssh_key_passphrase }}"
- name: "No SSH keys exist in $WINHOME or ~/.ssh :: Copy SSH key to $WINHOME/.ssh"
copy:
src: ~/.ssh/
dest: "{{ lookup('env','WINHOME') }}/.ssh"
remote_src: yes
- name: "SSH keys exist in $WINHOME but not in ~/.ssh"
when: winssh_key_check.stat.exists and not ssh_key_check.stat.exists
block:
- name: "SSH keys exist in $WINHOME but not in ~/.ssh :: Copy SSH keys to ~/.ssh"
copy:
src: "{{ lookup('env','WINHOME') }}/.ssh/"
dest: ~/.ssh
remote_src: yes
- name: Set private key permissions
file:
path: ~/.ssh/id_rsa
mode: '0600'
- name: Set public key permissions
file:
path: ~/.ssh/id_rsa.pub
mode: '0644'
- name: "SSH keys exist in ~/.ssh but not in $WINHOME :: Copy SSH key to $WINHOME/.ssh"
copy:
src: ~/.ssh/
dest: "{{ lookup('env','WINHOME') }}/.ssh"
remote_src: yes
when: not winssh_key_check.stat.exists and ssh_key_check.stat.exists
- name: Install unzip
become: yes
package:
name: unzip
state: present
- name: Install keychain
become: yes
package:
name: keychain
state: present
- name: Install pexpect
become: yes
package:
name: python3-pexpect
state: present
- name: Updating .profile
blockinfile:
path: /home/{{ lookup('env','USER') }}/.profile
block: "{{ profile }}"
- name: Updating .bashrc
blockinfile:
path: /home/{{ lookup('env','USER') }}/.bashrc
block: "{{ bash }}"
- name: Source .bashrc
shell: source ~/.bashrc
args:
executable: /bin/bash
- name: Set keychain.
expect:
command: /bin/bash -c "/usr/bin/keychain $HOME/.ssh/id_rsa"
responses:
passphrase: "{{ ssh_key_passphrase }}\n"
no_log: true
- name: Apply Keychain settings.
shell: source $HOME/.keychain/{{ lookup('env','NAME') }}-sh
args:
executable: /bin/bash
- name: Source .profile
shell: source ~/.profile
# no_log: true
args:
executable: /bin/bash
# stdin: "{{ ssh_key_passphrase }}"
# stdin_add_newline: yes
- name: Install Galaxy Roles in the requirements.yml file
local_action:
command ansible-galaxy install \
--force \
--keep-scm-meta \
-r {{ playbook_dir }}/requirements.yml \
--roles-path={{ playbook_dir }}/roles
when: skip_roles != "yes"
- name: Make sure the roles directory is being git ignored
shell: printf "*\n!.gitignore" > {{ playbook_dir }}/roles/.gitignore
- name: Install and configure Unison to sync ~/.ssh and $WINHOME/.ssh
include_role:
name: weareinteractive.unison
vars:
unison_configs:
- name: sync-ssh-keys
src: "{{ lookup('env','WINHOME') }}/.ssh"
dest: "/home/{{ lookup('env','USER') }}/.ssh"
batch: yes
unison_user: "{{ lookup('env','USER') }}"
ansible_become: yes
- name: Install PHP Versions
include_role:
name: geerlingguy.php-versions
vars:
ansible_become: yes
- name: Install PHP
include_role:
name: geerlingguy.php
vars:
ansible_become: yes
- name: Install Composer
include_role:
name: geerlingguy.composer
vars:
ansible_become: yes
- name: Install npm
include_role:
name: robertdebock.npm
vars:
ansible_become: yes
- name: DDEV - Check if exists
stat:
path: /usr/bin/ddev
register: ddev_binary
- name: DDEV not installed. Let's do it.
when: not ddev_binary.stat.exists
block:
- name: DDEV - Download key
shell: 'curl https://apt.fury.io/drud/gpg.key | sudo apt-key add -'
when: ddev_binary.stat.exists == False
- name: DDEV - Install apt sources
shell: 'echo "deb https://apt.fury.io/drud/ * *" | sudo tee -a /etc/apt/sources.list.d/ddev.list'
when: ddev_binary.stat.exists == False
- name: DDEV - Install
shell: 'sudo apt update && sudo apt install -y ddev'
when: ddev_binary.stat.exists == False
- name: Install mkcert
shell: 'mkcert -install'