launch.yml 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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:
  27. hostname: "{{ item.public_ip }}"
  28. groupname: new_ec2_instances"
  29. with_items: ec2.instances
  30. - name: Add Name and environment tags to instances
  31. ec2_tag: "resource={{ item.1.id }} region={{ inst_region }} state=present"
  32. with_together:
  33. - oo_new_inst_names
  34. - ec2.instances
  35. args:
  36. tags:
  37. Name: "{{ item.0 }}"
  38. - name: Add other tags to instances
  39. ec2_tag: "resource={{ item.id }} region={{ inst_region }} state=present"
  40. with_items: ec2.instances
  41. args:
  42. tags: "{{ oo_new_inst_tags }}"
  43. - name: Add new instances public IPs to oo_nodes_to_config
  44. add_host:
  45. hostname: "{{ item.0 }}"
  46. ansible_ssh_host: "{{ item.1.dns_name }}"
  47. groupname: oo_nodes_to_config
  48. ec2_private_ip_address: "{{ item.1.private_ip }}"
  49. ec2_ip_address: "{{ item.1.public_ip }}"
  50. with_together:
  51. - oo_new_inst_names
  52. - ec2.instances
  53. - name: Wait for ssh
  54. wait_for: "port=22 host={{ item.dns_name }}"
  55. with_items: ec2.instances
  56. - name: Wait for root user setup
  57. command: "ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null root@{{ item.dns_name }} echo root user is setup"
  58. register: result
  59. until: result.rc == 0
  60. retries: 20
  61. delay: 10
  62. with_items: ec2.instances
  63. # Apply the configs, seprate so that just the configs can be run by themselves
  64. - include: config.yml