---
- hosts: all
  roles:
    - role: common
  tasks:
  - name: "yum install postgresql"
    include_role:
      name: yum_apt_retry
    vars:
      package:
        - postgresql
  - name: "omd config change"
    shell: "omd config demo change"
    args:
      stdin: |
        APACHE_MODE=own
        CORE=icinga2
        LIVESTATUS_TCP=on
        MYSQL=on
        ICINGA2_IDO=mysql
  - shell: sudo su - demo -c "icinga2 feature disable compatlog"
  - shell: sed -i -e 's/^skip-networking/#skip-networking\nbind-address = 0.0.0.0\n/g' /opt/omd/sites/demo/.my.cnf
  - shell: sudo su - demo -c "icinga2 feature enable ido-pgsql"
  - name: hold until Postgresql is up and running
    wait_for:
      host: postgresdb
      port: 5432
  - shell: PGPASSWORD=icinga psql -h postgresdb -U icinga -w < /omd/sites/demo/share/icinga2-ido-pgsql/schema/pgsql.sql
  - lineinfile:
      path: /opt/omd/sites/demo/etc/icinga2/features-available/ido-pgsql.conf
      regexp: 'user ='
      line: '    user = "icinga"'
  - lineinfile:
      path: /opt/omd/sites/demo/etc/icinga2/features-available/ido-pgsql.conf
      regexp: 'password ='
      line: '    password = "icinga"'
  - lineinfile:
      path: /opt/omd/sites/demo/etc/icinga2/features-available/ido-pgsql.conf
      regexp: 'host ='
      line: '    host = "postgresdb"'
  - lineinfile:
      path: /opt/omd/sites/demo/etc/icinga2/features-available/ido-pgsql.conf
      regexp: 'database ='
      line: '    database = "icinga"'
  - 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
  - copy:
      src: /root/utf8.conf
      dest: /omd/sites/demo/etc/icinga2/conf.d/utf8.conf
      owner: demo
      group: demo
  - copy:
      src: /root/add_user.sh
      dest: /omd/sites/demo/etc/init-hooks.d/mysql-start-post
      mode: 0755
      owner: demo
      group: demo
