---
- name: install nomachine node and RDP client
  yum:
    name:
      - "{{ nomachine_node_rpm }}"
      - freerdp.x86_64
      - remmina.x86_64
      - remmina-plugins-rdp.x86_64
    state: present
  tags: setup

- name: setup nx node
  template:
    src: nx_node.cfg
    dest: /usr/NX/etc/node.cfg
    owner: nx
    group: nx
    mode: 0644
  notify: restart_nx

- name: setup nx desktop
  template:
    src: start-desktop
    dest: /usr/local/bin/start-desktop
    owner: root
    group: root
    mode: 0755
  when: "'nomachine_nodes' not in group_names"

- name: copy monitoring scripts to extend node_exporter for nomachine
  get_url:
    url: "{{ nomachine_monitoring_scripts_url }}/{{ item }}"
    dest: "/usr/local/bin/{{ item }}"
    mode: 0755
  loop: "{{ nomachine_monitoring_scripts }}"

- name: setup crontab to collect nomachine metrics
  cron:
    name: "{{ item }}"
    minute: "*"
    job: "/usr/local/bin/{{ item }} > {{ node_exporter_textfile_dir }}/{{ item }}.prom"
    user: root
    cron_file: /etc/crontab
  loop: "{{ nomachine_monitoring_scripts }}"
