Infra/pyinfra helpers (#8)

* build: pyinfra dependency

* infra: system update/reboot helpers
This commit is contained in:
Marc 2022-11-12 13:36:19 -05:00 committed by GitHub
parent bc2ef284a6
commit ef19e50360
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 125 additions and 1 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
spadinaistan.venv
pyinfra-debug.log
deluge/config
deluge/downloads
**/healthcheck.json

0
pyinfra/__init__.py Normal file
View file

1
pyinfra/inventory.py Normal file
View file

@ -0,0 +1 @@
hosts = [("spadinaistan.karnov.club", {"ssh_port": 6969})]

14
pyinfra/reboot.py Normal file
View file

@ -0,0 +1,14 @@
"""
Reboot machines.
"""
import pyinfra
def reboot_machines():
pyinfra.operations.server.reboot(
name="Reboot server", _sudo=True, _use_sudo_password=True
)
reboot_machines()

20
pyinfra/system_updates.py Normal file
View file

@ -0,0 +1,20 @@
"""
Runs Ubuntu system updates.
"""
import pyinfra
def update_ubuntu_packages():
common = {"_sudo": True, "_use_sudo_password": True}
pyinfra.operations.server.shell(
name="Search for system updates", commands=["apt update"], **common
)
pyinfra.operations.server.shell(
name="Apply updates and remove orphaned packages",
commands=["apt upgrade --autoremove"],
**common
)
update_ubuntu_packages()

View file

@ -1,2 +1,3 @@
black
invoke
pyinfra

View file

@ -4,19 +4,87 @@
#
# pip-compile ./requirements.in
#
bcrypt==4.0.1
# via paramiko
black==22.6.0
# via -r ./requirements.in
certifi==2022.9.24
# via requests
cffi==1.15.1
# via
# cryptography
# pynacl
charset-normalizer==2.1.1
# via requests
click==8.1.3
# via black
# via
# black
# pyinfra
colorama==0.4.6
# via pyinfra
configparser==5.3.0
# via pyinfra
cryptography==38.0.3
# via
# paramiko
# requests-ntlm
distro==1.8.0
# via pyinfra
gevent==22.10.2
# via pyinfra
greenlet==2.0.1
# via gevent
idna==3.4
# via requests
invoke==1.7.1
# via -r ./requirements.in
jinja2==3.1.2
# via pyinfra
markupsafe==2.1.1
# via jinja2
mypy-extensions==0.4.3
# via black
ntlm-auth==1.5.0
# via requests-ntlm
paramiko==2.12.0
# via pyinfra
pathspec==0.9.0
# via black
platformdirs==2.5.2
# via black
pycparser==2.21
# via cffi
pyinfra==2.5.3
# via -r ./requirements.in
pynacl==1.5.0
# via paramiko
python-dateutil==2.8.2
# via pyinfra
pywinrm==0.4.3
# via pyinfra
requests==2.28.1
# via
# pywinrm
# requests-ntlm
requests-ntlm==1.1.0
# via pywinrm
six==1.16.0
# via
# paramiko
# python-dateutil
# pywinrm
tomli==2.0.1
# via black
typing-extensions==4.3.0
# via black
urllib3==1.26.12
# via requests
xmltodict==0.13.0
# via pywinrm
zope-event==4.5.0
# via gevent
zope-interface==5.5.1
# via gevent
# The following packages are considered to be unsafe in a requirements file:
# setuptools

View file

@ -6,6 +6,25 @@ import kong.tasks
ns = invoke.Collection()
PYINFRA_COMMON_PREFIX = "pyinfra -vvv pyinfra/inventory.py"
@invoke.task()
def system_updates(ctx):
ctx.run(f"{PYINFRA_COMMON_PREFIX} pyinfra/system_updates.py")
@invoke.task()
def system_reboot(ctx):
ctx.run(f"{PYINFRA_COMMON_PREFIX} pyinfra/reboot.py")
server = invoke.Collection("server")
server.add_task(system_updates, name="update")
server.add_task(system_reboot, name="reboot")
ns.add_collection(plex.tasks.ns)
ns.add_collection(deluge.tasks.ns)
ns.add_collection(kong.tasks.ns)
ns.add_collection(server)