Skip to content

Commit

Permalink
CI: Refactor sshd configuration into a role
Browse files Browse the repository at this point in the history
Prep for applying it to macOS 13 GitHub runners.

refs mitogen-hq#1186
  • Loading branch information
moreati committed Nov 7, 2024
1 parent 9e0dad2 commit 8cfcb66
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
27 changes: 9 additions & 18 deletions tests/image_prep/_container_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@
gather_facts: true
vars:
distro: "{{ansible_distribution}}"
tasks:
- when: ansible_virtualization_type != "docker"
meta: end_play

pre_tasks:
- meta: end_play
when:
- ansible_facts.virtualization_type != "docker"

roles:
- role: sshd

tasks:
- name: Ensure requisite apt packages are installed
apt:
name: "{{ common_packages + packages }}"
Expand Down Expand Up @@ -134,10 +140,6 @@
content: |
i-am-mitogen-test-docker-image
- copy:
dest: /etc/ssh/banner.txt
src: ../data/docker/ssh_login_banner.txt

- name: Ensure /etc/sudoers.d exists
file:
state: directory
Expand Down Expand Up @@ -169,17 +171,6 @@
line: "%wheel ALL=(ALL) ALL"
when: ansible_os_family == 'RedHat'

- name: Enable SSH banner
lineinfile:
path: /etc/ssh/sshd_config
line: Banner /etc/ssh/banner.txt

- name: Allow remote SSH root login
lineinfile:
path: /etc/ssh/sshd_config
line: PermitRootLogin yes
regexp: '.*PermitRootLogin.*'

- name: Allow remote SSH root login
lineinfile:
path: /etc/pam.d/sshd
Expand Down
1 change: 1 addition & 0 deletions tests/image_prep/roles/sshd/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sshd_config_file: /etc/ssh/sshd_config
File renamed without changes.
18 changes: 18 additions & 0 deletions tests/image_prep/roles/sshd/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
- name: Create login banner
copy:
src: banner.txt
dest: /etc/ssh/banner.txt
mode: u=rw,go=r

- name: Configure sshd_config
lineinfile:
path: "{{ sshd_config_file }}"
line: "{{ item.line }}"
regexp: "{{ item.regexp }}"
loop:
- line: Banner /etc/ssh/banner.txt
regexp: '^#? *Banner.*'
- line: PermitRootLogin yes
regexp: '.*PermitRootLogin.*'
loop_control:
label: "{{ item.line }}"

0 comments on commit 8cfcb66

Please sign in to comment.