Como instalar fabtools y fabric 1.x
Bien les voy a contar que he probado muchos herramientas de configuració y de orquestación como cheff, puppet, ansible …
Y la verdad es que ningún me ha gustado como fabric
Fabric es una librería de python con la que puedas hacer deployments o configuraciones de servicios para linux exclusivamente.
Lo que hace es conectarse por ssh a la maquina que le tu definas y ejecutar comandos que tu programes o le definas en el fabfile.py
Es tan hermoso verlo ejecutar que tareas repetitivas las puede ejecutar con fabric.
Por ejemplo este script para automatizar la creación de registros DNS en nuestro DNS bind del trabajo
from fabric.api import *
import cuisine
import os
BIND_DIR = "/etc/bind"
BIND_FILE = "/etc/bind/named.conf.local"
CONTENT_ZONE = """
zone "{}" {{
type master;
file "/etc/bind/db.{}";
allow-update {{ none; }};
allow-transfer {{ 10.0.0.7; }};
}};
"""
CONTENT_ZONESLAVE= """
zone "{}" {{
type slave;
file "/var/cache/bind/db.{}";
masters {{ 10.0.0.14; }};
}};
"""
CONTENT_FILEZONE = """
$TTL 604800
@ IN SOA cache1.interalia. sistemas.interalia. (
6 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS cache1.interalia.
@ IN NS cache2.interalia.
@ IN A 10.0.0.2
@ IN AAAA ::1
;
"""
@task
@hosts("sysadmin@10.0.0.14")
def addhost_master(host):
with cuisine.mode_sudo(True):
print env.passwords
cuisine.file_backup(BIND_FILE, once=True)
print "ECHO BACKUP"
read_bind = cuisine.file_read(BIND_FILE)
if not host in read_bind:
content = CONTENT_ZONE.format(host, host)
cuisine.file_append(BIND_FILE, content)
file_bind = os.path.join(BIND_DIR, 'db.{}'.format(host))
cuisine.file_write(file_bind, CONTENT_FILEZONE)
cuisine.upstart_restart("bind9")
sudo("rm -f {}.orig".format(BIND_FILE))
@task
@hosts("sysadmin@10.0.0.7")
def addhost_slave(host):
with cuisine.mode_sudo(True):
cuisine.file_backup(BIND_FILE, once=True)
read_bind = cuisine.file_read(BIND_FILE)
if not host in read_bind:
content = CONTENT_ZONESLAVE.format(host, host)
cuisine.file_append(BIND_FILE, content)
cuisine.upstart_restart("bind9")
sudo("rm -f {}.orig".format(BIND_FILE))
@task
def addhost_test(host):
local("dig {} @10.0.0.7".format(host))
local("dig {} @10.0.0.14".format(host))
@task
def addhost(host):
execute(addhost_master, host)
execute(addhost_slave, host)
execute(addhost_test, host)
Ejecutando fab addhost:midominio.com
ejecuta y agrega el domino a nuestro proxy principal
Lamentablemente no tiene un ecosistema tan grande como ansible donde hay un repositorio de proyectos como el galaxy.ansible.com
Valdría la pena hacer algo rápido y veloz para tener recipes.fabfiles.org
Y tener un concentrado de recetas de fabric