---
- hosts: all
  tasks:
    - name: install sysbench
      apt: name="{{ item }}" update_cache=yes state=latest
      with_items:
      - phoronix-test-suite
      - sysbench
      - expect
      - git
      - python-pexpect
      - php-zip
      become: true
      
    - name: Phoronix-test-suite accept User Agreement
      command: expect -c "spawn phoronix-test-suite; expect \"Do you agree to these terms and wish to proceed \(Y/n\):\"; send \"Y\n\"; expect \"Enable anonymous usage / statistics reporting \(Y/n\):\"; send \"n\n\"; expect \"Enable anonymous statistical reporting of installed software / hardware \(Y/n\):\"; send \"n\n\"; interact;"
      become: true

    - name: Install stream
      command: phoronix-test-suite install-test stream
      become: true

    - name: Install iozone
      command: phoronix-test-suite install-test iozone
      become: true


    - name: Count vCPU
      command: nproc
      register: vcpunumber
      become: true
    - debug: msg="{{ vcpunumber.stdout }}"


    - name: Run sysbench
      command: sysbench --test=cpu --cpu-max-prime=100000 --num-threads={{ vcpunumber.stdout }} run
      register: sysbenchoutput
      become: true
    - debug: msg="{{ sysbenchoutput.stdout }}"


    - name: Run stream
      command: expect -c "spawn phoronix-test-suite run-test stream; expect \"Type:\"; send \"4\n\"; expect \"\(Y/n\):\"; send -- \"y\r\"; expect \"Enter a name to save these results under:\"; send \"out\n\"; expect \"Enter a unique name to describe this test run / configuration:\"; send -- \"unique\r\"; expect \"New Description:\"; send  \"\r\"; expect \"Would you like to upload the results to OpenBenchmarking.org (Y/n):\"; send  \"n\r\"; interact;"
      register: streamoutput
      become: true
    - debug: msg="{{ streamoutput.stdout }}"
    

    - name: Run iozone
      command: expect -c "spawn phoronix-test-suite run-test iozone; expect \"Record Size:\"; send \"2\n\"; expect \"File Size:\"; send \"2\n\"; expect \"Disk Test:\"; send \"3\n\";  expect \"\(Y/n\):\"; send -- \"y\r\"; expect \"Enter a name to save these results under:\"; send \"out\n\"; expect \"Enter a unique name to describe this test run / configuration:\"; send -- \"unique\r\"; expect \"New Description:\"; send  \"\r\"; expect \"Would you like to upload the results to OpenBenchmarking.org (Y/n):\"; send  \"n\r\"; interact;"
      register: iozoneoutput
      become: true
      
    - name: Get stream results
      command: phoronix-test-suite result-file-to-csv out
      register: streamoutput
      become: true
    - debug: msg="{{ streamoutput.stdout }}"