---
- hosts: all
  become: true
  tasks:

  - name: Installe paquets  git et ansible
    apt:
      name:
        - git
        - ansible
      state: present

  - name: Recupere paquet semaphore
    get_url:
      url: https://github.com/ansible-semaphore/semaphore/releases/download/v2.8.75/semaphore_2.8.75_linux_amd64.deb
      dest: /tmp/

  - name: Installie paquet semaphore
    apt:
      deb: semaphore_2.8.75_linux_amd64.deb

  - name: cree repert /etc/semaphore
    file:
      path: /etc/semaphore
      state: directory
      mode: '0755'

  - name: constitution fichier semaphore.service
    blockinfile:
      path: /etc/systemd/system/semaphore.service
      mode: '0644'
      create: yes
      block: |
        [Unit]
        Description=Semaphore Ansible
        Documentation=https://github.com/ansible-semaphore/semaphore
        Wants=network-online.target
        After=network-online.target

        [Service]
        Type=simple
        ExecReload=/bin/kill -HUP $MAINPID
        ExecStart=/usr/bin/semaphore service --config=/etc/semaphore/config.json
        SyslogIdentifier=semaphore
        Restart=always

        [Install]
        WantedBy=multi-user.target

  - name: reload daemon-reload
    service:
      name: semaphore
      state: started
      enabled: yes