- name: "install perl / git dependencies"
  include_role:
    name: yum_apt_retry
  vars:
    rpm:
      - perl-ExtUtils-Manifest
      - perl-ExtUtils-Install
      - git-core
    deb:
      - git
    package:
      - make
      - strace
    creates:
      - "/usr/share/perl5/vendor_perl/ExtUtils/Manifest.pm,/usr/share/perl/*/ExtUtils/Manifest.pm"
      - "/usr/share/perl5/vendor_perl/ExtUtils/Install.pm,/usr/share/perl5/ExtUtils/Install.pm,/usr/share/perl/*/ExtUtils/Install.pm"
      - /usr/bin/git
      - /usr/bin/make
      - /usr/bin/strace

- stat: path=/usr/lib/locale/en_US.utf8
  register: locale_path
- name: "glibc-langpack-en when rhel >= 8"
  include_role:
    name: yum_apt_retry
  vars:
    package:
      - glibc-langpack-en
  when:
      - not locale_path.stat.exists
      - ansible_os_family == 'RedHat'
      - ansible_distribution_version|int >= 8

- name: "install File::ChangeNotify"
  shell: "sudo su - {{ site }} -c 'cpanm -n File::ChangeNotify'"
  args:
    creates: "/omd/sites/{{ site }}/local/lib/perl5/lib/perl5/File/ChangeNotify.pm"

- name: "git clone omd_utils"
  shell: "sudo su - {{ site }} -c 'cd ~/local/share && git clone --depth=1 --branch=master https://github.com/sni/omd_utils.git'"
  args:
    creates: "/omd/sites/{{ site }}/local/share/omd_utils"

- stat: path=/thruk
  register: thruk_path
- name: "run install.sh from omd_utils"
  shell: "sudo su - {{ site }} -c 'yes | NONINTERACTIVE=1 ~/local/share/omd_utils/thruk_developer/install.sh /thruk'"
  when: thruk_path.stat.exists
- name: "disable auto restarts"
  shell: "sudo su - {{ site }} -c 'touch .THRUK_RESTARTER_DISABLED'"
- name: "add file to .gitignore"
  lineinfile:
    dest: /opt/omd/sites/{{ site }}/.gitignore
    line: ".THRUK_RESTARTER_DISABLED"
    regexp: '^.THRUK_RESTARTER_DISABLED'
