launch.yml 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_masters_to_config
  42. add_host:
  43. hostname: "{{ item.0 }}"
  44. ansible_ssh_host: "{{ item.1.dns_name }}"
  45. groupname: oo_masters_to_config
  46. ec2_private_ip_address: "{{ item.1.private_ip }}"
  47. ec2_ip_address: "{{ item.1.public_ip }}"
  48. with_together:
  49. - oo_new_inst_names
  50. - ec2.instances
  51. - name: Wait for ssh
  52. wait_for: "port=22 host={{ item.dns_name }}"
  53. with_items: ec2.instances
  54. - name: Wait for root user setup
  55. command: "ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null root@{{ item.dns_name }} echo root user is setup"
  56. register: result
  57. until: result.rc == 0
  58. retries: 20
  59. delay: 10
  60. with_items: ec2.instances
  61. # Apply the configs, seprate so that just the configs can be run by themselves
  62. - include: config.yml