Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Fixed ansible-lint problems
Browse files Browse the repository at this point in the history
  • Loading branch information
dmotte committed Jul 20, 2023
1 parent 4349ec9 commit 8da12c3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
---
strict: true
exclude_paths:
- .github/
14 changes: 7 additions & 7 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
private_dirs: []
sshd_addressfamily_inet: false
sshd_disable_psw_auth: false
disable_ipv6: false
hardening_private_dirs: []
hardening_sshd_addressfamily_inet: false
hardening_sshd_disable_psw_auth: false
hardening_disable_ipv6: false

restart_sshd_if_changed: true
restart_timesyncd_if_changed: true
reload_sysctl_if_changed: true
hardening_restart_sshd_if_changed: true
hardening_restart_timesyncd_if_changed: true
hardening_reload_sysctl_if_changed: true
6 changes: 3 additions & 3 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
ansible.builtin.service:
name: ssh
state: restarted
when: restart_sshd_if_changed
when: hardening_restart_sshd_if_changed

- name: Restart timesyncd
ansible.builtin.service:
name: systemd-timesyncd
state: restarted
when: restart_timesyncd_if_changed
when: hardening_restart_timesyncd_if_changed

- name: Reload the sysctl configuration
# We have to use the command here because (to date) the
# ansible.posix.sysctl module does not allow to force a reload
ansible.builtin.command:
cmd: sysctl --system
changed_when: false
when: reload_sysctl_if_changed
when: hardening_reload_sysctl_if_changed
10 changes: 5 additions & 5 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
path: "{{ item }}"
state: directory
mode: "0700"
loop: "{{ private_dirs }}"
loop: "{{ hardening_private_dirs }}"

- name: Set correct hostname in /etc/hosts
ansible.builtin.lineinfile:
Expand All @@ -42,15 +42,15 @@
path: /etc/ssh/sshd_config
regexp: "^#?AddressFamily"
line: AddressFamily inet
when: sshd_addressfamily_inet
when: hardening_sshd_addressfamily_inet
notify: Restart the ssh service

- name: In sshd_config, disable PasswordAuthentication
ansible.builtin.lineinfile:
path: /etc/ssh/sshd_config
regexp: "^#?PasswordAuthentication"
line: PasswordAuthentication no
when: sshd_disable_psw_auth
when: hardening_sshd_disable_psw_auth
notify: Restart the ssh service

- name: Force all notified handlers to run at this point
Expand Down Expand Up @@ -111,8 +111,8 @@
- name: Disable IPv6
ansible.builtin.include_role: { name: dmotte.disable_ipv6 }
vars:
disable_ipv6_reload_sysctl_if_changed: "{{ reload_sysctl_if_changed }}"
when: disable_ipv6
disable_ipv6_reload_sysctl_if_changed: "{{ hardening_reload_sysctl_if_changed }}"
when: hardening_disable_ipv6

- name: Force all notified handlers to run at this point
ansible.builtin.meta: flush_handlers
16 changes: 8 additions & 8 deletions test/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
tasks:
- name: Include the role from the parent directory
ansible.builtin.include_role: { name: "{{ playbook_dir | dirname }}" }
vars:
vars: # noqa: var-naming[no-role-prefix]
ansible_become: true
private_dirs: ["/home/{{ ansible_user_id }}"]
sshd_addressfamily_inet: true
sshd_disable_psw_auth: false
disable_ipv6: true
restart_sshd_if_changed: true
restart_timesyncd_if_changed: true
reload_sysctl_if_changed: true
hardening_private_dirs: ["/home/{{ ansible_user_id }}"]
hardening_sshd_addressfamily_inet: true
hardening_sshd_disable_psw_auth: false
hardening_disable_ipv6: true
hardening_restart_sshd_if_changed: true
hardening_restart_timesyncd_if_changed: true
hardening_reload_sysctl_if_changed: true

0 comments on commit 8da12c3

Please sign in to comment.