summaryrefslogtreecommitdiff
path: root/roles/dotfiles/tasks/main.yml
blob: 17228a5b0c4b08e319d07e65f98b6e8b08baa4df (plain) (blame)
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
# This role is a little bit different from others, because it is supposed to
# run mostly from localhost to make and copy dotfiles that might be useful on
# this particular machine. There is maybe not enough permissions to install
# software, so we are taking unusual approach here: check if software is
# installed and then bring relevant dotfiles for it.

- name: Configure bash if installed
  tags: bash
  block:
    - name: Check if bash is installed
      ansible.builtin.command: bash --version
      changed_when: false
      failed_when: false
      register: has_bash

    - name: Copy bash_profile to home directory
      ansible.builtin.copy:
        src: misc/dotfiles/bash_profile
        dest: '{{ homedir }}/.bash_profile'
      when: has_bash.rc == 0

    - name: Template bashrc to home directory
      ansible.builtin.template:
        src: misc/dotfiles/bashrc.j2
        dest: '{{ homedir }}/.bashrc'
      when: has_bash.rc == 0

- name: Configure vim if installed
  tags: vim
  block:
    - name: Check if vim is installed
      ansible.builtin.command: vim --version
      changed_when: false
      failed_when: false
      register: has_vim

    - name: Copy vimrc to home directory
      ansible.builtin.copy:
        src: misc/dotfiles/vimrc
        dest: '{{ homedir }}/.vimrc'
      when: has_vim.rc == 0

- name: Configure screen if installed
  tags: screen
  block:
    - name: Check if screen is installed
      ansible.builtin.command: screen --version
      changed_when: false
      failed_when: false
      register: has_screen

    - name: Template screenrc to home directory
      ansible.builtin.template:
        src: misc/dotfiles/screenrc.j2
        dest: '{{ homedir }}/.screenrc'
      when: has_screen.rc == 0

- name: Configure ssh if installed
  tags: ssh
  block:
    - name: Check if ssh is installed
      ansible.builtin.command: ssh -V
      changed_when: false
      failed_when: false
      register: has_ssh

    - name: Setup ssh directory
      ansible.builtin.file:
        path: '{{ user }}/.ssh'
        state: directory
        owner: '{{ user }}'
        mode: u+rw,g-rw,o-rw
      when: has_ssh.rc == 0

    - name: Template ssh config to home directory
      ansible.builtin.template:
        src: misc/dotfiles/ssh/config.j2
        dest: '{{ homedir }}/.ssh/config'
        owner: '{{ user }}'
        mode: u+rw,g-rw,o-rw
      when: has_ssh.rc == 0

    - name: Copy ssh rc to home directory
      ansible.builtin.copy:
        src: misc/dotfiles/ssh/rc
        dest: '{{ homedir }}/.ssh/rc'
        owner: '{{ user }}'
        mode: u+rwx,g-rw,o-rw
      when:
        - has_ssh.rc == 0
        - jumphost

- name: Configure git if installed
  tags: git
  block:
    - name: Check if git is installed
      ansible.builtin.command: git --version
      changed_when: false
      failed_when: false
      register: has_git

    - name: Copy git config files to home directory
      ansible.builtin.copy:
        src: misc/dotfiles/{{ item }}
        dest: '{{ homedir }}/.{{ item }}'
      loop:
        - gitconfig
        - gitignore
      when: has_git.rc == 0

- name: Configure gdb if installed
  tags: gdb
  block:
    - name: Check if gdb is installed
      ansible.builtin.command: gdb --version
      changed_when: false
      failed_when: false
      register: has_gdb

    - name: Copy gdbinit to home directory
      ansible.builtin.copy:
        src: misc/dotfiles/gdbinit
        dest: '{{ homedir }}/.gdbinit'
      when: has_gdb.rc == 0

- name: Configure mutt if installed
  tags: mutt
  block:
    - name: Check if mutt is installed
      ansible.builtin.command: mutt -v
      changed_when: false
      failed_when: false
      register: has_mutt

    - name: Copy muttrc to home directory
      ansible.builtin.copy:
        src: misc/dotfiles/muttrc
        dest: '{{ homedir }}/.muttrc'
      when: has_mutt.rc == 0

- name: Copy templates files if necessary
  tags: templates
  block:
    - name: Check if C++ compiler is installed
      ansible.builtin.command: c++ --version
      changed_when: false
      failed_when: false
      register: has_cpp

    - name: Check if Python is installed
      ansible.builtin.command: python --version
      changed_when: false
      failed_when: false
      register: has_python

    - name: Setup templates directory
      ansible.builtin.file:
        path: '{{ homedir }}/.templates'
        state: directory
        owner: '{{ user }}'
      when: has_cpp.rc == 0 or has_python.rc == 0

    - name: Copy template.cpp to home directory
      ansible.builtin.copy:
        src: misc/dotfiles/templates/template.cpp
        dest: '{{ homedir }}/.templates/template.cpp'
      when: has_cpp.rc == 0

    - name: Copy template.py to home directory
      ansible.builtin.copy:
        src: misc/dotfiles/templates/template.py
        dest: '{{ homedir }}/.templates/template.py'
      when: has_python.rc == 0