---
# this is a version of installPrereqs that uses a script on the targets to do most of the work
- hosts: all
  gather_facts: False
  remote_user: root
  #strategy: free

  tasks:

#  - name: upload script
#    copy: 
#      src: installPrereqs.sh
#      dest: .
#      mode: a+x

#  - name: run scripted installation
#    command: ./installPrereqs.sh {{ inventory_hostname }}
#    changed_when: True
#    register: installer
    #async: 3600
    #poll: 30

  - name: which rsync
    raw: "which rsync"
    changed_when: False
    #ignore_errors: yes

  - name: install instanceId.txt file
    shell: echo {{ inventory_hostname }} > ./instanceId.txt
    changed_when: True
    register: installer


  - name: create installed.inv (on master)
    delegate_to: localhost
    run_once: true
    raw: truncate --size 0 {{ lookup('env', 'PWD') }}/installed.inv

#  - name: show dateTimes
#    debug:
      #msg: "installerFinish {{ installer.stdout }}"
#      msg: "installerDateTimes,{{ inventory_hostname }},{{ installer.stdout_lines[0] }},{{ installer.stdout_lines[-1] }}"
#    ignore_errors: yes

- hosts: all
  gather_facts: False
  remote_user: root
  serial: 1

  tasks:

  - name: append installed.inv
    delegate_to: localhost
    lineinfile:
      line: >-
        {{ inventory_hostname }} ansible_python_interpreter={{ ansible_python_interpreter }}
        ansible_user={{ ansible_user }} ansible_ssh_host={{ansible_ssh_host }}
        ansible_port={{ ansible_port }}
      insertafter: EOF
      dest: "{{ lookup('env', 'PWD') }}/installed.inv"
