provision_instance.yml 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. ---
  2. - name: query vpc
  3. ec2_vpc_net_facts:
  4. region: "{{ openshift_aws_region }}"
  5. filters:
  6. 'tag:Name': "{{ openshift_aws_vpc_name }}"
  7. register: vpcout
  8. - name: fetch the default subnet id
  9. ec2_vpc_subnet_facts:
  10. region: "{{ openshift_aws_region }}"
  11. filters:
  12. "tag:Name": "{{ openshift_aws_subnet_name }}"
  13. vpc-id: "{{ vpcout.vpcs[0].id }}"
  14. register: subnetout
  15. - name: create instance for ami creation
  16. ec2:
  17. assign_public_ip: yes
  18. region: "{{ openshift_aws_region }}"
  19. key_name: "{{ openshift_aws_ssh_key_name }}"
  20. group: "{{ openshift_aws_build_ami_group }}"
  21. instance_type: m4.xlarge
  22. vpc_subnet_id: "{{ openshift_aws_subnet_id | default(subnetout.subnets[0].id) }}"
  23. image: "{{ openshift_aws_base_ami }}"
  24. volumes:
  25. - device_name: /dev/sdb
  26. volume_type: gp2
  27. volume_size: 100
  28. delete_on_termination: true
  29. wait: yes
  30. exact_count: 1
  31. count_tag:
  32. Name: "{{ openshift_aws_base_ami_name }}"
  33. instance_tags:
  34. Name: "{{ openshift_aws_base_ami_name }}"
  35. - name: fetch newly created instances
  36. ec2_remote_facts:
  37. region: "{{ openshift_aws_region }}"
  38. filters:
  39. "tag:Name": "{{ openshift_aws_base_ami_name }}"
  40. instance-state-name: running
  41. register: instancesout
  42. retries: 20
  43. delay: 3
  44. until: instancesout.instances|length > 0
  45. - name: wait for ssh to become available
  46. wait_for:
  47. port: 22
  48. host: "{{ instancesout.instances[0].public_ip_address }}"
  49. timeout: 300
  50. search_regex: OpenSSH
  51. - name: Pause 10 seconds to ensure ssh actually accepts logins
  52. pause:
  53. seconds: 20
  54. - name: add host to nodes
  55. add_host:
  56. groups: nodes
  57. name: "{{ instancesout.instances[0].public_dns_name }}"