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

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
7 months ago
9 months ago
9 months ago
9 months ago
  1. from pyinfra import host
  2. from pyinfra.operations import server, files, systemd, apt
  3. SUDO = True
  4. apt.packages(
  5. name='Install packages',
  6. packages=['zfsutils-linux'],
  7. update=True,
  8. )
  9. if not host.fact.command('zpool list local | grep local || true'):
  10. server.shell(
  11. name='Create ZFS pool',
  12. 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']
  13. )
  14. files.put(
  15. name='Upload LXD config',
  16. src='files/lxd.yml',
  17. dest='/tmp/lxd.yml',
  18. mode='644',
  19. )
  20. if not host.fact.command('lxc storage list | grep local || true'):
  21. server.shell(
  22. name='Init LXD',
  23. commands=['cat /tmp/lxd.yml | lxd init --preseed']
  24. )
  25. if not host.fact.command('lxc storage volume list default | grep backups || true'):
  26. server.shell(
  27. name='Set LXD backups volumes',
  28. commands=['lxc storage volume create default backups', 'lxc config set storage.backups_volume default/backups']
  29. )
  30. if not host.fact.command('lxc storage volume list default | grep images || true'):
  31. server.shell(
  32. name='Set LXD images volumes',
  33. commands=['lxc storage volume create default images', 'lxc config set storage.images_volume default/images']
  34. )
  35. files.put(
  36. name='Push zfs-scrub script',
  37. src='files/zfs-scrub.sh',
  38. dest='/usr/local/bin/zfs-scrub.sh',
  39. mode='700',
  40. user='root',
  41. group='root',
  42. )
  43. files.put(
  44. name='Push zfs-scrub timer',
  45. src='files/zfs-scrub.timer',
  46. dest='/etc/systemd/system/zfs-scrub.timer',
  47. user='root',
  48. group='root',
  49. mode='644',
  50. )
  51. files.put(
  52. name='Push zfs-scrub service',
  53. src='files/zfs-scrub.service',
  54. dest='/etc/systemd/system/zfs-scrub.service',
  55. user='root',
  56. group='root',
  57. mode='644',
  58. )
  59. systemd.daemon_reload(
  60. name='Reload systemd',
  61. user_mode=False,
  62. )
  63. systemd.service(
  64. name='Enable zfs-scrub timer',
  65. service='zfs-scrub.timer',
  66. running=True,
  67. enabled=True,
  68. )