<commit_before># coding: utf-8
from os import path
from fabric import api as fab
from fabric.api import task, env

eth_interface = """auto {eth_iface}
interface {eth_iface}
static ip_address={eth_ip}/{eth_netmask}
static routers={eth_gateway}
static domain_name_servers={eth_dns}
"""


@task
def bootstrap(boot_ip=None, authorized_keys='authorized_keys', static_ip=True):
    """bootstrap a freshly booted Raspberry PI 3 to make it ansible ready"""
    # (temporarily) set the user to `pi`
    if not path.isabs(authorized_keys):
        authorized_keys = path.join(
            env['config_base'],
            '..',
            authorized_keys)
    final_ip = env.instance.config['ip']
    if boot_ip:
        env.instance.config['ip'] = boot_ip
    hostname = env.instance.uid
    env.host_string = 'pi@%s' % hostname
    env.password = '<PASSWORD>'
    # upgrade to raspbian strech (gives us python3.5)
    fab.sudo("""echo 'deb http://mirrordirector.raspbian.org/raspbian/ testing main contrib non-free rpi' > /etc/apt/sources.list.d/stretch.list""")
    fab.sudo("""apt update""")
    fab.sudo("""apt dist-upgrade -y""")
    AV = env.instance.get_ansible_variables()
    AV.setdefault('eth_ip', final_ip)
    AV.setdefault('eth_iface', 'eth0')
    AV.setdefault('eth_netmask', '24')
    AV.setdefault('eth_gateway', '192.168.1.1')
    AV.setdefault('eth_dns', '8.8.8.8')
    with fab.settings(warn_only=True):
        if static_ip:
            fab.sudo(
                'echo """%s""" >> /etc/dhcpcd.conf' %
                eth_interface.format(**AV))
        # enable passwordless root login via ssh
        fab.sudo("""mkdir /root/.ssh""")
        fab.sudo("""chmod 700 /root/.ssh""")
        fab.put(
            local_path=authorized_keys,
            remote_path='/root/.ssh/authorized_keys',
            use_sudo=True,
            mode='0700')
        fab.sudo("""chown root:root /root/.ssh/authorized_keys""")
    fab.reboot()<commit_msg>Don't upgrade to raspbian stretch<commit_after># coding: utf-8
from os import path
from fabric import api as fab
from fabric.api import task, env

eth_interface = """auto {eth_iface}
interface {eth_iface}
static ip_address={eth_ip}/{eth_netmask}
static routers={eth_gateway}
static domain_name_servers={eth_dns}
"""


@task
def bootstrap(boot_ip=None, authorized_keys='authorized_keys', static_ip=True):
    """bootstrap a freshly booted Raspberry PI 3 to make it ansible ready"""
    # (temporarily) set the user to `pi`
    if not path.isabs(authorized_keys):
        authorized_keys = path.join(
            env['config_base'],
            '..',
            authorized_keys)
    final_ip = env.instance.config['ip']
    if boot_ip:
        env.instance.config['ip'] = boot_ip
    hostname = env.instance.uid
    env.host_string = 'pi@%s' % hostname
    env.password = '<PASSWORD>'
    fab.sudo("""apt update""")
    fab.sudo("""apt upgrade -y""")
    AV = env.instance.get_ansible_variables()
    AV.setdefault('eth_ip', final_ip)
    AV.setdefault('eth_iface', 'eth0')
    AV.setdefault('eth_netmask', '24')
    AV.setdefault('eth_gateway', '192.168.1.1')
    AV.setdefault('eth_dns', '8.8.8.8')
    with fab.settings(warn_only=True):
        if static_ip:
            fab.sudo(
                'echo """%s""" >> /etc/dhcpcd.conf' %
                eth_interface.format(**AV))
        # enable passwordless root login via ssh
        fab.sudo("""mkdir /root/.ssh""")
        fab.sudo("""chmod 700 /root/.ssh""")
        fab.put(
            local_path=authorized_keys,
            remote_path='/root/.ssh/authorized_keys',
            use_sudo=True,
            mode='0700')
        fab.sudo("""chown root:root /root/.ssh/authorized_keys""")
    fab.reboot()
{'fraction_non_alphanumeric': 0.1484375, 'fraction_numerical': 0.013469827586206896, 'mean_word_length': 2.875782881002088, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1419162', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1226, 'n_words': 255}