Skip to content

Commit be87279

Browse files
committedDec 4, 2023
Initial ansible files
0 parents  commit be87279

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
keys/*

‎ansible_defense.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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

‎handlers/restart.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- name: restart sshd
3+
ansible.builtin.service:
4+
name: sshd
5+
state: restarted

‎inventory.ini

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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

0 commit comments

Comments
 (0)
Please sign in to comment.