1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_sshd.git synced 2024-08-16 11:59:49 +02:00

create mechanism to get openssh-server version

This commit is contained in:
L3D 2020-08-05 15:22:13 +02:00 committed by L3D
parent 132e656992
commit 50f3287641
No known key found for this signature in database
GPG key ID: 5215C3441797AB2B
11 changed files with 75 additions and 44 deletions

View file

@ -63,5 +63,7 @@ sshd__allowed_groups:
- "admins"
sshd__xforwarding: True
sshd__state: present # use latest for upgrading
# perform simple version check for this role? (true is recomended)
submodules_versioncheck: false

View file

@ -1,5 +1,5 @@
---
- name: systemctrl restart ssh
- name: systemctl restart ssh
become: yes
service:
name: "{{ sshd__service }}"

43
tasks/keys.yml Normal file
View file

@ -0,0 +1,43 @@
---
- name: Generate new ssh host key pair if necessary
become: yes
command: ssh-keygen -t ecdsa -f 'ssh_host_{{ item }}_key' -P '' -q
args:
chdir: '/etc/ssh/'
creates: 'ssh_host_{{ item }}_key.pub'
notify:
- systemctl restart ssh
with_items: "{{ sshd__key_types }}"
when:
- sshd__manage_key_types | bool
- name: Remove unwanted host keys
become: yes
file:
path: '/etc/ssh/ssh_host_{{ item }}_key'
state: absent
with_items:
- rsa
- dsa
notify:
- systemctl restart ssh
- name: make sure the correct keys are available
file:
path: '/etc/ssh/ssh_host_{{ item }}_key'
state: absent
become: yes
with_items:
- "{{ sshd__key_types_list | difference( sshd__key_types ) }}"
notify:
- systemctl restart ssh
- name: make sure the correct pubkeys are available
file:
path: '/etc/ssh/ssh_host_{{ item }}_key.pub'
state: absent
become: yes
with_items:
- "{{ sshd__key_types_list | difference( sshd__key_types ) }}"
notify:
- systemctl restart ssh

View file

@ -2,6 +2,12 @@
- include_tasks: versioncheck.yml
when: submodules_versioncheck|bool
- name: Gather the package facts
package_facts:
manager: auto
- include_tasks: packages.yml
- name: set sshd_service variable
block:
- name: read os specific variable
@ -15,48 +21,12 @@
sshd__allowed_users: '{{ sshd__allowed_users + users.keys() | default({}) | sort }}'
sshd__allowed_groups: '{{ sshd__allowed_groups + users.keys() | default({}) | sort }}'
- name: Generate new ssh host key pair if necessary
become: yes
command: ssh-keygen -t ecdsa -f 'ssh_host_{{ item }}_key' -P '' -q
args:
chdir: '/etc/ssh/'
creates: 'ssh_host_{{ item }}_key.pub'
notify:
- systemctrl restart ssh
with_items: "{{ sshd__key_types }}"
when:
- sshd__manage_key_types | bool
- name: "get package version of {{ sshd__package }}"
debug:
msg: "{{ ansible_facts.packages[sshd__package][0].version }}"
when: "'{{ sshd__package }}' in ansible_facts.packages"
- name: Remove unwanted host keys
become: yes
file:
path: '/etc/ssh/ssh_host_{{ item }}_key'
state: absent
with_items:
- rsa
- dsa
notify:
- systemctrl restart ssh
- name: make sure the correct keys are available
file:
path: '/etc/ssh/ssh_host_{{ item }}_key'
state: absent
become: yes
with_items:
- "{{ sshd__key_types_list | difference( sshd__key_types ) }}"
notify:
- systemctrl restart ssh
- name: make sure the correct pubkeys are available
file:
path: '/etc/ssh/ssh_host_{{ item }}_key.pub'
state: absent
become: yes
with_items:
- "{{ sshd__key_types_list | difference( sshd__key_types ) }}"
notify:
- systemctrl restart ssh
- include_tasks: keys.yml
- name: Copy sshd configuration
become: yes
@ -69,4 +39,4 @@
validate: /usr/sbin/sshd -t -f %s
backup: yes
notify:
- systemctrl restart ssh
- systemctl restart ssh

6
tasks/packages.yml Normal file
View file

@ -0,0 +1,6 @@
---
- name: "install {{ sshd__package }}"
become: true
package:
name: "{{ sshd__package }}"
state: "{{ sshd_state }}"

View file

@ -1,3 +1,3 @@
---
playbook_version_number: 2070 # should be over ninethousand
playbook_version_number: 2075 # should be over ninethousand
playbook_version_path: 'role-sshd_chaos-bodensee_github.com.version'

View file

@ -8,3 +8,5 @@ sshd__key_types_list:
sshd__xauth:
- xorg-xauth
sshd__package: 'openssh-server'

View file

@ -8,3 +8,5 @@ sshd__key_types_list:
sshd__xauth:
- xorg-xauth
sshd__package: 'openssh-server'

View file

@ -8,3 +8,5 @@ sshd__key_types_list:
sshd__xauth:
- xorg-xauth
sshd__package: 'openssh-server'

View file

@ -8,3 +8,5 @@ sshd__key_types_list:
sshd__xauth:
- xorg-xauth
sshd__package: 'openssh-server'

View file

@ -8,3 +8,5 @@ sshd__key_types_list:
sshd__xauth:
- xorg-xauth
sshd__package: 'openssh-server'