Linux & outillage DevOps

Fiche pédagogique

  • Objectifs SMART : industrialiser un poste DevOps, écrire 5 scripts Bash testés, provisionner un lab Vagrant/Ansible en moins de 10 jours.
  • Durée : 8 h (4 h théorie, 4 h pratique)
  • Prérequis : notions shell, Git.
  • Niveau : Débutant → Intermédiaire.

Sommaire

  1. Architecture Linux & bonnes pratiques shell
  2. Automatiser avec Bash, tests & linting
  3. Provisionner un lab reproductible (Vagrant, Ansible)
  4. Sécuriser & industrialiser la toolchain
  5. Cas pratiques & exemples
  6. Labs, quiz & checklist
  7. Ressources et synthèse

1. Architecture Linux & bonnes pratiques shell

Rappels : noyau, userland, process tree pstree, gestion des services avec systemd (targets, units, journald). Diagramme recommandé : « boot → systemd → services ».

  • Gestion paquets (APT/DNF/Pacman) et dépôts internes.
  • Permissions POSIX, sudoers, ACL (setfacl).
  • Réseau : ss, ip addr, iptables/nft.

2. Automatiser avec Bash, tests & linting

  • Shebang portable #!/usr/bin/env bash, options set -euo pipefail, fonctions, arrays, traps.
  • Standards de logging (fonction log()), gestion erreurs, exit codes.
  • Qualité : shellcheck, shfmt, tests unitaires avec bats-core.
#!/usr/bin/env bash
set -euo pipefail
log() { printf '[%s] %s
' "$(date '+%F %T')" "$*"; }
trap 'log "Erreur ligne $LINENO"' ERR

backup_dir=${1:-/var/backups}
log "Rotation vers ${backup_dir}"
find /var/log -type f -mtime +7 -print0 | xargs -0 gzip -9

3. Provisionner un lab reproductible

Vagrant pour créer plusieurs VM locales, Ansible pour l’état désiré, Molecule pour tester les rôles.

Vagrant.configure('2') do |config|
  config.vm.define 'control' do |node|
    node.vm.box = 'bento/ubuntu-24.04'
    node.vm.network 'private_network', ip: '192.168.56.10'
    node.vm.provision 'ansible' do |ans|
      ans.playbook = 'site.yml'
      ans.inventory_path = 'inventory/vagrant'
    end
  end
end

Playbook d’exemple :

- hosts: all
  become: true
  roles:
    - harden
    - docker
  vars:
    users:
      - name: devops
        groups: ['docker','sudo']

4. Sécuriser & industrialiser la toolchain

  • Gestion des dotfiles (chez GitHub + chezmoi).
  • Secrets : pass ou age + sops.
  • Multiplexeurs (tmux), noyaux LTS, automatisation updates (unattended-upgrades).
  • Monitoring local : node_exporter pour suivre ressources du lab.

5. Cas pratiques

  1. Golden Laptop : script d’installation (Docker, kubectl, Helm, Terraform, Azure/AWS CLIs) + vérification version.
  2. Hardening express : rôle Ansible appliquant CIS L1 (ssh, auditd, journald).
  3. Script de diagnostic : collecte logs/services et zip pour support.

6. Labs, quiz & checklist

LabObjectifLivrable
Lab VagrantCréer 2 VM reliées + provisioning AnsibleDépôt Git + README
Lab ScriptsTrois scripts (backup, monitoring, reporting) avec tests BatsCI GitHub + badge
Lab HardeningPlaybook CIS + rapport lynisRapport HTML

Quiz d’évaluation (exemples) : commandes systemd, différence set -e/set -u, syntaxe Ansible idempotente, pipeline Vagrant → Molecule.

Checklist revue pair :

  • Scripts avec logs, tests et shellcheck OK.
  • Playbook Ansible idempotent + ansible-lint clean.
  • Documentation README (prérequis, commandes make).

7. Ressources & synthèse

  • CIS Benchmarks Ubuntu/RHEL, Red Hat System Design Guide.
  • Outils : chezmoi, ansible-lint, Molecule, Vagrant, cloud-init.
  • Veille : Fedora Magazine, Ubuntu Insights, DevOps Stack Exchange.
  • Prépa certifs : Linux Foundation LFCS, RHCSA.

À retenir : standardiser l’environnement évite les « fonctionne sur ma machine ». Versionnez scripts, playbooks et dotfiles. Ce module prépare les suivants (Terraform, Ansible, pipelines).