@task
def update_master_iptables():
    if env.host != env.master_server.public_ip:
        abort("tried to update_master_iptables on a non-master server")

    configurator_ports = ["4505", "4506"]  # get from settings.py?

    # Get the line in the iptables chain for inserting the new minon's
    with fabric_settings(warn_only=True):
        insert_line = sudo("iptables -L --line-numbers | grep {0}".format(configurator_ports[0]))

    if not insert_line:
        print(yellow("NOTE: iptables are wide open during first boot of a master"))
        return

    for port in configurator_ports:
        match = sudo("iptables -nvL | grep {0}".format(port))
        for server in env.bootmachine_servers:
            if server.private_ip not in match:
                sudo("iptables -I INPUT {0} -s {1} -m state --state new -m tcp -p tcp \
                --dport {2} -j ACCEPT".format(insert_line[0], server.private_ip, port))
Update iptables rules for salt, on the salt master,
dataset/ETHPy150Open rizumu/bootmachine/bootmachine/contrib/configurators/salt.py/update_master_iptables