df3b075ab0b25a113cbae0ff92c5b3508eb84bcd
[noc.git] / ansible / roles / base / tasks / main.yaml
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   lineinfile:
17      dest: /etc/ssh/sshd_config
18      regexp: "^#?AllowUsers"
19      line: "AllowUsers {{ ' '.join(sshd_allowusers) }}"
20   when: sshd_allowgroup is not defined
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: "{{ lookup('pipe','cat ssh/noc/*.pub') }}"
51     exclusive: yes
52
53 - name: disable apt suggests and recommends
54   copy: src=02no-recommends dest=/etc/apt/apt.conf.d/ mode=0644
55
56 - name: install basic packages
57   apt: name={{ item }} state=present
58   with_items:
59     - less
60     - psmisc
61     - sudo
62     - htop
63     - dstat
64     - mtr-tiny
65     - tcpdump
66     - debian-goodies
67     - lsof
68     - haveged
69     - net-tools
70     - ntp
71     - screen
72     - aptitude
73     - unp
74     - ca-certificates
75     - file
76     - zsh
77     - python-apt
78
79 - block:
80     - name: install systemd specific packages
81       apt: name={{ item }} state=present
82       with_items:
83         - dbus
84         - libpam-systemd
85
86     - name: set systemd-related environment variables
87       copy: src=xdg_runtime_dir.sh dest=/etc/profile.d/xdg_runtime_dir.sh mode=0644
88
89   when: ansible_service_mgr == "systemd"
90
91 - name: install zshrc
92   copy: src={{ item.src }} dest={{ item.dest }} mode=0644
93   with_items:
94     - { "src": "zprofile", "dest": "/etc/zsh/zprofile" }
95     - { "src": "zshrc", "dest": "/etc/zsh/zshrc" }
96     - { "src": "zshrc.skel", "dest": "/etc/skel/.zshrc" }
97
98 - name: set root default shell to zsh
99   user: name=root shell=/bin/zsh
100
101 - name: set default shell for adduser
102   lineinfile: dest=/etc/adduser.conf regexp={{ item.regexp }} line={{ item.line }}
103   with_items:
104     - { regexp: "^DSHELL", line: "DSHELL=/bin/zsh" }