Pyinfra that deploy my LXD server.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

81 lines
2.0 KiB

from pyinfra import host
from pyinfra.operations import server, files, systemd, apt
SUDO = True
apt.packages(
name='Install packages',
packages=['zfsutils-linux'],
update=True,
)
if not host.fact.command('zpool list local | grep local || true'):
server.shell(
name='Create ZFS pool',
commands=['zpool create -o ashift=12 -o autotrim=on -O acltype=posixacl -O canmount=off -O compression=lz4 -O dnodesize=auto -O normalization=formD -O relatime=on -O xattr=sa local /dev/vdb']
)
files.put(
name='Upload LXD config',
src='files/lxd.yml',
dest='/tmp/lxd.yml',
mode='644',
)
if not host.fact.command('lxc storage list | grep local || true'):
server.shell(
name='Init LXD',
commands=['cat /tmp/lxd.yml | lxd init --preseed']
)
if not host.fact.command('lxc storage volume list default | grep backups || true'):
server.shell(
name='Set LXD backups volumes',
commands=['lxc storage volume create default backups', 'lxc config set storage.backups_volume default/backups']
)
if not host.fact.command('lxc storage volume list default | grep images || true'):
server.shell(
name='Set LXD images volumes',
commands=['lxc storage volume create default images', 'lxc config set storage.images_volume default/images']
)
files.put(
name='Push zfs-scrub script',
src='files/zfs-scrub.sh',
dest='/usr/local/bin/zfs-scrub.sh',
mode='700',
user='root',
group='root',
)
files.put(
name='Push zfs-scrub timer',
src='files/zfs-scrub.timer',
dest='/etc/systemd/system/zfs-scrub.timer',
user='root',
group='root',
mode='644',
)
files.put(
name='Push zfs-scrub service',
src='files/zfs-scrub.service',
dest='/etc/systemd/system/zfs-scrub.service',
user='root',
group='root',
mode='644',
)
systemd.daemon_reload(
name='Reload systemd',
user_mode=False,
)
systemd.service(
name='Enable zfs-scrub timer',
service='zfs-scrub.timer',
running=True,
enabled=True,
)