---
- hosts: all
  roles:
    - role: common
    - role: thruk_developer
  tasks:
  - name: "yum install krb5 client"
    include_role:
      name: yum_apt_retry
    vars:
      package:
        - mod_auth_gssapi
        - krb5-workstation
  - name: "omd config change"
    shell: "omd config demo change"
    args:
      stdin: |
        THRUK_COOKIE_AUTH=off
        GRAFANA=on
        INFLUXDB=on
        MOD_GEARMAN=on
        NAGFLUX=on
        PNP4NAGIOS=gearman
  - lineinfile:
      path: /omd/sites/demo/etc/mod-gearman/server.cfg
      regexp: '^perfdata='
      line: 'perfdata=nagflux'
  - lineinfile:
      path: /omd/sites/demo/etc/nagflux/config.gcfg
      regexp: '^\s*Queue\s*='
      line: '        Queue = "nagflux"'
  - replace:
      dest=/omd/sites/demo/etc/nagflux/config.gcfg
      regexp='(ModGearman "example".*)Enabled = \w'
      replace='\1        Enabled = true'
  - lineinfile:
      path: /omd/sites/demo/etc/nagflux/config.gcfg
      regexp: '^\s*Queue\s*='
      line: '        Enabled = true'
  - copy:
      src: /omd/sites/demo/share/doc/naemon/example.cfg
      dest: /omd/sites/demo/etc/naemon/conf.d/example.cfg
      owner: demo
      group: demo
  - shell: sed -e "s/localhost/remote-pnp/g" -i /omd/sites/demo/etc/naemon/conf.d/example.cfg
  - copy:
      src: /root/naemon_grafana_example.cfg
      dest: /omd/sites/demo/etc/naemon/conf.d/naemon_grafana_example.cfg
      owner: demo
      group: demo
  - lineinfile:
      path: /omd/sites/demo/etc/thruk/cgi.cfg
      regexp: '^authorized_for_admin='
      line: 'authorized_for_admin=omdadmin,demo'
  - shell: echo "testkey" > /omd/sites/demo/var/thruk/secret.key
  - file:
      path: /omd/sites/demo/var/thruk/secret.key
      mode: 0600
      owner: demo
      group: demo
  - name: create krb folder
    file:
      path: /omd/sites/demo/etc/krb
      state: directory
      owner: demo
      group: demo
      mode: 0770
  - copy:
      src: /root/krb5.conf
      dest: /omd/sites/demo/etc/krb/krb5.conf
      owner: demo
      group: demo
  - copy:
      src: /root/apache_auth_krb5.conf
      dest: /omd/sites/demo/etc/apache/conf.d/auth.conf
      owner: demo
      group: demo
  - name: wait for kerberos to become available
    wait_for:
      host: krb5.test.local
      port: 88
  - name: wait for kerberos admin server to become available
    wait_for:
      host: krb5.test.local
      port: 749
  - lineinfile:
      path: /omd/sites/demo/.profile
      regexp: '^export KRB5_CONFIG'
      line: 'export KRB5_CONFIG=/omd/sites/demo/etc/krb/krb5.conf'
  - shell: "sudo su - demo -c 'yes omd | kinit -f HTTP/omd2.test.local'"
  - shell: "sudo su - demo -c 'echo -e \"addent -password -p HTTP/omd2.test.local -k 1 -e aes256-cts\nomd\nwkt etc/krb/omd.keytab\" | ktutil'"
