---
- name: Add GitHub CLI repo
  ansible.builtin.yum_repository:
    name: gh-cli
    description: GitHub CLI
    baseurl: https://cli.github.com/packages/rpm
    gpgkey: https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x23F3D4EA75716059
    gpgcheck: true
    enabled: true

- name: Install gh CLI
  ansible.builtin.dnf:
    name: gh
    state: present

- name: Create state directory
  ansible.builtin.file:
    path: "{{ hermes_auto_improve_state_dir }}"
    state: directory
    mode: '0755'

- name: Deploy auto-improve script
  ansible.builtin.copy:
    src: "{{ playbook_dir }}/../../tools/hermes-auto-improve/auto-improve.py"
    dest: /usr/local/bin/hermes-auto-improve
    mode: '0755'
  notify: Restart hermes-auto-improve-server

- name: Deploy trigger server
  ansible.builtin.copy:
    src: "{{ playbook_dir }}/../../tools/hermes-auto-improve/trigger-server.py"
    dest: /usr/local/bin/hermes-auto-improve-server
    mode: '0755'
  notify: Restart hermes-auto-improve-server

- name: Deploy systemd service
  ansible.builtin.template:
    src: hermes-auto-improve.service.j2
    dest: /etc/systemd/system/hermes-auto-improve.service
    mode: '0644'
  notify: Restart hermes-auto-improve-server

- name: Enable and start service
  ansible.builtin.systemd:
    name: hermes-auto-improve
    enabled: true
    state: started
    daemon_reload: true

