Skip to content

Commit 1b83232

Browse files
committed
Merge branch 'main' into feat/k3s-bootstrap
2 parents 5fb1d33 + 30d6ce4 commit 1b83232

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

ansible/roles/basic_users/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
basic_users
33
===========
44

5-
Setup users on cluster nodes using `/etc/passwd` and manipulating `$HOME`, i.e. without requiring LDAP etc. Features:
5+
Setup users on cluster nodes using `/etc/passwd` and manipulating `$HOME`, i.e.
6+
without requiring LDAP etc. Features:
67
- UID/GID is consistent across cluster (and explicitly defined).
78
- SSH key generated and propagated to all nodes to allow login between cluster nodes.
89
- An "external" SSH key can be added to allow login from elsewhere.
9-
- Login to the control node is prevented.
10+
- Login to the control node is prevented (by default)
1011
- When deleting users, systemd user sessions are terminated first.
1112

1213
Requirements
1314
------------
14-
- $HOME (for normal users, i.e. not `centos`) is assumed to be on a shared filesystem.
15+
- `$HOME` (for normal users, i.e. not `rocky`) is assumed to be on a shared
16+
filesystem. Actions affecting that shared filesystem are run on a single host,
17+
see `basic_users_manage_homedir` below.
1518

1619
Role Variables
1720
--------------
@@ -22,9 +25,15 @@ Role Variables
2225
- `shell` if *not* set will be `/sbin/nologin` on the `control` node and the default shell on other users. Explicitly setting this defines the shell for all nodes.
2326
- An additional key `public_key` may optionally be specified to define a key to log into the cluster.
2427
- An additional key `sudo` may optionally be specified giving a string (possibly multiline) defining sudo rules to be templated.
28+
- `ssh_key_type` defaults to `ed25519` instead of the `ansible.builtin.user` default of `rsa`.
2529
- Any other keys may present for other purposes (i.e. not used by this role).
2630
- `basic_users_groups`: Optional, default empty list. A list of mappings defining information for each group. Mapping keys/values are passed through as parameters to [ansible.builtin.group](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/group_module.html) and default values are as given there.
2731
- `basic_users_override_sssd`: Optional bool, default false. Whether to disable `sssd` when ensuring users/groups exist with this role. Permits creating local users/groups even if they clash with users provided via sssd (e.g. from LDAP). Ignored if host is not in group `sssd` as well. Note with this option active `sssd` will be stopped and restarted each time this role is run.
32+
- `basic_users_manage_homedir`: Optional bool, must be true on a single host to
33+
determine which host runs tasks affecting the shared filesystem. The default
34+
is to use the first play host which is not the control node, because the
35+
default NFS configuration does not have the shared `/home` directory mounted
36+
on the control node.
2837

2938
Dependencies
3039
------------

ansible/roles/basic_users/defaults/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
basic_users_manage_homedir: "{{ (ansible_hostname == (ansible_play_hosts | first)) }}"
1+
basic_users_manage_homedir: "{{ ansible_hostname == (ansible_play_hosts | difference(groups['control']) | first) }}"
22
basic_users_userdefaults:
33
state: present
44
create_home: "{{ basic_users_manage_homedir }}"
55
generate_ssh_key: "{{ basic_users_manage_homedir }}"
66
ssh_key_comment: "{{ item.name }}"
7+
ssh_key_type: ed25519
78
shell: "{{'/sbin/nologin' if 'control' in group_names else omit }}"
89
basic_users_users: []
910
basic_users_groups: []

ansible/roles/basic_users/tasks/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,21 @@
4646
- item.state | default('present') == 'present'
4747
- item.public_key is defined
4848
- basic_users_manage_homedir
49-
run_once: true
5049

5150
- name: Write generated public key as authorized for SSH access
51+
# this only runs on the basic_users_manage_homedir so has registered var
52+
# from that host too
5253
authorized_key:
5354
user: "{{ item.name }}"
5455
state: present
5556
manage_dir: no
5657
key: "{{ item.ssh_public_key }}"
57-
loop: "{{ hostvars[ansible_play_hosts | first].basic_users_info.results }}"
58+
loop: "{{ basic_users_info.results }}"
5859
loop_control:
5960
label: "{{ item.name }}"
6061
when:
6162
- item.ssh_public_key is defined
6263
- basic_users_manage_homedir
63-
run_once: true
6464

6565
- name: Write sudo rules
6666
blockinfile:

environments/skeleton/{{cookiecutter.environment}}/tofu/control.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ resource "openstack_networking_port_v2" "control" {
1414
subnet_id = data.openstack_networking_subnet_v2.cluster_subnet[each.key].id
1515
}
1616

17-
security_group_ids = [for o in data.openstack_networking_secgroup_v2.nonlogin: o.id]
17+
port_security_enabled = lookup(each.value, "port_security_enabled", true)
18+
security_group_ids = lookup(each.value, "port_security_enabled", true) ? [for o in data.openstack_networking_secgroup_v2.nonlogin: o.id] : []
1819

1920
binding {
2021
vnic_type = lookup(var.vnic_types, each.key, "normal")

environments/skeleton/{{cookiecutter.environment}}/tofu/node_group/nodes.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ resource "openstack_networking_port_v2" "compute" {
4545
subnet_id = data.openstack_networking_subnet_v2.subnet[each.value.network].id
4646
}
4747

48-
security_group_ids = var.security_group_ids
48+
port_security_enabled = lookup(each.value, "port_security_enabled", true)
49+
security_group_ids = lookup(each.value, "port_security_enabled", true) ? var.security_group_ids : []
4950

5051
binding {
5152
vnic_type = lookup(var.vnic_types, each.value.network, "normal")

environments/skeleton/{{cookiecutter.environment}}/tofu/variables.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ variable "cluster_networks" {
1313
type = list(map(string))
1414
description = <<-EOT
1515
List of mappings defining networks. Mapping key/values:
16-
network: Name of existing network
17-
subnet: Name of existing subnet
16+
network: Required. Name of existing network
17+
subnet: Required. Name of existing subnet
18+
port_security_enabled: Optional. Bool, default true
1819
EOT
1920
}
2021

0 commit comments

Comments
 (0)