diff --git a/playbooks/setup/server/natsuco.yaml b/playbooks/setup/server/natsuco.yaml index 40f8321..019cadd 100644 --- a/playbooks/setup/server/natsuco.yaml +++ b/playbooks/setup/server/natsuco.yaml @@ -5,23 +5,8 @@ ansible_user: root alt_ssh_port: 1023 name: setup server natsuco + + roles: + - kevinnlsamuel.galaxy.sshd.disablepasswd + - kevinnlsamuel.galaxy.sshd.altport tasks: - - name: harden ssh - block: - - name: disable password auth - include_role: - name: kevinnlsamuel.galaxy.sshd.disablepasswd - - name: change ssh port - when: false - template: - src: sshd/00-altport.conf - dest: /etc/ssh/ssh_config.d/00-altport.conf - - name: install semanage - dnf: - state: present - name: policycoreutils-python-utils - - name: give sshd access to alt port on selinux - register: result_change_to_alt_port - ignore_errors: true - changed_when: "'already defined' not in result_change_to_alt_port.stdout" - command: semanage port -a -t ssh_port_t -p tcp {{ alt_ssh_port }} diff --git a/roles/sshd/_handlers/main.yaml b/roles/sshd/_handlers/main.yaml new file mode 100644 index 0000000..6207454 --- /dev/null +++ b/roles/sshd/_handlers/main.yaml @@ -0,0 +1,5 @@ +--- +- name: restart sshd + service: + name: sshd + state: restarted diff --git a/roles/sshd/altport/handlers b/roles/sshd/altport/handlers new file mode 120000 index 0000000..93c5ad7 --- /dev/null +++ b/roles/sshd/altport/handlers @@ -0,0 +1 @@ +/home/kevins/Projects/galaxy/roles/sshd/_handlers \ No newline at end of file diff --git a/roles/sshd/altport/tasks/main.yaml b/roles/sshd/altport/tasks/main.yaml new file mode 100644 index 0000000..a35c7a9 --- /dev/null +++ b/roles/sshd/altport/tasks/main.yaml @@ -0,0 +1,16 @@ +--- +- name: change ssh port to {{ alt_ssh_port | mandatory }} + notify: restart sshd + template: + src: 00-altport.conf + dest: /etc/ssh/sshd_config.d/00-altport.conf +- name: install semanage + when: ansible_facts.selinux.status != 'disabled' + dnf: + state: present + name: policycoreutils-python-utils +- name: give sshd access to alt port on selinux + register: result_change_to_alt_port + ignore_errors: true + changed_when: "'already defined' not in result_change_to_alt_port.stdout" + command: semanage port -a -t ssh_port_t -p tcp {{ alt_ssh_port }} diff --git a/roles/sshd/altport/templates/00-altport.conf b/roles/sshd/altport/templates/00-altport.conf new file mode 100644 index 0000000..2f81a5f --- /dev/null +++ b/roles/sshd/altport/templates/00-altport.conf @@ -0,0 +1 @@ +Port {{ alt_ssh_port }} diff --git a/roles/sshd/disablepasswd/handlers b/roles/sshd/disablepasswd/handlers new file mode 120000 index 0000000..93c5ad7 --- /dev/null +++ b/roles/sshd/disablepasswd/handlers @@ -0,0 +1 @@ +/home/kevins/Projects/galaxy/roles/sshd/_handlers \ No newline at end of file diff --git a/roles/sshd/disablepasswd/meta/main.yml b/roles/sshd/disablepasswd/meta/main.yml deleted file mode 100644 index 9f28352..0000000 --- a/roles/sshd/disablepasswd/meta/main.yml +++ /dev/null @@ -1,6 +0,0 @@ -galaxy_info: - author: kevinnlsamuel - description: sayin hello -dependencies: - # List your role dependencies here, one per line. Be sure to remove the '[]' above, - # if you add dependencies to this list. diff --git a/roles/sshd/disablepasswd/tasks/main.yml b/roles/sshd/disablepasswd/tasks/main.yml index eea9095..e4fe58c 100644 --- a/roles/sshd/disablepasswd/tasks/main.yml +++ b/roles/sshd/disablepasswd/tasks/main.yml @@ -1,8 +1,5 @@ - name: disable password auth + notify: restart sshd copy: src: 00-nopasswd.conf dest: /etc/ssh/sshd_config.d/00-nopasswd.conf -- name: restart sshd - service: - name: sshd - state: restarted