---
- hosts: localhost
  gather_facts: false
  connection: local

  pre_tasks:
    - name: "Import constraints check"
      import_tasks: tasks/constraints_check.yml
      become: false
      tags:
        - always

- name: 'apply setup to {{ host | default("all") }}'
  hosts: '{{ host | default("all") }}'
  serial: "{{ serial_number | default(10) }}"
  vars:
    ansible_ssh_host: "{{ stage_server_domain }}"
  remote_user: root
  become: yes

  pre_tasks:
    - name: "Import autodiscover pre-tasks"
      import_tasks: tasks/autodiscover_pre_tasks.yml
      become: false
      tags:
        - always

    - name: Remove outdated dependencies
      apt:
        name: [
          'docker',
          'docker-client',
          'docker-client-latest',
          'docker-common',
          'docker-latest',
          'docker-latest-logrotate',
          'docker-logrotate',
          'docker-engine',
          'smartmontools',
          'mc',
        ]
        state: 'absent'
      when: ansible_distribution == "Ubuntu"
      tags:
        - common
        - install

  roles:
    - role: ansible-role-docker
      when:
        - docker_enabled

    - role: hetzner-ansible-common
      tags:
        - common

    - role: devsec.hardening.ssh_hardening
      tags:
        - ssh_hardening 

    - role: hetzner-ansible-node-exporter
      when:
        - node_exporter_enabled
      tags:
        - node-exporter

    - role: hetzner-ansible-filebeat
      when:
        - docker_enabled
        - filebeat_enabled
      tags:
        - filebeat

    - role: hetzner-ansible-metricbeat
      when:
        - docker_enabled
        - metricbeat_enabled
      tags:
        - metricbeat

    - role: hetzner-ansible-traefik
      when:
        - docker_enabled
        - traefik_enabled
      tags:
        - traefik
