---
- hosts: all
  roles:
    - role: common
    - role: local_tests
    - role: thruk_developer
  tasks:
  - name: "omd config change"
    shell: "omd config demo change"
    args:
      stdin: |
        APACHE_MODE=own
        LIVESTATUS_TCP=on
        LIVESTATUS_TCP_PORT=7001

  - copy:
      src: "/root/thruk_local.conf"
      dest: "/omd/sites/demo/etc/thruk/thruk_local.conf"
      owner: "demo"
      group: "demo"

  - name: "create secret.key"
    shell: echo "testkey" > /omd/sites/demo/var/thruk/secret.key
  - name: "set permissions on secret.key"
    file:
      path: /omd/sites/demo/var/thruk/secret.key
      mode: 0600
      owner: demo
      group: demo

  - name: create symlink to agents plugin
    shell: "ln -sfn /thruk/plugins/plugins-available/agents /opt/omd/sites/demo/etc/thruk/plugins-enabled/agents"

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

  - name: wait for livestatus backend to become available
    wait_for:
      host: livestatus-backend
      port: 7001

