---

- name: remove old package
  apt:
    name: kvm-tools
    purge: yes
    state: absent

- include_role:
    name: remount-usr
  when: kvm_scripts_dir is search ("/usr")

- name: add-vm script is present
  copy:
    src: add-vm.sh
    dest: "{{ kvm_scripts_dir }}/add-vm"
    mode: "0700"
    owner: root
    group: root
    force: yes

- name: migrate-vm script is present
  copy:
    src: migrate-vm.sh
    dest: "{{ kvm_scripts_dir }}/migrate-vm"
    mode: "0700"
    owner: root
    group: root
    force: yes

- name: kvmstats script is present
  copy:
    src: kvmstats.sh
    dest: "{{ kvm_scripts_dir }}/kvmstats"
    mode: "0700"
    owner: root
    group: root
    force: yes

- name: kvmstats cron is present
  template:
    src: kvmstats.cron.j2
    dest: "/etc/cron.hourly/kvmstats"
    mode: "0755"
    owner: root
    group: root

- name: entry for kvmstats in web page is present
  lineinfile:
    dest: /var/www/index.html
    insertbefore: '</ul>'
    line: '<li><a href="/kvmstats.html">kvmstats</a></li>'


# backward compatibility

- name: remove old migrate-vm script
  file:
    path: /usr/share/scripts/migrate-vm
    state: absent
  when: "'/usr/share/scripts' not in kvm_scripts_dir"

- name: remove old kvmstats script
  file:
    path: /usr/share/scripts/kvmstats
    state: absent
  when: "'/usr/share/scripts' not in kvm_scripts_dir"