"Después del juego es antes del juego"
Sepp Herberger

viernes, 13 de octubre de 2017

Cómo montar el pkgsync con control compartido usando puppet.

Cada vez que preparo un tipo nuevo de equipo y tengo que meterle pkgsync para mantener la coherencia de los paquetes de forma centralizada me toca re-estudiarme como está montado. Esta vez voy a apuntarlo aquí a modo de guía.

1. Cómo funciona el pkgsync en máquinas clientes.

Gracias a Esteban tenemos un pkgsync cada vez mas potente y versátil. En los repositorios tenemos la version 1.39:
# apt-cache policy pkgsync
pkgsync:
  Instalados: 1.39
  Candidato:  1.39
  Tabla de versión:
 *** 1.39 0
        500 http://linex.educarex.es/ubuntu/trusty/ trusty/linex amd64 Packages
        500 http://servidor/html/linex2/ubuntu/trusty/ trusty/linex amd64 Packages
        100 /var/lib/dpkg/status
        ....
Hace años que partimos de un pkgsync primitivo basado en solo 3 ficheros (/etc/pkgsync/mayhave, maynothave y musthave) que nos daba muchos problemas de competencia entre lo que nos imponían desde Mérida y lo que queríamos tener cada uno en nuestro centro (¿quién manda si hay un único mayhave?).

Gracias a las mejoras de Esteban hemos evolucionado a un sistema de soberanía compartida, donde hay una parte del mayhave (y compañía) controlada por Mérida y otra controlada por nosotros.

Por ello ahora tenemos tres orígenes de ficheros que se fusionan al ejecutar pkgsync en un único /etc/pkgsync/mayhave.all, el cual toma la función que tenía el antiguo y solitario /etc/pkgsync/mayhave. Estos 3 orígenes son:

  • /etc/pkgsync/mayhave: es controlado por Mérida mediante diversas tareas puestas en nuestro servidor puppet. Si lo modificamos será sobreescrito desde el Puppet Master of Our Universe de la Consejería.
  • /etc/pkgsync/mayhave.ies: es controlado por nosotros en nuestro servidor puppet. Para ello debemos tener una tarea hecha que lo controle.
  • /etc/pkgsync/mayhave.d/*: es como mayhave.ies, pero en este directorio podemos poner varios ficheros que se fusionarán con el resto. Es muy cómodo para hacer grupos de paquetes personalizados según el tipo de equipo (por ejemplo /etc/pkgsync/mayhave.d/mayhave.multimedia y poner dentro una lista de paquetes relacionados con multimedia). También debemos tener una tarea hecha por nosotros que controle estos ficheros.

Of course, esto relatado del mayhave se aplica de forma idéntica para musthave y maynothave.

2. Cómo se distribuyen los ficheros de pkgsync oficiales desde el servidor puppet.

Para evitar tener que ir equipo a equipo, los ficheros vistos en el apartado anterior tienen que controlarse desde el servidor puppet del centro. Hemos convenido en que los ficheros musthave/mayhave/maynothave son controlados desde Mérida por su puppet, mientras que los musthave.ies/mayhave.ies/maynothave.ies y los musthave.d/mayhave.d/maynothave.d están controlados por nosotros por nuestro puppet.

Los controlados por el servidor de la Consejería en Mérida se guardan en la ruta /etc/puppet/files/xubuntu del servidor principal del centro. Si vamos allí, veremos al menos estos ficheros:
mayhave.siatic.i386
musthave.hp360
musthave.infolab
musthave.siatic
musthave.siatic.i386
Para saber que se hace con ellos, busco en las tareas puppet:
root@servidor:/etc/puppet# grep -ir puppetinstituto/files/xubuntu/mayhave * 
manifests/classes/xubuntu/siatic.pp:        source => "puppet://puppetinstituto/files/xubuntu/mayhave.siatic.i386",

root@servidor:/etc/puppet# grep -ir puppetinstituto/files/xubuntu/musthave * 
manifests/classes/xubuntu/notebookHP.pp:        source => "puppet://puppetinstituto/files/xubuntu/musthave.hp360",
manifests/classes/xubuntu/siatic.pp:        source => "puppet://puppetinstituto/files/xubuntu/musthave.siatic.i386",
manifests/classes/xubuntu/infolab.pp:#        source => "puppet://puppetinstituto/files/xubuntu/musthave.infolab",
De lo visto podemos decir que:
  • musthave.hp360: es el musthave que se copia para tablets-portátiles hp360.
  • musthave.infolab: es el musthave para infolabs. Lo cierto es que a día de hoy no se usa, se comentó su inserción por un problema con las tarjetas nvidia y así permanece.
  • mayhave.siatic.i386, musthave.siatic.i386: son el mayhave/musthave que se copia a las Siatic con sistema de 64bits.
  • musthave.siatic: ya no se usa. En su día era el oficial de los siatics, pero había paquetes de xserver que daban problemas y se dejó de insertar.

Como vemos, no hay musthaves/mayhaves/maynothave oficiales para equipos ltsp, workstations, portátiles distintos a los hp360 ni para siatics de 64bits. Se entiende que todos estos equipos tienen un /etc/pkgsync/musthave que viene de serie en su respectiva imagen y de momento la Sección no contempla modificarlos por puppet ya que no hay tarea oficial que se ocupe de actualizarlos.

En el caso de las siatic 64bits ni siquiera traen un musthave inicialmente (lo cual hace que pkgsync no funcione ya que requiere de su existencia para trabajar) y si lo queremos debemos generarlo con el script que aparece en la imagen llamado /root/Primer_arranque/generar_musthave.sh (el cual también es una creación de Esteban).

Por lo general tampoco hay mayhaves y maynothave oficiales para ningún equipo, ya que de momento no ha surgido la necesidad de tenerlos de forma general en todos los centros.

3. Cómo distribuyo los ficheros de pkgsync particulares desde el servidor puppet.

Hasta aquí hemos visto la infraestructura común, ahora veremos como controlar por nuestra parte los mayhave/musthave/maynothave que son de nuestra competencia. Nada de esto lo tenemos por defecto en el servidor del centro y por tanto nos toca montar por nuestra cuenta el módulo puppet y los ficheros que distribuye.

En primer lugar aclarar los musthave.ies/mayhave.ies/maynothave.ies no los uso. Tuvieron su momento cuando teníamos Debian Wheezy pero ahora preferimos la solución mas elegante basada en los ficheros fragmentados a través de musthave.d/mayhave.d/maynothave.d. Si lo montamos bien, podremos tener un musthave general, que se aplica a todos los equipos, y un musthave por cada tipo-use2 de equipo.

En mi caso, en /etc/puppet/files/xubuntu tengo esta estructura de directorios creada:
├── mayhave.d
│   ├── mayhave.infolab
│   ├── mayhave.infolab.profesor
│   ├── mayhave.ltsp.profesor
│   ├── mayhave.notebookHP
│   ├── mayhave.portatil-alumno
│   ├── mayhave.siatic
│   ├── mayhave.workstation
│   ├── mayhave.workstation-i386
│   └── mayhave.xubuntu
├── maynothave.d
│   ├── maynothave.infolab
│   ├── maynothave.infolab.profesor
│   ├── maynothave.ltsp.profesor
│   ├── maynothave.notebookHP
│   ├── maynothave.portatil-alumno
│   ├── maynothave.siatic
│   ├── maynothave.workstation
│   ├── maynothave.workstation-i386
│   └── maynothave.xubuntu
└── musthave.d
    ├── musthave.infolab
    ├── musthave.infolab.profesor
    ├── musthave.ltsp.profesor
    ├── musthave.notebookHP
    ├── musthave.portatil-alumno
    ├── musthave.siatic
    ├── musthave.workstation
    ├── musthave.workstation-i386
    └── musthave.xubuntu
Los ficheros .xubuntu se copian a todo los equipos con ubuntu y los otros según los facter tipo (siatic, infolab, ltsp, workstation, etc) y use2 (profesor/alumno). Para ello uso la siguiente clase puppet basada en la original que compartieron mis compañeros del IES Téllez hace ya tiempo:
# cat /etc/puppet/modules/xubuntu_pkgsync/manifests/init.pp 

#Clase para control de los ficheros básicos para pkgsync de siatic, infolab y notebookHP
import "/etc/puppet/defines/*.pp"

class  xubuntu_pkgsync {

        case $use2 {
                "profesor":  { $esprofe=".profesor" }
                default: { $esprofe = "" }
        }

        #====================================================================================================================
        #Ficheros dependientes del tipo: Se pone un mayhave, musthave, maynothave personalizado en función del tipo y use2 (si es profesor) 

        case $tipo {

                "siatic", "infolab", "notebookHP", "ltsp", "workstation","portatil-alumno", "workstation-i386": {  
                        file { "mayhave.instituto":
                         path => "/etc/pkgsync/mayhave.d/mayhave.$tipo",
                         owner => root, group => root, mode => 644, 
                         source => "puppet:///files/xubuntu/mayhave.d/mayhave.${tipo}${esprofe}",
                         ensure => file,
                        }

                        file { "maynothave.instituto": 
                         path => "/etc/pkgsync/maynothave.d/maynothave.$tipo",
                         owner => root, group => root, mode => 644,
                         source => "puppet:///files/xubuntu/maynothave.d/maynothave.${tipo}${esprofe}",
                         ensure => file,
                        }

                        file { "musthave.instituto": 
                         path => "/etc/pkgsync/musthave.d/musthave.$tipo",
                         owner => root, group => root, mode => 644,
                         source => "puppet:///files/xubuntu/musthave.d/musthave.${tipo}${esprofe}",
                         ensure => file,
                        }
                }
                default: { }

        }

        #====================================================================================================================
        #Musthaves/maynothave/mayhave globales para todos los xubuntus controlados por mi

        # musthave global para todos los xubuntu
        file { "musthave.xubuntu":
                path => "/etc/pkgsync/musthave.d/musthave.xubuntu",
                owner => root, group => root, mode => 644,
                source => "puppet:///files/xubuntu/musthave.d/musthave.xubuntu",
                ensure => file,
        }

        # mayhave global para todos los xubuntu
                file { "mayhave.xubuntu":
                path => "/etc/pkgsync/mayhave.d/mayhave.xubuntu",
                owner => root, group => root, mode => 644,
                source => "puppet:///files/xubuntu/mayhave.d/mayhave.xubuntu",
                ensure => file,
        }

        # maynothave global para todos los xubuntu
        file { "maynothave.xubuntu":
                path => "/etc/pkgsync/maynothave.d/maynothave.xubuntu",
                owner => root, group => root, mode => 644,
                source => "puppet:///files/xubuntu/maynothave.d/maynothave.xubuntu",
                ensure => file,
        } 

        #====================================================================================================================
        #Ficheros mayhave/maynothave principales vacios por defecto si no existen.
        #El musthave debe ser creado por el administrador a mano. No se crea por defecto por su peligrosidad.

        # Por si no existen los ficheros, los creamos inicialmente a vacíos
        file { "mayhave.inicial": 
                path => "/etc/pkgsync/mayhave",
                owner => root, group => root, mode => 644,
                ensure => file,
        }

        file { "maynothave.inicial": 
                path => "/etc/pkgsync/maynothave",
                owner => root, group => root, mode => 644,
                ensure => file,
        }

        #El musthave no se crea por precaucion. Si existe el pkgsync se ejecutaría y puede destrozar el sistema de paquetes.
        #   cada /etc/pkgsync/musthave debe ser creado a mano por el administrador. Si no existe, pkgsync se aborta.

}
Y así es como lo tengo montado, utilizando los facter tipo y use2 para colocar los ficheros en las máquinas correspondientes. Los compañeros de Mérida tienen sus ficheros y yo tengo los míos.

Si quiero aplicar un paquete a todos los Ubuntu lo meto en el fichero *.xubuntu correspondiente. Si quiero aplicarlo a un tipo concreto (por ejemplo en los workstation de 64bits), lo meto en el fichero *.workstation correspondiente. En la siguiente ejecución de puppet en el cliente se copiarán los ficheros desde servidor:/etc/puppet/files/xubuntu y en la posterior ejecución de pkgsync se sincronizarán los paquetes de acuerdo con lo ordenado.

Como se ve, es una solución elegante que permite que trabajar colaborativamente sin machacarnos entre nosotros. Parlem.

No hay comentarios:

Publicar un comentario