File tree 4 files changed +45
-0
lines changed
4 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ keys /*
Original file line number Diff line number Diff line change
1
+ ---
2
+ - name : Update servers
3
+ vars :
4
+ p : " super_secret"
5
+ hosts : servers
6
+ tasks :
7
+ - name : Update password
8
+ ansible.builtin.user :
9
+ name : root
10
+ password : " {{ p | password_hash('sha512') }}"
11
+ state : present
12
+ - name : Place ssh key
13
+ authorized_key :
14
+ user : " root"
15
+ key : " {{ lookup('file', './keys/ansible.pub') }}"
16
+ state : present
17
+ - name : Change ssh_config
18
+ lineinfile :
19
+ path : " /etc/ssh/sshd_config"
20
+ regex : " ^(#)?{{item.key}}"
21
+ line : " {{item.key}} {{item.value}}"
22
+ state : present
23
+ loop :
24
+ - { key: "PermitRootLogin", value: "yes" }
25
+ - { key: "AuthenticationMethods", value: "publickey" }
26
+ - { key: "PasswordAuthentication", value: "no" }
27
+ - { key: "PubkeyAuthentication", value: "yes" }
28
+ - { key: "PermitEmptyPasswords", value: "no" }
29
+ notify :
30
+ - restart sshd
Original file line number Diff line number Diff line change
1
+ ---
2
+ - name : restart sshd
3
+ ansible.builtin.service :
4
+ name : sshd
5
+ state : restarted
Original file line number Diff line number Diff line change
1
+ [servers:vars]
2
+ # ansible_connection=ssh
3
+ ansible_user =notroot
4
+ ansible_ssh_pass =bingbong1
5
+ ansible_sudo_pass =bingbong1
6
+ key_file =" ./ansible"
7
+
8
+ [servers]
9
+ 10.16.0.5 ansible_become =true
You can’t perform that action at this time.
0 commit comments