Create systemd unit to create rke user

This commit is contained in:
Gerald Pinder
2025-05-11 13:22:52 -04:00
parent ad73e87daa
commit f25c8be0f9
4 changed files with 40 additions and 1 deletions

View File

@@ -0,0 +1,3 @@
Cmnd_Alias RKE_CMDS = /usr/bin/chown, /usr/bin/chmod, /usr/bin/mkdir, /usr/bin/systemctl, /usr/bin/cp, /usr/bin/find, /usr/bin/ls, /usr/bin/reboot, /usr/bin/install, /usr/bin/rke2, /usr/bin/firewall-cmd
rke ALL=(root) NOPASSWD: RKE_CMDS

View File

@@ -0,0 +1,16 @@
[Unit]
Description=Create 'rke' user and add to docker group
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/libexec/rke2/create-rke-user.sh
RemainAfterExit=yes
# Disable and mask the service after successful execution
ExecStartPost=-/bin/systemctl disable --now create-rke-user.service
ExecStartPost=-/bin/systemctl mask --now create-rke-user.service
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,15 @@
#!/bin/bash
# Check if user 'rke' exists
if ! id -u rke &> /dev/null; then
echo "Creating user 'rke'"
# Create user 'rke' with home directory using useradd
sudo useradd --system -m rke
fi
# Add 'rke' to docker group
echo "Adding 'rke' to docker group"
sudo usermod -aG docker rke
echo "Done"
exit 0

View File

@@ -1,7 +1,6 @@
modules: modules:
- from-file: common/common.yml - from-file: common/common.yml
- type: dnf - type: dnf
# source: local
repos: repos:
cleanup: true cleanup: true
files: files:
@@ -27,10 +26,16 @@ modules:
- type: script - type: script
snippets: snippets:
- curl -sfL https://get.rke2.io | sh - curl -sfL https://get.rke2.io | sh
- sed -i 's|#includedir /etc/sudoers.d|includedir /etc/sudoers.d|' /etc/sudoers
- type: files
files:
- source: rke_setup
destination: /
- type: systemd - type: systemd
system: system:
enabled: enabled:
- docker.service - docker.service
- create_rke_user.service
- from-file: common/updates.yml - from-file: common/updates.yml
- from-file: common/bluebuild-logo.yml - from-file: common/bluebuild-logo.yml
- from-file: common/jp-chezmoi.yml - from-file: common/jp-chezmoi.yml