-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathssh_hand.yaml
119 lines (105 loc) · 3.61 KB
/
ssh_hand.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
---
- hosts: all
user: charles.a
connection: ssh
become_user: root
become: yes
become_method: sudo
connection: paramiko
gather_facts: yes
vars:
ssh_chaves:
- charles.a
sshd_config: /etc/ssh/sshd_config
chave_dir_ori: /Users/charles.a/Acessos/Ansible/chaves
chave_dir_dst: /etc/ssh/chaves
ansible_sudo_flags: '-H'
pwd_alias: "{{ lookup('password', '/dev/null length=17 chars=ascii_letters') }}"
sudo_config: /etc/sudoers
tasks:
- name: Adicionado grupo 'wheel'
group:
name: wheel
state: present
tags: adiciona_wheel
- name: Adiciona grupo %grpadminlinux e usuario charles para sem senha
lineinfile:
backup=yes
dest="{{ sudo_config }}"
line="{{ item.line }}"
insertafter="{{ item.insertafter }}"
with_items:
# - { line: '%grpadminlinux ALL=(ALL) ALL ', insertafter: EOF }
- { line: '%wheel ALL=(ALL) ALL ', insertafter: EOF }
- { line: 'charles.a ALL=(ALL) NOPASSWD: ALL ', insertafter: EOF }
- name: Criando diretorios das Chaves SSH
action: file path={{ chave_dir_dst }} state=directory
owner=0 group=0 mode=0755
tags: adiciona_chaves
- name: Copiando as chaves SSH
action: copy src={{ chave_dir_ori }}/{{ item }}.pub
dest={{ chave_dir_dst }}
owner=0 group=0 mode=644
with_items: "{{ ssh_chaves }}"
tags: adiciona_chaves
- name: Deixando o sshd nas permissoes corretas /etc/ssh/sshd_config
file:
path: /etc/ssh/sshd_config
state: file
mode: 0600
owner: root
group: root
- name: Remove configuracoes antigas
lineinfile:
backup=yes
dest="{{ sshd_config }}"
state=absent
regexp="(?i)^{{ item }}"
with_items:
- AllowGroups
- AllowUsers
- DenyUsers
- PermitRootLogin
- X11Forwarding
- AuthorizedKeysFile
- MaxAuthTries
- Ciphers
- ClientAliveCountMax
tags: configura_ssh
- name: Modifca algumas linhas do ssh - handering
lineinfile:
backup=yes
dest="{{ sshd_config }}"
regexp="{{ item.regexp }}"
line="{{ item.line }}"
with_items:
- { regexp: '(?i)^.PermitRootLogin', line: 'PermitRootLogin no' }
- { regexp: '(?i)^.AuthorizedKeysFile', line: 'AuthorizedKeysFile {{ chave_dir_dst }}/%u.pub ' }
- { regexp: '(?i)^.X11Forwarding', line: 'X11Forwarding no' }
- { regexp: '(?i)^.MaxAuthTries', line: 'MaxAuthTries 3' }
- { regexp: '(?i)^.PermitUserEnvironment', line: 'PermitUserEnvironment no' }
- { regexp: '(?i)^.Ciphers', line: 'Ciphers aes128-ctr,aes192-ctr,aes256-ctr' }
- { regexp: '(?i)^.AllowTcpForwarding', line: 'AllowTcpForwarding No' }
- { regexp: '(?i)^.ClientAliveCountMax', line: 'ClientAliveCountMax 0' }
- name: Permite grupo whell acesso e grpadminlinux ao sistema
lineinfile:
dest="{{ sshd_config }}"
line="{{ item.line }}"
insertafter="{{ item.insertafter }}"
with_items:
- { line: 'AllowGroups wheel ', insertafter: EOF }
- { line: 'DenyUsers ALL', insertafter: EOF }
notify:
- restart ssh
- restart sshd
tags: configura_ssh
handlers:
- name: restart sshd
service: name=sshd state=restarted
when: (ansible_distribution == 'Red Hat Enterprise Linux') or
(ansible_distribution == 'RedHat') or
(ansible_distribution == 'CentOS') or
(ansible_distribution == 'OracleLinux')
- name: restart ssh
service: name=ssh state=restarted
when: (ansible_distribution == 'Debian') or (ansible_distribution == 'Ubuntu')