---
- hosts: all
  roles:
    - role: common
    - role: thruk_developer
  tasks:
  - name: "yum install perl depdendencies of Dancer2::Plugin::OAuth2::Server"
    include_role:
      name: yum_apt_retry
    vars:
      package:
        - gcc
        - perl-App-cpanminus
        - perl-Attribute-Handlers
        - perl-Class-Load
        - perl-Config-Any
        - perl-CryptX
        - perl-Getopt-Long-Descriptive
        - perl-Hash-Merge-Simple
        - perl-Import-Into
        - perl-LWP-Protocol-https
        - perl-Module-Build-Tiny
        - perl-Module-Metadata
        - perl-Moo
        - perl-Plack-Test
        - perl-Ref-Util
        - perl-Role-Tiny
        - perl-Safe-Isa
        - perl-Test-CPAN-Meta
        - perl-Type-Tiny
        - perl-URI
  - name: "omd config change"
    shell: "omd config demo change"
    args:
      stdin: |
        APACHE_MODE=own
        GRAFANA=on
        LIVESTATUS_TCP=on
  - copy:
      src: /omd/sites/demo/share/doc/naemon/example.cfg
      dest: /omd/sites/demo/etc/naemon/conf.d/example.cfg
      owner: demo
      group: demo
  - copy:
      src: /root/test.cfg
      dest: /omd/sites/demo/etc/naemon/conf.d/test.cfg
      owner: demo
      group: demo
  - copy:
      src: /root/thruk_local.conf
      dest: /omd/sites/demo/etc/thruk/thruk_local.conf
      owner: demo
      group: demo
  - copy:
      src: /root/grafana.ini
      dest: /omd/sites/demo/etc/grafana/grafana.ini
      owner: demo
      group: demo
  - name: Create /opt/omd/sites/demo/var/thruk/teams
    file:
      path: /opt/omd/sites/demo/var/thruk/teams
      state: directory
      mode: '0755'
      owner: demo
      group: demo
  - copy:
      src: /root/{{item}}.json
      dest: /opt/omd/sites/demo/var/thruk/teams/{{item}}.json
      owner: demo
      group: demo
    with_items: ['group1', 'group2', 'group3']
  - name: "install Dancer2::Plugin::OAuth2::Server"
    shell: "sudo su - {{ site }} -c 'cpanm -n Dancer2::Plugin::OAuth2::Server'"
    environment:
        CFLAGS: "-maes -msse2"
  - shell: sudo su - demo -c "( plackup -D -p 4444 /scenario/omd/oauth2_server/oauth2_server.pl >/dev/null 2>&1 & )"
