view tasks.py @ 320:11d3bcedb9f0

updates for tofu rebuild; some dead code; start moving tasks into subdirs with their files and templates
author drewp@bigasterisk.com
date Fri, 08 Nov 2024 23:16:56 -0800
parents 2d20824d8e8b
children 4d1b6a6e65d2
line wrap: on
line source

from invoke import task

cmd = '''
HOME=/root
export HOME
eval `keychain --quiet --eval id_ecdsa`
cd /my/proj/infra
pdm run pyinfra '''


def _run(ctx, s):
    ctx.run(cmd + '--no-wait -y inventory.py %s' % s, pty=True, echo=True)


@task
def users(ctx):
    _run(ctx, 'users.py')


@task
def ssh(ctx):
    _run(ctx, 'ssh.py')


@task
def system(ctx):
    _run(ctx, 'system.py')


@task
def apt(ctx):
    _run(ctx, 'apt/apt.py')


@task
def packages(ctx):
    _run(ctx, 'packages.py')


@task
def net(ctx):
    _run(ctx, 'net.py')


@task
def dns(ctx):
    _run(ctx, 'dns.py')


@task
def dns_check(ctx):
    _run(ctx, 'dns_check.py -v')


@task
def dns_k8s_check(ctx):
    ctx.run('pdm run python dns_k8s_check.py', pty=True)


@task
def wireguard(ctx):
    _run(ctx, 'wireguard.py')


@task
def kube(ctx):
    _run(ctx, 'kube.py')


@task
def sync(ctx):
    _run(ctx, 'sync.py')


@task
def mail(ctx):
    _run(ctx, 'mail.py')


@task
def home(ctx):
    _run(ctx, 'home.py')


@task
def multikube(ctx):  # danger- wipes previous k3s
    from multikube_config import server_node, nodes
    ctx.run(cmd + 'inventory.py multikube_wipe.py', pty=True)
    ctx.run(cmd + f'inventory.py multikube.py --limit {server_node}', pty=True)
    if nodes:
        ctx.run(cmd + f'inventory.py multikube.py {" ".join(f"--limit {n}" for n in nodes)}', pty=True)
    print("""now try
    curl http://10.43.0.10:9153/metrics | head
    k3s kubectl run hello --image crccheck/hello-world
    curl -m2 http://`kubectl get pod/hello '-o=jsonpath={.status.podIP}'`:8000
    """)


@task
def all(ctx):
    configs = [
        'users.py',
        'ssh.py',
        'system.py',
        'apt/apt.py',
        'packages.py',
        'net.py',
        'dns.py',
        'wireguard.py',
        'kube.py',
        'sync.py',
        'mail.py',
        'home.py',
    ]
    ctx.run(' '.join([cmd, '--no-wait', '-y', 'inventory.py'] + configs), pty=True)
    ctx.run('touch /my/proj/infra/ran_all.timestamp')


@task
def get_fact(ctx, host='dash', fact='server.LinuxDistribution'):
    ctx.run(cmd + f'{host} -vv fact {fact}', pty=True)