---
- hosts: all
  roles:
    - role: common
    - role: service_sshd
    - role: ssh_site_login
    - role: thruk_developer
    - role: thruk_plugin_editor
    - role: node_control_client
  tasks:
  - copy:
      src: "/root/thruk_local.conf"
      dest: "/omd/sites/demo/etc/thruk/thruk_local.conf"
      owner: "demo"
      group: "demo"

  - copy:
      src: "/scenario/objects.cfg"
      dest: "/omd/sites/demo/etc/naemon/conf.d/objects.cfg"
      owner: "demo"
      group: "demo"
  - shell: sed -e "s/###SITE###/{{ lookup('env','PREFIX') }}/g" -i /omd/sites/demo/etc/naemon/conf.d/objects.cfg -i /omd/sites/demo/etc/thruk/thruk_local.conf

  - shell: echo "key_tier2a" > /omd/sites/demo/var/thruk/secret.key

  - file:
      path: /omd/sites/demo/var/thruk/secret.key
      mode: 0600
      owner: demo
      group: demo

  - copy:
      src: "{{ item }}"
      dest: "/omd/sites/demo/etc/thruk/bp/"
      owner: "demo"
      group: "demo"
    with_fileglob:
    - /root/*.tbp

  - name: "disable shutdown warnings"
    lineinfile:
      dest: /opt/omd/sites/{{ site }}/.thruk
      create: true
      line: "export THRUK_NO_SHUTDOWN_WARNINGS=1"
      regexp: 'export THRUK_NO_SHUTDOWN_WARNINGS'

  - name: "thruk bp commit"
    shell: sudo su - demo -c "thruk bp commit"

  - name: "wait for {{ item }} to come up"
    uri:
      url: "https://{{ item }}.tier3.test.local/demo/thruk/cgi-bin/remote.cgi"
      validate_certs: False
      status_code: 200
    register: result
    until: result.status == 200
    retries: 180
    delay: 1
    with_items:
      - tier3a
      - tier3b

  - include_role:
      name: thruk_logcache_mysql

  - shell: sudo su - demo -c "git add . && git commit -m 'setup complete'"
