41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
# SPDX-FileCopyrightText: 2022-present Raoul Snyman <raoul@libertytechforce.com>
|
|
#
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
from pyinfra import host
|
|
from pyinfra.api.deploy import deploy
|
|
from pyinfra.api.exceptions import DeployError
|
|
from pyinfra.facts.deb import DebPackages
|
|
from pyinfra.facts.rpm import RpmPackages
|
|
from pyinfra.facts.server import Which
|
|
from pyinfra.operations import apt, dnf, yum
|
|
|
|
|
|
def _apt_install():
|
|
apt.packages(
|
|
name='Install Docker Compose plugin via apt',
|
|
packages='docker-compose-plugin',
|
|
update=True
|
|
)
|
|
|
|
|
|
def _yum_or_dnf_install(yum_or_dnf):
|
|
yum_or_dnf.packages(
|
|
name='Install Docker Compose plugin via yum',
|
|
packages=['docker-compose-plugin']
|
|
)
|
|
|
|
|
|
@deploy('Deploy Docker Compose')
|
|
def deploy_docker_compose():
|
|
"""
|
|
Install the Docker Compose plugin on the target machine.
|
|
"""
|
|
|
|
if host.get_fact(DebPackages):
|
|
_apt_install()
|
|
elif host.get_fact(RpmPackages):
|
|
_yum_or_dnf_install(dnf if host.get_fact(Which, command='dnf') else yum)
|
|
else:
|
|
raise DeployError('Neither apt or yum were found, pyinfra-docker-compose cannot provision this machine!')
|