ansible: use variables for ssh keys
[noc.git] / ansible / roles / base / tasks / main.yml
1 ---
2 - set_fact:
3     sshd_allowusers: >-
4       {{ [ 'root' ] | union(user_groups.noc)
5                     | union(sshd_allowusers_group | default([]))
6                     | union(sshd_allowusers_host  | default([])) }}
7
8 - name: only allow pubkey auth for root
9   lineinfile:
10     dest: /etc/ssh/sshd_config
11     regexp: "^PermitRootLogin"
12     line: "PermitRootLogin without-password"
13   notify: restart ssh
14
15 - name: limit allowed users (1/2)
16   when: sshd_allowgroup is not defined
17   lineinfile:
18     dest: /etc/ssh/sshd_config
19     regexp: "^#?AllowUsers"
20     line: "AllowUsers {{ ' '.join(sshd_allowusers) }}"
21   notify: restart ssh
22
23 - block:
24     - name: "limit allowed users (2/2): Make sure AllowUsers is not in sshd_config"
25       lineinfile:
26         dest: /etc/ssh/sshd_config
27         regexp: "^AllowUsers"
28         state: absent
29       notify: restart ssh
30
31     - name: "limit allowed users (2/2): Set AllowGroups in sshd_config"
32       lineinfile:
33         dest: /etc/ssh/sshd_config
34         regexp: "^#?AllowGroups"
35         line: AllowGroups {{ sshd_allowgroup }}
36       notify: restart ssh
37
38     - name: "limit allowed users (2/2): Add allowed users to ssh group"
39       user:
40         name: "{{ item }}"
41         groups: "{{ sshd_allowgroup }}"
42         append: True
43       with_items: "{{ sshd_allowusers }}"
44
45   when: sshd_allowgroup is defined
46
47 - name: Set authorized keys for root user
48   authorized_key:
49     user: root
50     key: "{{ noc_ssh_keys | join('\n') }}"
51     exclusive: yes
52
53 - name: disable apt suggests and recommends
54   copy:
55     src: 02no-recommends
56     dest: /etc/apt/apt.conf.d/
57     mode: 0644
58
59 - name: install basic packages
60   apt:
61     name:
62       - less
63       - psmisc
64       - sudo
65       - htop
66       - dstat
67       - mtr-tiny
68       - tcpdump
69       - debian-goodies
70       - lsof
71       - haveged
72       - net-tools
73       - ntp
74       - screen
75       - aptitude
76       - unp
77       - ca-certificates
78       - file
79       - zsh
80       - python-apt
81     state: present
82
83 - name: make sure grml-(etc|scripts)-core is not installed
84   apt:
85     name:
86       - grml-etc-core
87       - grml-scripts-core
88     state: absent
89     purge: yes
90
91 - block:
92     - name: install systemd specific packages
93       apt:
94         name:
95           - dbus
96           - libpam-systemd
97         state: present
98
99     - name: set systemd-related environment variables
100       copy:
101         src: xdg_runtime_dir.sh
102         dest: /etc/profile.d/xdg_runtime_dir.sh
103         mode: 0644
104
105   when: ansible_service_mgr == "systemd"
106
107 - name: install zshrc
108   with_items:
109     - src: "zprofile"
110       dest: "/etc/zsh/zprofile"
111     - src: "zshrc"
112       dest: "/etc/zsh/zshrc"
113     - src: "zshrc.skel"
114       dest: "/etc/skel/.zshrc"
115   copy:
116     src: "{{ item.src }}"
117     dest: "{{ item.dest }}"
118     mode: 0644
119
120 - name: set root default shell to zsh
121   user:
122     name: root
123     shell: /bin/zsh
124
125 - name: set default shell for adduser
126   with_items:
127     - regexp: "^DSHELL"
128       line: "DSHELL=/bin/zsh"
129   lineinfile:
130     dest: /etc/adduser.conf
131     regexp: "{{ item.regexp }}"
132     line: "{{ item.line }}"