---
- hosts: all
  roles:
    - role: common
    - role: local_tests
    - role: thruk_developer
    #- role: naemon_debug_log
  tasks:
  - name: "yum install krb5 dependencies"
    include_role:
      name: yum_apt_retry
    vars:
      package:
        - mod_auth_gssapi
        - krb5-workstation
  - name: "omd config change"
    shell: "omd config demo change"
    args:
      stdin: |
        APACHE_MODE=own
        THRUK_COOKIE_AUTH=sso-support
        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/mod-gearman/server.cfg
  #    regexp: '^debug='
  #    line: 'debug=2'
  #- lineinfile:
  #    path: /omd/sites/demo/etc/nagflux/config.gcfg
  #    regexp: '^\s*MinSeverity\s*='
  #    line: '        MinSeverity = "TRACE"'
  - replace:
      dest=/omd/sites/demo/etc/nagflux/config.gcfg
      after='ModGearman "example"'
      before='Worker'
      regexp='.*Enabled = \w+'
      replace='       Enabled = true'
  - lineinfile:
      path: /omd/sites/demo/etc/nagflux/config.gcfg
      regexp: '^\s*Queue\s*='
      line: '        Queue = "nagflux"'
  - copy:
      dest: /omd/sites/demo/etc/nagflux/nagios_nagflux.cfg
      content: ""
  - 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/local-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
  - copy:
      src: "/root/thruk_local.conf"
      dest: "/omd/sites/demo/etc/thruk/thruk_local.conf"
      owner: "demo"
      group: "demo"
  - name: create api key folder
    file:
      path: /omd/sites/demo/var/thruk/api_keys
      state: directory
      owner: demo
      group: demo
      mode: 0770
  - shell: "echo '{ \"user\" : \"omdadmin\" }' > /omd/sites/demo/var/thruk/api_keys/e90f647f602519d946bc877c908194ab97cf08c8ad6add4122adebd1b46fbe21.SHA-256; chown demo: /omd/sites/demo/var/thruk/api_keys/e90f647f602519d946bc877c908194ab97cf08c8ad6add4122adebd1b46fbe21.SHA-256"
  - name: create api key folder
    file:
      path: /omd/sites/demo/var/thruk/sessions
      state: directory
      owner: demo
      group: demo
      mode: 0770
  - shell: "echo '{\"fake\":1,\"hash\":\"none\",\"username\":\"omdadmin\"}' > /omd/sites/demo/var/thruk/sessions/6c00acbf83ec24ca10c04878eeac2aea956fb3224e82cf772f16b6758c1e3192.SHA-256; chown demo: /omd/sites/demo/var/thruk/sessions/6c00acbf83ec24ca10c04878eeac2aea956fb3224e82cf772f16b6758c1e3192.SHA-256"
  - 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/omd.test.local'"
  - shell: "sudo su - demo -c 'echo -e \"addent -password -p HTTP/omd.test.local -k 1 -e aes256-cts\nomd\nwkt etc/krb/omd.keytab\" | ktutil'"
