---
- name: Install fmc and fedora-messaging rpm
  package:
    name:
      - fedora-messaging
      # fmc rpm is built in infra tags
      - fmc
    state: present
  when: inventory_hostname.startswith('odcs-backend-releng')
  tags:
  - fmc

- name: Place fedora-minimal-compose.toml /etc/fedora-messaging/
  template:
    src: fedora-minimal-compose.toml
    dest: /etc/fedora-messaging/fedora-minimal-compose.toml
    owner: root
    group: root
    mode: 644
  when: inventory_hostname.startswith('odcs-backend-releng')
  tags:
  - fmc

- name: Start and enable the fmc services
  service:
    name: fm-consumer@fedora-minimal-compose
    state: started
    enabled: yes
  when: inventory_hostname.startswith('odcs-backend-releng')
  tags:
  - fmc

- name: Create /etc/pki/fedora-messaging
  file:
    dest: /etc/pki/fedora-messaging
    mode: 0775
    owner: root
    group: root
    state: directory
  tags:
  - fmc

- name: Deploy the fedora-messaging CA
  copy:
    src: "{{ private }}/files/rabbitmq/{{env}}/pki/ca.crt"
    dest: /etc/pki/fedora-messaging/cacert.pem
    mode: 0644
    owner: root
    group: root
  tags:
  - fmc

- name: Deploy the fedora-messaging cert
  copy:
    src: "{{ private }}/files/rabbitmq/{{env}}/pki/issued/fmc{{env_suffix}}.crt"
    dest: /etc/pki/fedora-messaging/fmc-cert.pem
    mode: 0644
    owner: root
    group: root
  tags:
  - fmc

- name: Deploy the fedora-messaging key
  copy:
    src: "{{ private }}/files/rabbitmq/{{env}}/pki/private/fmc{{env_suffix}}.key"
    dest: /etc/pki/fedora-messaging/fmc-key.pem
    mode: 0600
    owner: root
    group: root
  tags:
  - fmc
