---
- 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
      \"; expect \"Enable anonymous usage / statistics reporting \(Y/n\):\"; send
      \"n \"; expect \"Enable anonymous statistical reporting of installed software
      / hardware \(Y/n\):\"; send \"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 \"; expect \"\(Y/n\):\"; send -- \"y\r\"; expect
      \"Enter a name to save these results under:\"; send \"ram \"; expect \"Enter
      a unique name to describe this test run / configuration:\"; send -- \"ram_conf\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 \"; expect \"File Size:\"; send \"2 \"; expect
      \"Disk Test:\"; send \"3 \";  expect \"\(Y/n\):\"; send -- \"y\r\"; expect \"Enter
      a name to save these results under:\"; send \"disk_out \"; expect \"Enter a unique
      name to describe this test run / configuration:\"; send -- \"disk_conf\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 ram,
    register: streamoutput, become: true}
  - {debug: 'msg="{{ streamoutput.stdout }}"'}
  
    - {name: Get stream results, command: phoronix-test-suite result-file-to-csv disk_out,
    register: streamoutput, become: true}
  - {debug: 'msg="{{ streamoutput.stdout }}"'}