From 1c2dc323e7045317e9190404be78a6d5a725984b Mon Sep 17 00:00:00 2001 From: L3D Date: Wed, 10 Mar 2021 22:34:42 +0100 Subject: [PATCH] use new ansible syntax --- handlers/main.yml | 2 +- tasks/main.yml | 36 ++++++++++++++---------------------- tasks/packages.yml | 2 +- vars/main.yml | 9 ++++++++- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index e8f3bb5..2ebe567 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,7 +1,7 @@ --- - name: systemctl restart ssh become: yes - service: + ansible.builtin.systemd: name: "{{ sshd__service }}" state: restarted when: sshd__service is defined diff --git a/tasks/main.yml b/tasks/main.yml index fc23d60..ae79b2a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -3,20 +3,11 @@ ansible.builtin.include_tasks: versioncheck.yml when: submodules_versioncheck|bool -- name: Gather the package facts - package_facts: - manager: auto - failed_when: false +- name: load sshd_service variable + ansible.builtin.include_vars: "{{ lookup('first_found', sshd__service_var_path) }}" -- name: set sshd_service variable - block: - - 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: install packages + ansible.builtin.include_tasks: packages.yml - name: Collect all users and groups allowed to login via ssh set_fact: @@ -27,32 +18,33 @@ when: sshd__version_is_above_eight is not defined block: - name: Gather the package facts - package_facts: + ansible.builtin.package_facts: manager: auto - name: "get package version of {{ sshd__package }}" - debug: + ansible.builtin.debug: msg: "{{ ansible_facts.packages[sshd__package][0].version }}" - name: set fact sshd__version_is_above_eight - set_fact: + ansible.builtin.set_fact: sshd__version_is_above_eight: true when: ansible_facts.packages[sshd__package][0].version is version('8.0', '>=') 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" -- include_tasks: keys.yml +- name: manage ssh host keys + ansible.builtin.include_tasks: keys.yml - name: Create sshd configuration - become: yes - template: - src: sshd_config.j2 + become: true + ansible.builtin.template: + src: 'templates/sshd_config.j2' dest: '/etc/ssh/sshd_config' owner: root group: root mode: 'u=rw,g=r,o=r' validate: /usr/sbin/sshd -t -f %s - backup: yes + backup: true notify: - systemctl restart ssh diff --git a/tasks/packages.yml b/tasks/packages.yml index 493387e..62b2092 100644 --- a/tasks/packages.yml +++ b/tasks/packages.yml @@ -1,6 +1,6 @@ --- - name: install openssh server become: true - package: + ansible.builtin.package: name: "{{ sshd__package }}" state: "{{ sshd__state }}" diff --git a/vars/main.yml b/vars/main.yml index 12ea23e..d9c7d42 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -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' + +sshd__service_var_path: + files: + - "sshd_{{ ansible_distribution | lower }}" + - 'sshd_default.yml' + paths: + - 'vars'