Automatisez l’installation de votre poste de travail !

@sylvain_metayer

photo

Sylvain MÉTAYER

logo

Tech Lead @Onepoint

Avantages / Inconvénients

Objectif

État

Gérer mes fichiers de configuration

?

Gérer les logiciels installés

?

Versionnable

?

Facilement maintenable

?

Gérer mon poste de travail pro et perso

?

Gestion de secrets

?

Dotfiles, c’est quoi ?

~/.bashrc
#!/usr/bin/env bash

if [ -f /etc/bashrc ]; then
 . /etc/bashrc
fi

export SSH_AUTH_SOCK=/run/user/1000/ssh-agent.socket
# ...

Et d’autres : vimrc, gitconfig, …​

Comment fait-on ?

Stow

GNU Stow is a symlink farm manager which takes distinct sets of software and/or data located in separate directories on the filesystem, and makes them all appear to be installed in a single directory tree.
— https://www.gnu.org/software/stow/manual/stow.html#Bootstrapping

Avantages / Inconvénients

Objectif

État

Gérer mes fichiers de configuration

Gérer les logiciels installés

Versionnable

Facilement maintenable

Gérer mon poste de travail pro et perso

😐

Gestion de secrets

Un script maison

Du shell, du python, du C, du PHP…​ Venez comme vous êtes, on va coder !

Avantages / Inconvénients

Objectif

État

Gérer mes fichiers de configuration

Gérer les logiciels installés

Versionnable

Facilement maintenable

😐

Gérer mon poste de travail pro et perso

Gestion de secrets

Ansible

Structure

├── playbooks
│   ├── perso
│   ├── pro
│   ├── ├── main.yaml
├── roles
│   ├── jetbrains_toolbox
│   │   ├── defaults
│   │   ├── tasks
│   │── git_config
│   │   ├── tasks
│   └── [...]

Playbook

---
- hosts: localhost
  tasks:
    - name: "Simple task"
      debug:
        msg: |-
Hello TNT#25 ! :)
  roles:
    - role: geerlingguy.docker
      become: true
    - role: git_config

Usage

$ cat scripts/setup.sh
python3 -m pip install --user -r "requirements.txt"
ansible-galaxy role install -r "requirements.yml"
$ cat requirements.txt
ansible==11.2.0
$ cat requirements.yml
roles:
  - src: geerlingguy.docker
    version: 7.4.4

Usage

$ ansible-playbook playbooks/perso/main.yaml -K
BECOME password:
PLAY [localhost] ************************************

TASK [git_config : Ensure Git config file exists] ************************************
ok: [localhost]

TASK [git_config : Render Git config Template] ************************************
changed: [localhost]

PLAY RECAP ************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Playbook run took 0 days, 0 hours, 0 minutes, 1 seconds

Installation de paquets

roles/commons/defaults/main.yaml
packages_to_install:
  - vim
  - firefox
  - code
roles/commons/tasks/main.yaml
- name: Install packages
  become: true
  ansible.builtin.package:
    name: "{{ packages_to_install }}"
    state: present
playbooks/perso/main.yaml
- hosts: localhost
  roles:
    - role: commons
      vars:
        packages_to_install: [vim, firefox]

Templating

- name: Template gitconfig
  ansible.builtin.template:
    src: templates/gitconfig.j2
    dest: "~/.gitconfig"
roles/git_config/templates/gitconfig.j2
[user]
{% if git_config_user is defined %}
  name = {{ git_config_user }}
{% endif %}
{% if git_config_email is defined %}
  email = {{ git_config_email }}
{% endif %}

Gestion des secrets

- name: "Copy secret file"
  copy:
    src: "secret_data.txt"
    dest: ~/secret_data.txt
    mode: "0600"
$ANSIBLE_VAULT;1.1;AES256
61613732623662623936633538623331663661303939636439316236633333356561646562356335
3936383330653736393132313565643539326666666366360a323539623938626232663965336264
32616364633761616231336464303732323936393131346536646465313162623537303363366265
6334613463623635620a663765366238353435373336373832396536386164346266626433303165
66336136313064323461613461303461643864316361653838333565396633616564

Gestion des secrets

$ ansible-vault create secret_data.txt
$ ansible-vault view secret_data.txt
Vault password:
Hello TNT#25 ! :)
$ ansible-playbook playbooks/work/main.yaml --ask-vault-pass

Mais encore ?

Indicateur batterie off
- name: Display battery percentage
  dconf:
    key: "/org/gnome/desktop/interface/show-battery-percentage"
    value: "true"
    state: present
Indicateur batterie on

Windows (regedit) : win_regedit_module

Avantages / Inconvénients

Objectif

État

Gérer mes fichiers de configuration

Gérer les logiciels installés

Versionnable

Facilement maintenable

Gérer mon poste de travail pro et perso

Gestion de secrets

Et si je veux faire…​

Conclusion

Standard
Slides
Slides
Vos retours
Feedback