• # BSD Owl Scripts

    Posté par (site web personnel) . En réponse au journal Gérer ses fichiers de config avec git. Évalué à 9. Dernière modification le 17 avril 2015 à 11:09.

    Sommaire

    Comment gérez-vous les fichiers de configs répartis sur vos différentes machines ?

    Je fais ça avec BSD Owl Scripts1 qui propose un module dédié pour les systèmes FreeBSD.

    Organisation

    Dans mon parc, j'ai quelques ordinateurs personnels sous FreeBSD ou Mac OS X et quelques systèmes virtualisés dans des jails. Chaque machine, possède un dossier contenant ses fichoers de configuration et il existe un dossier common contenant les fichiers communs à toutes les machines:

    % ls
    common creidhne llea mongan poudriere puk

    Tous ces dossiers sont dans un dépôt git qui est cloné sur chaque machine réelle – les machines virtualisées dans des jails n'ont pas besoin du clone, cf. ci-dessous.

    Fichiers communs

    Dans le fichier common on trouve par exemple un fichier host mais aussi plein de petits trucs du style configuration du dæmon npd qui met à jour l'horloge du réseau, ou bien un fichier Xresource.

    % ls common
    10-ignore-patterns.fdi hosts ports-supfile
    PolicyKit.conf loader.conf portsnap.conf
    Xmodmap login.conf refuse-supfile
    Xresources make.conf resolv.conf
    devfs.conf motd src.conf
    devfs.rules networks stable-supfile
    doc-supfile ntp.conf sudoers
    fonts-local.conf pkgtools.conf sysctl.conf

    Fichiers par machine réelle

    Pour la machine réelle llea on a les fichiers spécifiques suivants: on y trouve la configuration de SSH, de NFS, de poudrière, de musicpd, etc.:

    % ls llea
    ls
    Makefile exports loader.conf.local smartd.conf
    NOTES ezjail.conf make-site.conf ssh_config
    NOTES.jail fstab musicpd.conf sshd_config
    allow-restart.pkla fstab.creidhne periodic.conf sysctl.conf
    device.hints fstab.mongan poudriere.conf ttys
    dump_hdaa_config.ml jail.conf rc.conf xorg.conf

    La partie importante est le Makefile:

    ### Makefile -- The LLEA workstation
    BOOT= loader.conf
    BOOT+= loader.conf.local
    BOOT+= device.hints
    BASE= rc.conf
    BASE+= login.conf
    BASE+= sysctl.conf
    BASE+= fstab
    BASE+= fstab.creidhne
    BASE+= fstab.mongan
    BASE+= ttys
    BASE+= resolv.conf
    BASE+= ntp.conf
    BASE+= devfs.rules
    BASE+= sshd_config
    BASE+= ssh_config
    BASE+= exports
    BASE+= hosts
    BASE+= networks
    BASE+= jail.conf
    BASE+= periodic.conf
    XORG= xorg.conf
    XORG+= Xresources
    XORG+= Xmodmap
    PORT= sudoers
    PORT+= ezjail.conf
    PORT+= musicpd.conf
    PORT+= poudriere.conf
    PKLA+= allow-restart.pkla
    .PATH: ../common
    .include "conf.freebsd.mk"
    ### End of file `Makefile'

    Les listes BOOT, BASE, XORG, PORT et PKLA énumèrent respectivement les fichiers de configuration pour le démarrage de la machine, pour le système de base, Xorg, les ports et les règles pour le Policy Kit de FreeDektop.org.

    L'incantation magique .PATH: ../common indique à bmake que les fichiers non trouvés dans le dossier courant peuvent être cherchés dans ../common. Après ceci un petit make install donne

    % console
    make install
    ===> Switching to root credentials for target (install)
    Password:
    install -d /etc
    install -d /etc/ssh
    install -d /etc/ssh
    install -d /usr/local/etc
    install -d /usr/local/etc/polkit-1/localauthority/50-local.d
    install -d /boot
    install -d /etc/X11
    install -o root -g wheel -m 444 rc.conf /etc
    install -o root -g wheel -m 444 ../common/login.conf /etc
    install -o root -g wheel -m 444 sysctl.conf /etc
    install -o root -g wheel -m 444 fstab /etc
    install -o root -g wheel -m 444 fstab.creidhne /etc
    install -o root -g wheel -m 444 fstab.mongan /etc
    install -o root -g wheel -m 444 ttys /etc
    install -o root -g wheel -m 444 ../common/resolv.conf /etc
    install -o root -g wheel -m 444 ../common/ntp.conf /etc
    install -o root -g wheel -m 444 ../common/devfs.rules /etc
    install -o root -g wheel -m 444 sshd_config /etc/ssh
    install -o root -g wheel -m 444 ssh_config /etc/ssh
    install -o root -g wheel -m 444 exports /etc
    install -o root -g wheel -m 444 ../common/hosts /etc
    install -o root -g wheel -m 444 ../common/networks /etc
    install -o root -g wheel -m 444 jail.conf /etc
    install -o root -g wheel -m 444 periodic.conf /etc
    install -o root -g wheel -m 440 ../common/sudoers /usr/local/etc
    install -o root -g wheel -m 444 ezjail.conf /usr/local/etc
    install -o root -g wheel -m 444 musicpd.conf /usr/local/etc
    install -o root -g wheel -m 444 poudriere.conf /usr/local/etc
    install -o root -g wheel -m 444 allow-restart.pkla /usr/local/etc/polkit-1/localauthority/50-local.d
    install -o root -g wheel -m 444 ../common/loader.conf /boot
    install -o root -g wheel -m 444 loader.conf.local /boot
    install -o root -g wheel -m 444 device.hints /boot
    install -o root -g wheel -m 444 xorg.conf /etc/X11
    install -o root -g wheel -m 444 ../common/Xresources /etc/X11
    install -o root -g wheel -m 444 ../common/Xmodmap /etc/X11
    cap_mkdb /etc/login.conf
    

    On voit une authentification avec su - mais on pourrait utiliser sudo aussi. La dernière ligne montre un petit détail sympa puisque la base de donnée des logins est automatiquement reconstruite.

    Fichiers par machine virtualisée dans une jail

    C'est la même chose que pour une machine réelle, mais il faut ajouter une déclaration JAILDIR qui indique la racine du système de fichiers du système virtualisé:

    ### Makefile – The CREIDHNE Trac server
    JAILDIR?= /guest/jail/creidhne
    ...

    Ainsi dans le système hôte, on peut installer les fichiers dans le système virtualisé:

    % make install
    ===> Switching to root credentials for target (install)
    Password:
    install -d /guest/jail/creidhne/usr/local/etc/apache24
    install -d /guest/jail/creidhne/usr/local/etc/apache24/Includes
    ...
    install -o www -g www -m 640 site.html /guest/jail/creidhne/var/trac/templates
    install -o www -g www -m 640 style.css /guest/jail/creidhne/var/trac/htdocs
    ...

    Et voilà!

    Prolongations

    Si vous êtes tentés pour avoir la même chose sur votre sytème Linux préféré n'hésitez pas à me faire part de vos besoin sur le issue tracker du projet! Même en français ou en allemand! :)


    1 Disponible sous Debian, Ubuntu, et bientôt MacPorts et FreeBSD. Une installation à la mano est possible et facile. Marche aussi sous Cygwin.