feat(openssh): add ansible role
This commit is contained in:
28
roles/openssh/tasks/configure-sshd.yml
Normal file
28
roles/openssh/tasks/configure-sshd.yml
Normal file
@ -0,0 +1,28 @@
|
||||
---
|
||||
- name: Configure sshd
|
||||
ansible.builtin.lineinfile:
|
||||
path: "{{ openssh_sshd_config_file }}"
|
||||
regexp: "{{ openssh_sshd_config_regexp }}"
|
||||
line: "{{ openssh_sshd_config_line }}"
|
||||
firstmatch: true
|
||||
state: present
|
||||
validate: "sshd -Tf %s"
|
||||
loop: "{{ openssh_sshd_merged_config | dict2items }}"
|
||||
loop_control:
|
||||
loop_var: "tuple"
|
||||
label: "{{ tuple.key }}"
|
||||
notify:
|
||||
- openssh_sshd_reload
|
||||
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
|
||||
)
|
||||
}}
|
16
roles/openssh/tasks/install.yml
Normal file
16
roles/openssh/tasks/install.yml
Normal file
@ -0,0 +1,16 @@
|
||||
---
|
||||
- name: Ensure openssh server package is {{ openssh_state }} (dnf)
|
||||
ansible.builtin.dnf:
|
||||
name: "{{ openssh_packages[ansible_distribution | lower] }}"
|
||||
state: "{{ openssh_state }}"
|
||||
when:
|
||||
- ansible_facts['pkg_mgr'] in ['dnf', 'dnf5']
|
||||
- ansible_distribution | lower in openssh_packages.keys()
|
||||
|
||||
- name: Ensure openssh server package is {{ openssh_state }} (apt)
|
||||
ansible.builtin.apt:
|
||||
package: "{{ openssh_packages[ansible_distribution | lower] }}"
|
||||
state: "{{ openssh_state }}"
|
||||
when:
|
||||
- ansible_facts['pkg_mgr'] in ['apt']
|
||||
- ansible_distribution | lower in openssh_packages.keys()
|
15
roles/openssh/tasks/main.yml
Normal file
15
roles/openssh/tasks/main.yml
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
- name: Ensure 'openssh_state' is valid
|
||||
ansible.builtin.fail:
|
||||
msg: >-2
|
||||
Invalid value '{{ openssh_state }}' for 'openssh_state'.
|
||||
Valid values are {{ openssh_states | join(', ') }}!
|
||||
when: openssh_state not in openssh_states
|
||||
|
||||
- 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