launch.yml 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ---
  2. - name: Launch instance(s)
  3. hosts: localhost
  4. connection: local
  5. gather_facts: no
  6. vars:
  7. inst_region: us-east-1
  8. atomic_ami: ami-86781fee
  9. user_data_file: user_data.txt
  10. vars_files:
  11. - vars.yml
  12. tasks:
  13. - name: Launch instances
  14. ec2:
  15. state: present
  16. region: "{{ inst_region }}"
  17. keypair: libra
  18. group: ['public']
  19. instance_type: m3.large
  20. image: "{{ atomic_ami }}"
  21. count: "{{ oo_new_inst_names | oo_len }}"
  22. user_data: "{{ lookup('file', user_data_file) }}"
  23. wait: yes
  24. register: ec2
  25. - name: Add new instances public IPs to the atomic proxy host group
  26. add_host: "hostname={{ item.public_ip }} groupname=new_ec2_instances"
  27. with_items: ec2.instances
  28. - name: Add Name and environment tags to instances
  29. ec2_tag: "resource={{ item.1.id }} region={{ inst_region }} state=present"
  30. with_together:
  31. - oo_new_inst_names
  32. - ec2.instances
  33. args:
  34. tags:
  35. Name: "{{ item.0 }}"
  36. - name: Add other tags to instances
  37. ec2_tag: "resource={{ item.id }} region={{ inst_region }} state=present"
  38. with_items: ec2.instances
  39. args:
  40. tags: "{{ oo_new_inst_tags }}"
  41. - name: Add new instances public IPs to oo_hosts_to_config
  42. add_host: "hostname={{ item.0 }} ansible_ssh_host={{ item.1.dns_name }} groupname=oo_hosts_to_config"
  43. with_together:
  44. - oo_new_inst_names
  45. - ec2.instances
  46. - debug: var=ec2
  47. - name: Wait for ssh
  48. wait_for: "port=22 host={{ item.dns_name }}"
  49. with_items: ec2.instances
  50. - name: Wait for root user setup
  51. command: "ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null root@{{ item.dns_name }} echo root user is setup"
  52. register: result
  53. until: result.rc == 0
  54. retries: 20
  55. delay: 10
  56. with_items: ec2.instances
  57. # Apply the configs, seprate so that just the configs can be run by themselves
  58. - include: config.yml