add backup control user to start/stop virtual machines

This commit is contained in:
Pim Kunis 2023-04-11 21:18:03 +02:00
parent c9baaa2205
commit a172a02fe1
3 changed files with 36 additions and 1 deletions

View file

@ -92,13 +92,27 @@
src: dmz.conf src: dmz.conf
dest: /etc/network/interfaces.d/dmz.conf dest: /etc/network/interfaces.d/dmz.conf
notify: enable interfaces notify: enable interfaces
- name: Add backup user - name: Add backup share user
user: user:
name: "{{ backup_share_user }}" name: "{{ backup_share_user }}"
create_home: false create_home: false
password: '!' password: '!'
shell: /sbin/nologin shell: /sbin/nologin
system: true system: true
- name: Add backup control user
user:
name: "{{ backup_control_user }}"
password: '!'
shell: /usr/bin/sh
system: true
groups: "libvirt"
- name: Copy control script
copy:
src: "backup_control.sh"
dest: "/home/{{ backup_control_user }}/control.sh"
owner: "{{ backup_control_user }}"
group: "{{ backup_control_user }}"
mode: u=rx,g=rx,o=rx
- name: Add backup user principals file - name: Add backup user principals file
copy: copy:
dest: "/etc/ssh/backup_principals" dest: "/etc/ssh/backup_principals"

View file

@ -0,0 +1,15 @@
VIRSH="virsh --connect qemu:///system"
read -p "" option
case "$option" in
up)
for i in $($VIRSH list --all --name --autostart); do $VIRSH start "$i"; done
;;
down)
for i in $($VIRSH list --state-running --name --autostart); do
$VIRSH shutdown "$i"
until $VIRSH domstate "$i" | grep shut; do
sleep 0.5
done
done
;;
esac

View file

@ -6,3 +6,9 @@ Match User {{ backup_share_user }}
ForceCommand internal-sftp ForceCommand internal-sftp
AllowTcpForwarding no AllowTcpForwarding no
X11Forwarding no X11Forwarding no
Match User {{ backup_control_user }}
AuthorizedPrincipalsFile /etc/ssh/backup_principals
ForceCommand /home/{{ backup_control_user }}/control.sh
AllowTcpForwarding no
X11Forwarding no