WIP: feat(openssh): add ansible role
This commit is contained in:
7
playbooks/openssh.yml
Normal file
7
playbooks/openssh.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
- name: Ensure openssh is installed and configured
|
||||||
|
hosts: "{{ openssh_target | default('openssh') }}"
|
||||||
|
become: "{{ openssh_become | default(true) }}"
|
||||||
|
gather_facts: "{{ openssh_gather_facts | default(true) }}"
|
||||||
|
roles:
|
||||||
|
- role: finallycoffee.base.openssh
|
2
roles/openssh/defaults/main/main.yml
Normal file
2
roles/openssh/defaults/main/main.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
openssh_sshd_config_file: "/etc/ssh/sshd_config"
|
33
roles/openssh/defaults/main/sshd.yml
Normal file
33
roles/openssh/defaults/main/sshd.yml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
---
|
||||||
|
openssh_sshd_enable: true
|
||||||
|
openssh_sshd_config_pubkey_authentication: true
|
||||||
|
openssh_sshd_config_password_authentication: false
|
||||||
|
openssh_sshd_config_challenge_response_authentication: false
|
||||||
|
openssh_sshd_config_permit_root_login: false
|
||||||
|
|
||||||
|
# Limits
|
||||||
|
openssh_sshd_config_max_sessions: ~
|
||||||
|
openssh_sshd_config_max_startups: ~
|
||||||
|
|
||||||
|
# Hardening
|
||||||
|
openssh_sshd_config_protocol: 2
|
||||||
|
openssh_sshd_config_x11_forwarding: false
|
||||||
|
openssh_sshd_config_allow_agent_forwarding: false
|
||||||
|
openssh_sshd_config_allow_tcp_forwarding: false
|
||||||
|
|
||||||
|
openssh_sshd_default_config:
|
||||||
|
PubkeyAuthentication: "{{ openssh_sshd_config_pubkey_authentication }}"
|
||||||
|
PasswordAuthentication: "{{ openssh_sshd_config_password_authentication }}"
|
||||||
|
ChallengeResponseAuthentication: >-2
|
||||||
|
{{ openssh_sshd_config_challenge_response_authentication }}
|
||||||
|
PermitRootLogin: "{{ openssh_sshd_config_permit_root_login }}"
|
||||||
|
MaxSessions: "{{ openssh_sshd_config_max_sessions }}"
|
||||||
|
MaxStartups: "{{ openssh_sshd_config_max_startups }}"
|
||||||
|
Protocol: "{{ openssh_sshd_config_protocol }}"
|
||||||
|
X11Forwarding: "{{ openssh_sshd_config_x11_forwarding }}"
|
||||||
|
AllowAgentForwarding: "{{ openssh_sshd_config_allow_agent_forwarding }}"
|
||||||
|
AllowTcpForwarding: "{{ openssh_sshd_config_allow_tcp_forwarding }}"
|
||||||
|
|
||||||
|
openssh_sshd_merged_config: >-2
|
||||||
|
{{ openssh_sshd_default_config | default({}, true)
|
||||||
|
| combine(openssh_sshd_config | default({}, true)) }}
|
25
roles/openssh/tasks/configure-sshd.yml
Normal file
25
roles/openssh/tasks/configure-sshd.yml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
---
|
||||||
|
- name: Configure sshd
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: "{{ openssh_sshd_config_file }}"
|
||||||
|
regexp: "{{ openssh_sshd_config_regexp }}"
|
||||||
|
line: "{{ openssh_sshd_config_line }}"
|
||||||
|
state: present
|
||||||
|
validate: "sshd -Tf %s"
|
||||||
|
loop: "{{ openssh_sshd_merged_config | dict2items }}"
|
||||||
|
loop_control:
|
||||||
|
loop_var: "tuple"
|
||||||
|
label: "{{ tuple.key }}"
|
||||||
|
vars:
|
||||||
|
openssh_sshd_config_regexp: "^\\s*#?\\s*{{ tuple.key }}"
|
||||||
|
openssh_sshd_config_line: >-2
|
||||||
|
{{ openssh_sshd_config_line_commented }}{{ tuple.key }} {{ openssh_sshd_config_value }}
|
||||||
|
openssh_sshd_config_value_is_none: "{{ tuple.value is none }}"
|
||||||
|
openssh_sshd_config_line_commented: >-2
|
||||||
|
{{ openssh_sshd_config_value_is_none | ternary('#', '') }}
|
||||||
|
openssh_sshd_config_value: >-2
|
||||||
|
{{ (tuple.value is boolean) | ternary(
|
||||||
|
tuple.value | ternary('yes', 'no'),
|
||||||
|
tuple.value
|
||||||
|
)
|
||||||
|
}}
|
2
roles/openssh/tasks/install.yml
Normal file
2
roles/openssh/tasks/install.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
|
8
roles/openssh/tasks/main.yml
Normal file
8
roles/openssh/tasks/main.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
- name: Ensure openssh is {{ openssh_state }}
|
||||||
|
ansible.builtin.include_tasks:
|
||||||
|
file: "install.yml"
|
||||||
|
|
||||||
|
- name: Ensure sshd is configured
|
||||||
|
ansible.builtin.include_tasks:
|
||||||
|
file: "configure-sshd.yml"
|
Reference in New Issue
Block a user