main.yml 1.0 KB

12345678910111213141516171819202122232425262728
  1. - name: ensure droplets exist
  2. digital_ocean: >
  3. state=present
  4. command=droplet
  5. unique_name=yes
  6. name={{ item }}
  7. size_id=512mb
  8. region_id=nyc1
  9. image_id=debian-8-x64
  10. ssh_key_ids={{ desktap.ssh_key.id }}
  11. with_items: "{{ droplets }}"
  12. register: droplet_details
  13. - name: Save IP/ID/Group to file
  14. local_action: copy content="{{ item['droplet']['ip_address'] }}" dest="/tmp/outfile{{item['droplet']['name']}}"
  15. with_items: "{{ droplet_details.results }}"
  16. - name: Add new droplet to host group
  17. local_action: add_host hostname={{ item['droplet']['ip_address'] }} groupname={{ dogroupname }}
  18. with_items: "{{ droplet_details.results }}"
  19. - name: Wait for SSH to come up
  20. local_action: wait_for host={{ item['droplet']['ip_address'] }} port=22 delay=5 timeout=320 state=started
  21. with_items: "{{ droplet_details.results }}"
  22. - name: Keyscan droplets
  23. local_action: shell ssh-keyscan {{ item['droplet']['ip_address'] }} >> ~/.ssh/known_hosts
  24. with_items: "{{ droplet_details.results }}"