-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup_zsh.yaml
104 lines (87 loc) · 2.73 KB
/
Setup_zsh.yaml
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
---
- name: Install zsh, antigen
hosts: all
become: yes
become_method: sudo
become_user: "{{ dev_user }}"
vars:
- shell_config_dir: .shell-config
pre_tasks:
- name: Install zsh
become: true
become_user: root
package:
name: zsh
state: present
tasks:
- name: Get the dev user home dir
become: yes
become_user: "{{ dev_user }}"
shell:
cmd: "echo $HOME"
# level: 2
changed_when: false
register: dev_home
- name: Print dev_home variable
debug:
var: dev_home.stdout
- name: Clone the shell-config repo
git:
clone: yes
repo: https://github.com/Gray-Stone/shell-config
dest: "{{ dev_home.stdout }}/{{ shell_config_dir }}"
- name: Install the antigen source file anyway.
get_url:
url: 'http://git.io/antigen'
dest: "{{ dev_home.stdout }}/{{ shell_config_dir }}/antigen.zsh"
force: yes
mode: 0644
- name: Make sure .zshrc exists
become: yes
become_user: root
file:
owner: "{{ dev_user }}"
group: "{{ dev_user }}"
mode: 0644
state: touch
path: "{{ dev_home.stdout }}/.zshrc"
- name: Check if oh my zsh is installed by checking folder
stat:
path: "{{ dev_home.stdout }}/.oh-my-zsh"
register: oh_my_zsh_dir
###################################
# When oh my zsh is not installed
###################################
- name: Install oh my zsh
become: yes
become_user: "{{ dev_user }}"
shell:
chdir: "~/."
cmd: sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended --keep-zshrc
when: not oh_my_zsh_dir.stat.exists
##################################
# Still run these regardless of oh my zsh just installed or not
##################################
- name: Insert a ansible managed zsh config to zshrc
become: yes
become_user: root
blockinfile:
owner: "{{ dev_user }}"
group: "{{ dev_user }}"
path: "{{ dev_home.stdout }}/.zshrc"
mode: 0644
insertbefore: BOF
marker_begin: "#### Block Inserted by ansible ####"
marker_end: "#### End of ansible block, add more after this ####"
block: |
# Include the fully managed script from ansible
source "{{ dev_home.stdout }}/{{ shell_config_dir }}/zsh-config.zsh"
# force sub shell
export SHELL=/bin/zsh
# Most are in shell config repo
- name: Set zsh and user default shell
become: yes
become_user: root
user:
name: "{{ dev_user }}"
shell: /bin/zsh