-
Notifications
You must be signed in to change notification settings - Fork 0
/
pb-permitrootlogin-v3.yml
51 lines (43 loc) · 1.82 KB
/
pb-permitrootlogin-v3.yml
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
- hosts: local
#become: yes
#become_method: sudo
tasks:
- name: checking if /etc/ssh/sshd_config.bckup exist
shell: test -f /etc/ssh/sshd_config.bckup
ignore_errors: true
register: sshdbckup_exists
failed_when: sshdbckup_exists.rc not in [0, 1]
- name: create /etc/ssh/sshd_config.bckup
shell: cat /etc/ssh/sshd_config >/etc/ssh/sshd_config.bckup
when: sshdbckup_exists.rc == 1
- name: checking if admin1 exists
shell: test -d /home/admin1
ignore_errors: true
register: admin1_exists
failed_when: admin1_exists.rc not in [0, 1]
- name: checking again if /etc/ssh/sshd_config.bckup exist
shell: test -f /etc/ssh/sshd_config.bckup
ignore_errors: true
register: sshdbckupagain_exists
failed_when: sshdbckupagain_exists.rc not in [0, 1]
- name: editing PermitRootLogin entry when /etc/ssh/sshd_config.bckup and admin1 exist
shell: cat /etc/ssh/sshd_config.bckup | sed -e 's/\#PermitRootLogin yes/PermitRootLogin no/g' > /etc/ssh/sshd_config
when: (sshdbckupagain_exists.rc == 0) and
(admin1_exists.rc == 0)
- name: checking if /etc/securetty.bckup exist
shell: test -f /etc/securetty.bckup
ignore_errors: true
register: securettybckup_exists
failed_when: securettybckup_exists.rc not in [0, 1]
- name: create /etc/securetty.bckup
shell: cat /etc/securetty > /etc/securetty.bckup
when: securettybckup_exists.rc == 1
- name: checking again if /etc/securetty.bckup exist
shell: test -f /etc/securetty.bckup
ignore_errors: true
register: securettybckupagain_exists
failed_when: securettybckupagain_exists.rc not in [0, 1]
- name: editing /etc/securetty entry when /etc/securetty.bckup and admin1 exist
shell: echo "" > /etc/securetty
when: (securettybckupagain_exists.rc == 0) and
(admin1_exists.rc == 0)