This repository has been archived on 2022-07-19. You can view files and clone it, but cannot push or open issues or pull requests.
autonomic.sshd/tasks/main.yml

47 lines
1.2 KiB
YAML
Raw Normal View History

2022-05-30 11:44:52 +00:00
---
2022-05-30 11:55:29 +00:00
- name: Ensure mandatory variables are configured
assert:
that: "{{ item }} is defined"
fail_msg: "You must define the '{{ item }}' variable"
with_items:
2022-05-31 07:12:56 +00:00
- sshd_user_accounts
2022-05-30 11:55:29 +00:00
2022-05-30 11:44:52 +00:00
- name: Disable root SSH login
lineinfile:
line: PermitRootLogin no
dest: /etc/ssh/sshd_config
regexp: "^#?PermitRootLogin"
when: not sshd_permit_root_login
notify: Restart SSH
- name: Do not allow SSH access using passwords
lineinfile:
line: PasswordAuthentication no
dest: /etc/ssh/sshd_config
regexp: "^#?PasswordAuthentication"
notify: Restart SSH
2022-05-30 11:55:29 +00:00
- name: Include resource variables
2022-05-31 07:12:56 +00:00
include_vars: "{{ sshd_user_accounts }}"
2022-05-30 11:55:29 +00:00
tags:
# Note(d1): we already load in converge.yml so skip here
- molecule-notest
2022-05-30 11:44:52 +00:00
2022-05-30 11:55:29 +00:00
- name: Register the list of members
2022-05-30 11:44:52 +00:00
set_fact:
2022-05-30 11:55:29 +00:00
members_list: "{{ members | map(attribute='username') | list | join(' ') }}"
2022-05-30 11:44:52 +00:00
- name: "Only allow logins from {{ members_list }}"
lineinfile:
line: "AllowUsers {{ members_list }}"
dest: /etc/ssh/sshd_config
regexp: "^#?AllowUsers"
notify: Restart SSH
- name: "Set SSH port to {{ sshd_port }}"
lineinfile:
line: "Port {{ sshd_port }}"
dest: /etc/ssh/sshd_config
regexp: "^#?Port"
notify: Restart SSH