view tasks.py @ 147:51a48aeca8ba

node/npm fixes
author drewp@bigasterisk.com
date Sat, 11 Mar 2023 12:19:25 -0800
parents ee0384eebee5
children ae13e608b105
line wrap: on
line source

from invoke import task

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

def _run(ctx, s):
    ctx.run(cmd + '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 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('env/bin/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 kube_bang(ctx): _run(ctx, 'kube.py --limit bang')

@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 pipe(ctx): ctx.run(cmd + 'inventory.py pipe.py --limit pipe', pty=True)

@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',
        'packages.py',
        'net.py',
        'dns.py',
        'wireguard.py',
        'kube.py',
        'sync.py',
        'mail.py',
        'home.py',
    ]
    # https://github.com/Fizzadar/pyinfra/issues/787
    #ctx.run(' '.join([cmd, 'inventory.py'] + configs), pty=True)
    for c in configs:
        ctx.run(' '.join([cmd, 'inventory.py', c]), 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)