Beispiel #1
0
def update(state: Optional[State] = None, host: Optional[Host] = None) -> None:
    """update system"""
    if host.fact.os == "Linux":
        if host.fact.linux_distribution["release_meta"]["ID"] == "neon":
            pkcon.update(state=state, host=host)
        elif host.fact.linux_distribution["release_meta"]["ID"] in [
                "debian", "ubuntu"
        ]:
            apt.update(state=state, host=host)
            apt.upgrade(state=state, host=host)
        elif host.fact.linux_distribution["release_meta"]["ID"] == "fedora":
            dnf.update(state=state, host=host)
        elif host.fact.linux_distribution["release_meta"]["ID"] == "alpine":
            apk.update(state=state, host=host)
            apk.upgrade(state=state, host=host)

        else:
            python.raise_exception(state, host, NotImplementedError)
    elif host.fact.os == "FreeBSD":
        freebsd.update(state=state, host=host)
        freebsd.upgrade(state=state, host=host)
    elif host.fact.os == "Darwin":
        brew.update(state=state, host=host)
        brew.upgrade(state=state, host=host)
    else:
        python.raise_exception(state, host, NotImplementedError)
Beispiel #2
0
def brook(state: Optional[State] = None, host: Optional[Host] = None) -> None:
    """Install brook."""
    if host.fact.arch == "x86_64":
        files.download(
            source_url=
            "https://github.com/txthinking/brook/releases/download/v20200909/brook_linux_amd64",  # noqa: E950
            destination="/usr/local/bin/brook",
            mode=755,
            sha256sum=
            "efc4dc925bcaff4d33450fbcd02351da8f971f5cea6b84501a3d2a6f94876adf",  # noqa: E950
            state=state,
            host=host,
        )
        server.shell(
            f"nohup brook server -l {_get_host_ip(host.name)}:{environ['BROOK_PORT']} -p {environ['BROOK_PASSWORD']} > /dev/null 2> /dev/null &",  # noqa: B950
            success_exit_codes=[0, 1],
            state=state,
            host=host,
        )
    else:
        python.raise_exception(state, host, NotImplementedError)
Beispiel #3
0
def wireguard(state: Optional[State] = None,
              host: Optional[Host] = None) -> None:
    """Install wireguard."""
    if host.fact.os == "Linux":
        if host.fact.linux_distribution["release_meta"]["ID"] in [
                "debian", "ubuntu"
        ]:
            apt.packages(packages=["wireguard"], state=state, host=host)
        else:
            python.raise_exception(exception_class=NotImplementedError,
                                   state=state,
                                   host=host)
    else:
        python.raise_exception(exception_class=NotImplementedError,
                               state=state,
                               host=host)

    files.template(
        template_filename="templates/wg0.conf.j2",
        remote_filename="/etc/wireguard/wg0.conf",
        create_remote_dir=True,
        state=state,
        host=host,
        wg_private_key=environ["WG_PRIVATE_KEY"],
        wg_port=environ["WG_PORT"],
        wg_interface=environ["WG_INTERFACE"],
        wg_peer_1_public_key=environ["WG_PEER_1_PUBLIC_KEY"],
        wg_peer_2_public_key=environ["WG_PEER_2_PUBLIC_KEY"],
    )

    server.sysctl(key="net.ipv4.ip_forward", value=1, state=state, host=host)
    server.sysctl(key="net.ipv6.conf.all.forwarding",
                  value=1,
                  state=state,
                  host=host)
    server.shell(commands=["wg-quick up wg0"],
                 success_exit_codes=[0, 1],
                 state=state,
                 host=host)
Beispiel #4
0
from pyinfra import host, state
from pyinfra.modules import apt, files, postgresql, python

SUDO = True


if host.fact.linux_distribution['name'] != 'Ubuntu':
    # Raises an exception mid-deploy
    python.raise_exception(
        {'Ensure we are Ubuntu'},
        NotImplementedError,
        '`postgresql.py` only works on Ubuntu',
    )


apt.packages(
    {'Install postgresql server & client'},
    ['postgresql'],
    update=True,
    cache_time=3600,
)


# Setup a PostgreSQL role & database
#

postgresql.role(
    {'Create the pyinfra PostgreSQL role'},
    'pyinfra',
    password='******',
    superuser=True,
Beispiel #5
0
from pyinfra import host, state
from pyinfra.modules import apt, files, mysql, python

SUDO = True

if host.fact.linux_distribution['name'] != 'Debian':
    # Raises an exception mid-deploy
    python.raise_exception(
        {'Ensure we are Debian'},
        NotImplementedError,
        '`mysql.py` only works on Debian',
    )

apt.packages(
    {'Install mysql server & client'},
    ['mysql-server'],
    update=True,
    cache_time=3600,
)

# Setup a MySQL role & database
#

mysql.user(
    {'Create the pyinfra@localhost MySQL user'},
    'pyinfra',
    password='******',
)

mysql.database(
    {'Create the pyinfra_stuff database'},