---
# ansible-playbook -i hosts test.yaml -vv

- hosts: server
  gather_facts: false
  vars_prompt:
    - name: "cpus"
      prompt: "please input cpus"
      default: '1'
      private: no
  tasks:
    - name: Install NTP server
      yum:
        name: chronyd
        state: present
    - name: Start NTP server
      service:
        name: chronyd
        state: started
        enabled: yes
    - name: start-test-server
      shell: |
        for ((i=0; i<{{ cpus }}; i++ )); do
          echo $i
          date
        done
      args:
        executable: /bin/bash

- hosts: client
  gather_facts: false
  vars_prompt:
    - name: "cpus"
      prompt: "please input cpus"
      default: '1'
      private: yes
  tasks:
    - name: start-test-client
      shell: |
        echo {{ item }}
        date
        index="{{groups['client'].index(inventory_hostname)}}"
        port=$(expr $index + 1200)
        echo ${port}
        echo $(expr $port \* 2)
        echo ${key}
      with_items: "{{ groups['server'] }}"
