- name: "Install Rabbit MQ"
  hosts:
    - rabbitmq-39-1
  tasks:
    - name: Install components and prerequisites
      apt:
        name:
          - curl
          - gnupg
          - apt-transport-https
        state: present

    - name: Add repository
      apt_repository:
        repo: "ppa:rabbitmq/rabbitmq-erlang-25"
        state: present

    - name: Update APT
      apt:
        update_cache: yes

    - name: Install RabbitMQ
      apt:
        name:
          - erlang-base
          - erlang-asn1
          - erlang-crypto
          - erlang-eldap
          - erlang-ftp
          - erlang-inets
          - erlang-mnesia
          - erlang-os-mon
          - erlang-parsetools
          - erlang-public-key
          - erlang-runtime-tools
          - erlang-snmp
          - erlang-ssl
          - erlang-syntax-tools
          - erlang-tftp
          - erlang-tools
          - erlang-xmerl
          - rabbitmq-server
        state: present

    - name: Enable RabbitMQ service
      systemd:
        name: rabbitmq-server
        enabled: yes

    - name: Start RabbitMQ service
      systemd:
        name: rabbitmq-server
        state: restarted
