Skip to content

Commit 2a6240a

Browse files
committed
refactor config export task, enable sshd
1 parent fbc47d6 commit 2a6240a

File tree

4 files changed

+80
-17
lines changed

4 files changed

+80
-17
lines changed

ansible/roles/compute_init/files/compute-init.yml

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
enable_resolv_conf: "{{ os_metadata.meta.resolv_conf | default(false) | bool }}"
1111
enable_etc_hosts: "{{ os_metadata.meta.etc_hosts | default(false) | bool }}"
1212
enable_sssd: "{{ os_metadata.meta.sssd | default(false) | bool }}"
13+
enable_sshd: "{{ os_metadata.meta.sshd | default(false) | bool }}"
1314
enable_tuned: "{{ os_metadata.meta.tuned | default(false) | bool }}"
1415
enable_nfs: "{{ os_metadata.meta.nfs | default(false) | bool }}"
1516
enable_manila: "{{ os_metadata.meta.manila | default(false) | bool }}"
@@ -24,6 +25,9 @@
2425
sssd_started: true
2526
sssd_enabled: true
2627

28+
sshd_password_authentication: false
29+
sshd_conf_dest: /etc/ssh/sshd_config.d/10-ansible.conf
30+
2731
tuned_profile_baremetal: hpc-compute
2832
tuned_profile_vm: virtual-guest
2933
tuned_profile: "{{ tuned_profile_baremetal if ansible_virtualization_role != 'guest' else tuned_profile_vm }}"
@@ -141,8 +145,8 @@
141145
- name: Configure sssd
142146
block:
143147
- name: Manage sssd.conf configuration
144-
ansible.builtin.template:
145-
src: "/mnt/cluster/hostconfig/{{ ansible_hostname }}/sssd.conf.j2"
148+
copy:
149+
src: "/mnt/cluster/hostconfig/{{ ansible_hostname }}/sssd.conf"
146150
dest: "{{ sssd_conf_dest }}"
147151
owner: root
148152
group: root
@@ -179,6 +183,51 @@
179183
enabled: "{{ sssd_enable_mkhomedir }}"
180184
when: enable_sssd
181185

186+
- name: Configure sshd
187+
block:
188+
- name: Grab facts to determine distribution
189+
setup:
190+
191+
- name: Ensure drop in directory exists
192+
file:
193+
path: /etc/ssh/sshd_config.d/*.conf
194+
state: directory
195+
owner: root
196+
group: root
197+
mode: "0700"
198+
199+
- name: Ensure drop in directory is included
200+
blockinfile:
201+
dest: /etc/ssh/sshd_config
202+
content: |
203+
# To modify the system-wide sshd configuration, create a *.conf file under
204+
# /etc/ssh/sshd_config.d/ which will be automatically included below
205+
Include /etc/ssh/sshd_config.d/*.conf
206+
state: present
207+
insertafter: "# default value."
208+
validate: sshd -t -f %s
209+
when: ansible_facts.distribution_major_version == '8'
210+
211+
- name: Restart sshd
212+
systemd:
213+
name: sshd
214+
state: restarted
215+
216+
- name: Manage sshd.conf configuration
217+
copy:
218+
src: "/mnt/cluster/hostconfig/{{ ansible_hostname }}/sshd.conf"
219+
dest: "{{ sshd_conf_dest }}"
220+
owner: root
221+
group: root
222+
mode: "0600"
223+
validate: sshd -t -f %s
224+
225+
- name: Restart sshd
226+
systemd:
227+
name: sshd
228+
state: restarted
229+
when: enable_sshd
230+
182231
- name: Configure tuned
183232
include_tasks: tasks/tuned.yml
184233
when: enable_tuned

ansible/roles/compute_init/tasks/export.yml

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,12 @@
8181
mode: u=rw,go=
8282
delegate_to: "{{ groups['control'] | first }}"
8383

84-
- name: Inject host specific config template files
85-
copy:
86-
src: "{{ item.src }}"
87-
dest: "/exports/cluster/hostconfig/{{ inventory_hostname }}/{{ item.dest }}"
88-
owner: root
89-
group: root
90-
mode: u=rw,go=
91-
loop:
92-
- src: "{{ sssd_conf_src | default('') }}"
93-
dest: sssd.conf.j2
94-
- src: "{{ sshd_conf_src | default('') }}"
95-
dest: sshd.conf.j2
96-
when:
97-
- item.src != ''
98-
delegate_to: "{{ groups['control'] | first }}"
84+
- name: Template sssd config
85+
import_role:
86+
name: sssd
87+
tasks_from: export.yml
88+
89+
- name: Template sshd config
90+
import_role:
91+
name: sshd
92+
tasks_from: export.yml
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- name: Inject host specific config template
2+
template:
3+
src: "{{ sshd_conf_src | default('') }}"
4+
dest: "/exports/cluster/hostconfig/{{ inventory_hostname }}/sshd.conf"
5+
owner: root
6+
group: root
7+
mode: u=rw,go=
8+
when:
9+
- sshd_conf_src != ''
10+
delegate_to: "{{ groups['control'] | first }}"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- name: Inject host specific config template
2+
template:
3+
src: "{{ sssd_conf_src | default('') }}"
4+
dest: "/exports/cluster/hostconfig/{{ inventory_hostname }}/sssd.conf"
5+
owner: root
6+
group: root
7+
mode: u=rw,go=
8+
when:
9+
- sssd_conf_src != ''
10+
delegate_to: "{{ groups['control'] | first }}"

0 commit comments

Comments
 (0)