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

use new ansible syntax

This commit is contained in:
L3D 2021-03-10 22:34:42 +01:00
parent 8ca50abd38
commit 1c2dc323e7
Signed by: l3d
GPG key ID: CD08445BFF4313D1
4 changed files with 24 additions and 25 deletions

View file

@ -1,7 +1,7 @@
--- ---
- name: systemctl restart ssh - name: systemctl restart ssh
become: yes become: yes
service: ansible.builtin.systemd:
name: "{{ sshd__service }}" name: "{{ sshd__service }}"
state: restarted state: restarted
when: sshd__service is defined when: sshd__service is defined

View file

@ -3,20 +3,11 @@
ansible.builtin.include_tasks: versioncheck.yml ansible.builtin.include_tasks: versioncheck.yml
when: submodules_versioncheck|bool when: submodules_versioncheck|bool
- name: Gather the package facts - name: load sshd_service variable
package_facts: ansible.builtin.include_vars: "{{ lookup('first_found', sshd__service_var_path) }}"
manager: auto
failed_when: false
- name: set sshd_service variable - name: install packages
block: ansible.builtin.include_tasks: packages.yml
- name: read os specific variable
include_vars: "vars/sshd_{{ ansible_distribution | lower }}.yml"
rescue:
- name: read default variable
include_vars: vars/sshd_default.yml
- include_tasks: packages.yml
- name: Collect all users and groups allowed to login via ssh - name: Collect all users and groups allowed to login via ssh
set_fact: set_fact:
@ -27,32 +18,33 @@
when: sshd__version_is_above_eight is not defined when: sshd__version_is_above_eight is not defined
block: block:
- name: Gather the package facts - name: Gather the package facts
package_facts: ansible.builtin.package_facts:
manager: auto manager: auto
- name: "get package version of {{ sshd__package }}" - name: "get package version of {{ sshd__package }}"
debug: ansible.builtin.debug:
msg: "{{ ansible_facts.packages[sshd__package][0].version }}" msg: "{{ ansible_facts.packages[sshd__package][0].version }}"
- name: set fact sshd__version_is_above_eight - name: set fact sshd__version_is_above_eight
set_fact: ansible.builtin.set_fact:
sshd__version_is_above_eight: true sshd__version_is_above_eight: true
when: ansible_facts.packages[sshd__package][0].version is version('8.0', '>=') when: ansible_facts.packages[sshd__package][0].version is version('8.0', '>=')
rescue: rescue:
- debug: - ansible.builtin.debug:
msg: "Failed to detect ssh version. Set sshd__version_is_above_eight to true if you want to experience new config features from sshd version 8" msg: "Failed to detect ssh version. Set sshd__version_is_above_eight to true if you want to experience new config features from sshd version 8"
- include_tasks: keys.yml - name: manage ssh host keys
ansible.builtin.include_tasks: keys.yml
- name: Create sshd configuration - name: Create sshd configuration
become: yes become: true
template: ansible.builtin.template:
src: sshd_config.j2 src: 'templates/sshd_config.j2'
dest: '/etc/ssh/sshd_config' dest: '/etc/ssh/sshd_config'
owner: root owner: root
group: root group: root
mode: 'u=rw,g=r,o=r' mode: 'u=rw,g=r,o=r'
validate: /usr/sbin/sshd -t -f %s validate: /usr/sbin/sshd -t -f %s
backup: yes backup: true
notify: notify:
- systemctl restart ssh - systemctl restart ssh

View file

@ -1,6 +1,6 @@
--- ---
- name: install openssh server - name: install openssh server
become: true become: true
package: ansible.builtin.package:
name: "{{ sshd__package }}" name: "{{ sshd__package }}"
state: "{{ sshd__state }}" state: "{{ sshd__state }}"

View file

@ -1,3 +1,10 @@
--- ---
playbook_version_number: 4100 # should be over ninethousand playbook_version_number: 4101 # should be over ninethousand
playbook_version_path: 'role-sshd_chaos-bodensee_github.com.version' playbook_version_path: 'role-sshd_chaos-bodensee_github.com.version'
sshd__service_var_path:
files:
- "sshd_{{ ansible_distribution | lower }}"
- 'sshd_default.yml'
paths:
- 'vars'