Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix service files generated on EL7 and workaround the tests for containers #276

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tasks/install_service.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
- name: Install systemd service files
when: sshd_install_service | bool and ansible_facts['service_mgr'] == 'systemd'
when:
- sshd_install_service | bool
- ansible_facts['service_mgr'] == 'systemd' or
(ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '7')
block:
- name: Install service unit file
ansible.builtin.template:
Expand Down
2 changes: 1 addition & 1 deletion templates/sshd.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Documentation=man:sshd(8) man:sshd_config(5)
[Service]
Type=notify
{% if __sshd_environment_file is string %}
EnvironmentFile=-{{ __sshd_environment_file }}
EnvironmentFile={{ __sshd_environment_file_mandatory | ternary('', '-')}}{{ __sshd_environment_file }}
{% elif __sshd_environment_file is iterable %}
{% for file in __sshd_environment_file %}
EnvironmentFile=-{{ file }}
Expand Down
7 changes: 4 additions & 3 deletions tests/tests_systemd_services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
- name: Read the service files and verify they are reasonable
tags: tests::verify
when:
- ansible_facts['service_mgr'] == 'systemd'
- ansible_facts['service_mgr'] == 'systemd' or
(ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '7')
block:
- name: Read the distribution service file
ansible.builtin.slurp:
Expand Down Expand Up @@ -114,7 +115,8 @@
- name: Read the instantiated service file and verify they are reasonable
tags: tests::verify
when:
- ansible_facts['service_mgr'] == 'systemd'
- ansible_facts['service_mgr'] == 'systemd' or
(ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '7')
- ansible_facts['distribution'] != "Debian" or ansible_facts['distribution_major_version'] | int < 12
block:
- name: Read the distribution instantiated service file
Expand Down Expand Up @@ -154,6 +156,5 @@
that:
- "' -f /etc/ssh/' in service_inst.content | b64decode"


- name: "Restore configuration files"
ansible.builtin.include_tasks: tasks/restore.yml
1 change: 1 addition & 0 deletions vars/RedHat_7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ __sshd_hostkeys_nofips:
- /etc/ssh/ssh_host_ed25519_key

__sshd_environment_file: /etc/sysconfig/sshd
__sshd_environment_file_mandatory: true
__sshd_environment_variable: $OPTIONS
__sshd_service_after: sshd-keygen.service
__sshd_service_wants: sshd-keygen.service
Expand Down
1 change: 1 addition & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ __sshd_supports_validate: true

# The path to an environment file for the SSHD service
__sshd_environment_file: ~
__sshd_environment_file_mandatory: false

# The variable name we are passing from the environment file as an argument to the sshd
__sshd_environment_variable: $OPTIONS
Expand Down