---
- hosts: all
  become: yes
  become_user: root
  become_method: sudo
  gather_facts: yes

  vars:
      raft_repo: "https://github.com/yossigo/redisraft"
      raft_branch: "cluster"
      mypkgs:
        - git
        - gcc
        - make
        - rpm-build
        - autoconf
        - automake
        - libedit
        - openssl-devel
        - epel-release
        - libbsd-devel
        - libbsd
        - curl
        - gnupg2
        - libevent-devel

  pre_tasks:

    - name: Enable epel-release
      yum:
        name: epel-release
        state: latest

    - name: RedHat Dev Tools
      yum:
        name: "@Development tools"
        state: present

    - name: RedHat Packages
      package:
        name: "{{ mypkgs }}"

    - name: Get cmake version
      unarchive:
        src: "https://cmake.org/files/v3.19/cmake-3.19.1.tar.gz"
        dest: /usr/local/share/
        remote_src: yes

    - name: Bootstrap cmake
      command: "./bootstrap"
      args:
        chdir: /usr/local/share/cmake-3.19.1
        creates: /usr/local/share/cmake-3.19.1/Makefile
  
    - name: Cmake - Build install
      make:
        chdir: /usr/local/share/cmake-3.19.1
        target: install
    
    - name: Link cmake
      file:
        src: /usr/local/bin/cmake
        dest: /usr/bin/cmake
        state: link

  tasks:

    - name: raft - clone the github repo
      git:
        repo: "{{raft_repo}}"
        dest: /home/redis/redisraft
        version: "{{raft_branch}}"
        recursive: yes
        update: yes
        force: yes

    - name: raft - make
      make:
        chdir: /home/redis/redisraft

    - name: checkout redis git repo
      git:
        repo: 'https://github.com/redis/redis'
        dest: /home/redis/redis
  
    - name: redis - Build the default target
      make:
        chdir: /home/redis/redis

    - name: checkout memtier_benchmark git repo
      git:
        repo: 'https://github.com/RedisLabs/memtier_benchmark'
        dest: /home/redis/memtier_benchmark
  
    - name: memtier - Run the autoconf
      command: autoreconf -ivf
      args:
        chdir: /home/redis/memtier_benchmark
        creates: /home/redis/memtier_benchmark/configure
  
    - name: memtier - Run the configure script first
      command: ./configure
      args:
        chdir: /home/redis/memtier_benchmark
        creates: /home/redis/memtier_benchmark/Makefile
  
    - name: memtier - Build the default target
      make:
        chdir: /home/redis/memtier_benchmark
  
    - name: Run 'memtier_benchmark install' target as root
      make:
        chdir: /home/redis/memtier_benchmark
        target: install
      become: yes
  
  

  roles:
    - { 
        role: rvm.ruby,
        rvm1_rubies: ['ruby-2.7'],
        rvm1_install_flags: '--auto-dotfiles',
        rvm1_install_path: /usr/local/rvm, 
        rvm1_user: 'root',
        rvm1_bundler_install: True
       }

#  post_tasks:
#
#   - name: Install FPM
#     community.general.gem:
#       name: fpm
#       state: present

