fix role and ansible-lint errors

This commit is contained in:
Sergey Malyuk
2025-12-18 11:54:32 +03:00
parent 2c4b30314b
commit 14bcc89e5d
7 changed files with 25 additions and 14 deletions

View File

@@ -1,5 +1,5 @@
---
disable_pam: false
password_auth: false
challenge_response_auth: false
gss_api_auth: false
sshd_disable_pam: false
sshd_password_auth: false
sshd_challenge_response_auth: false
sshd_gss_api_auth: false

View File

@@ -10,8 +10,8 @@ galaxy_info:
platforms:
- name: "Ubuntu"
versions: [ "focal", "jammy" ]
versions: ["focal", "jammy"]
galaxy_tags: [ ]
galaxy_tags: []
dependencies: []

View File

@@ -6,5 +6,6 @@
any_errors_fatal: true
tasks:
- name: blank
- name: Blank
ansible.builtin.command: echo
changed_when: false

View File

@@ -1,4 +1,13 @@
---
# next task requires this directory to exist for sshd -t flag
- name: Ensure /run/sshd exists
ansible.builtin.file:
path: /run/sshd
state: directory
owner: root
group: root
mode: '0755'
# NOTE: order of preference for openssh-server ed25519 -> rsa
- name: "Algorithms | enable ed25519 authentication algorithm"
notify: Restart sshd

View File

@@ -3,13 +3,13 @@
notify: Restart sshd
loop:
- { regexp: '^#?\s*PubkeyAuthentication\s+', line: 'PubkeyAuthentication yes' }
- { regexp: '^#?\s*PasswordAuthentication\s+', line: 'PasswordAuthentication {{ password_auth | ternary("yes", "no") }}' }
- { regexp: '^#?\s*PasswordAuthentication\s+', line: 'PasswordAuthentication {{ sshd_password_auth | ternary("yes", "no") }}' }
- { regexp: '^#?\s*PermitEmptyPasswords\s+', line: 'PermitEmptyPasswords no' }
- { regexp: '^#?\s*ChallengeResponseAuthentication\s+', line: 'ChallengeResponseAuthentication {{ challenge_response_auth | ternary("yes", "no") }}' }
- { regexp: '^#?\s*GSSAPIAuthentication\s+', line: 'GSSAPIAuthentication {{ gss_api_auth | ternary("yes", "no") }}' }
- { regexp: '^#?\s*ChallengeResponseAuthentication\s+', line: 'ChallengeResponseAuthentication {{ sshd_challenge_response_auth | ternary("yes", "no") }}' }
- { regexp: '^#?\s*GSSAPIAuthentication\s+', line: 'GSSAPIAuthentication {{ sshd_gss_api_auth | ternary("yes", "no") }}' }
- {
regexp: '^#?\s*AuthenticationMethods\s+',
line: "{{ 'AuthenticationMethods publickey password' if password_auth else 'AuthenticationMethods publickey' }}"
line: "{{ 'AuthenticationMethods publickey password' if sshd_password_auth else 'AuthenticationMethods publickey' }}"
}
ansible.builtin.lineinfile:
path: /etc/ssh/sshd_config
@@ -22,10 +22,10 @@
ansible.builtin.stat:
path: "/etc/ssh/sshd_config.d/50-cloud-init.conf"
- name: "Authentication | override password authentication by cloud-init to '{{ password_auth | ternary('yes', 'no') }}'"
- name: "Authentication | override password authentication by cloud-init to '{{ sshd_password_auth | ternary('yes', 'no') }}'"
when: sshd_cloud_init.stat.exists
notify: Restart sshd
ansible.builtin.lineinfile:
path: "/etc/ssh/sshd_config.d/50-cloud-init.conf"
regexp: '^#?PasswordAuthentication'
line: 'PasswordAuthentication {{ password_auth | ternary("yes", "no") }}'
line: 'PasswordAuthentication {{ sshd_password_auth | ternary("yes", "no") }}'

View File

@@ -10,3 +10,4 @@
ansible.builtin.apt:
name: openssh-server
state: present
update_cache: true

View File

@@ -18,7 +18,7 @@
ansible.builtin.lineinfile:
path: /etc/ssh/sshd_config
regexp: '^#?UsePAM'
line: "UsePAM {{ disable_pam | ternary('no', 'yes') }}"
line: "UsePAM {{ sshd_disable_pam | ternary('no', 'yes') }}"
validate: sshd -f %s -t
- name: "Restrictions | ensure the SSHD config is restricted to the root user"