v0.1
This commit is contained in:
51
playbooks/roles/ssh/tasks/SSH-playbook.yaml.examples
Normal file
51
playbooks/roles/ssh/tasks/SSH-playbook.yaml.examples
Normal file
@@ -0,0 +1,51 @@
|
||||
---
|
||||
- name: Configure SSH
|
||||
hosts: main_server
|
||||
become: yes
|
||||
tasks:
|
||||
- name: Change SSH port
|
||||
lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
regexp: '^#?Port'
|
||||
line: "Port {{ main_ssh_port }}"
|
||||
|
||||
- name: Secure SSH config
|
||||
lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
regexp: "^{{ item.regexp }}"
|
||||
line: "{{ item.line }}"
|
||||
loop:
|
||||
- { regexp: '^#?PermitRootLogin', line: 'PermitRootLogin no' }
|
||||
- { regexp: '^#?PubkeyAuthentication', line: 'PubkeyAuthentication yes' }
|
||||
- { regexp: '^#?PasswordAuthentication', line: 'PasswordAuthentication no' }
|
||||
|
||||
- name: Setup SSH keys
|
||||
authorized_key:
|
||||
user: "{{ item }}"
|
||||
state: present
|
||||
key: "{{ user_ssh_key }}"
|
||||
loop:
|
||||
- "{{ ansible_user }}"
|
||||
- "{{ new_user}}"
|
||||
|
||||
- name: Reload SSH
|
||||
service:
|
||||
name: ssh
|
||||
state: reloaded
|
||||
|
||||
- name: Ensure SSH service is running
|
||||
ansible.builtin.service:
|
||||
name: ssh
|
||||
state: restarted
|
||||
enabled: true
|
||||
|
||||
- name: Check if SSH is listening on the correct port
|
||||
become: yes
|
||||
shell: "ss -tulpn | grep :{{ main_ssh_port }}"
|
||||
register: ssh_port_check
|
||||
|
||||
- name: show SSH port
|
||||
debug:
|
||||
var: ssh_port_check.stdout
|
||||
|
||||
|
34
playbooks/roles/ssh/tasks/main.yml
Normal file
34
playbooks/roles/ssh/tasks/main.yml
Normal file
@@ -0,0 +1,34 @@
|
||||
---
|
||||
- name: Install SSH
|
||||
ansible.builtin.package:
|
||||
name:
|
||||
- openssh-server
|
||||
|
||||
state: present
|
||||
|
||||
- name: Change SSH port
|
||||
lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
regexp: '^#?Port'
|
||||
line: "Port {{ ports.main_ssh_port.port }}"
|
||||
|
||||
- name: Secure SSH config
|
||||
lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
regexp: "^{{ item.regexp }}"
|
||||
line: "{{ item.line }}"
|
||||
loop:
|
||||
- { regexp: '^#?PermitRootLogin', line: 'PermitRootLogin no' }
|
||||
- { regexp: '^#?PubkeyAuthentication', line: 'PubkeyAuthentication yes' }
|
||||
- { regexp: '^#?PasswordAuthentication', line: 'PasswordAuthentication no' }
|
||||
|
||||
- name: Setup SSH keys
|
||||
authorized_key:
|
||||
user: "{{ main_user }}"
|
||||
key: "{{ main_user_ssh_key }}"
|
||||
|
||||
- name: Reload SSH
|
||||
service:
|
||||
name: ssh
|
||||
state: reloaded
|
||||
enabled: true
|
Reference in New Issue
Block a user