- name: Activer les backports
  lineinfile:
    path: /etc/apt/sources.list.d/backports.list
    line: deb http://ftp.debian.org/debian buster-backports main contrib
    create: yes
    state: present

- name: Installer les paquets de base
  apt:
    state: present
    name: "{{ packages }}"
    update_cache: yes
  vars:
    packages:
      - git
      - subversion
      - mercurial
      - htop
      - tmux
      - vim
      - emacs
      - certbot
      - mutt
      - weechat
      - elinks
      - rustc
      - cargo
      - cargo-doc
      - rsync
      - dnsutils
      - make
      - g++
      - libssl-dev
      - mosh
      - tor
      - sudo

- name: setup certbot with contact email
  copy:
    src: ../files/letsencrypt_cli.ini
    dest: /etc/letsencrypt/cli.ini

- include: tor.yml

- include: rust_packages.yml

- include: users.yml

- name: Créer le dossier /home/peers
  file:
    path: "/home/peers"
    state: directory

- name: Créer un compte peer pour se connecter avec d'autres serveurs
  user:
    name: "peer"
    state: present
    skeleton: /etc/skel
    shell: /bin/bash
    system: no
    createhome: yes
    home: "/home/peers/{{ hostname }}"

- name: Créer un lien symbolique /home/peers/self
  file:
    dest: /home/peers/self
    src: "/home/peers/{{ hostname }}"
    state: link

- file:
    path: /home/peers/self/.ssh
    owner: peer
    group: peer
    state: directory

- name: Générer une clé SSH pour le compte peer
  become: yes
  become_user: peer
  command:
    creates: /home/peers/self/.ssh/id_ed25519.pub
    cmd: ssh-keygen -t ed25519 -f /home/peers/self/.ssh/id_ed25519 -N ""

- name: Configurer SSH en ed25519 depuis le compte peer
  copy:
    src: ../files/ssh_config
    dest: /home/peers/self/.ssh/config

- name: Générer les comptes 
  include: peers.yml
  loop: "{{ peers }}"
