---
- hosts: ManagementNodes,LoginNodes,ComputeNodes
  gather_facts: false
  tasks:
  - name: add user hpctest
    user:
      name: hpctest
      shell: /bin/bash
    become: true

- hosts: ManagementNodes
  gather_facts: false
  tasks:
  - name: Create a parent account
    command: ./sacctmgr -i add account parentAccount cluster=m3 Description="Test parent account" Organization="Monash"
    args:
      chdir: '/opt/slurm-latest/bin'
    become: true
    register: result 
    failed_when: result.rc != 0 and result.stdout != " Nothing new added."
    
  - name: Create a project associated with a given parent
    command: ./sacctmgr -i add account testProject parent=parentAccount cluster=m3 Organization="Monash"
    args:
      chdir: '/opt/slurm-latest/bin'
    become: true
    register: result 
    failed_when: result.rc != 0 and result.stdout != " Nothing new added."
    
  - name: Create a user and associate them with a project
    command: ./sacctmgr -i create user hpctest cluster=m3 account=testProject
    args:
      chdir: '/opt/slurm-latest/bin'
    become: true 
    register: result 
    failed_when: result.rc != 0 and result.stdout != " Nothing new added."

- hosts: LoginNodes
  gather_facts: false
  tasks:
  - name: make sure munge is running
    service:
      name: munge
      state: started
    become: true
  - name: simple srun test
    command: ./srun --ntasks=1  --partition=batch  hostname
    args:
      chdir: '/opt/slurm-latest/bin'
    become: true       
    become_user: hpctest
