launch.yml 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ---
  2. - hosts: localhost
  3. connection: local
  4. gather_facts: false
  5. tasks:
  6. - include_vars: "{{ item }}"
  7. with_first_found:
  8. - vars.yml
  9. - vars.yaml
  10. - name: list available AMIs
  11. ec2_ami_facts:
  12. region: "{{ aws_region }}"
  13. filters: "{{ aws_ami_tags }}"
  14. register: ami_facts
  15. when: aws_image is not defined
  16. - name: determine which AMI to use
  17. set_fact:
  18. aws_image: "{{ ami_facts.images[-1].image_id }}"
  19. when: aws_image is not defined
  20. - name: determine which AMI to use
  21. set_fact:
  22. aws_image: "{{ ami_facts.images[-1].image_id }}"
  23. when: aws_image is not defined
  24. - name: Create EC2 instance
  25. ec2:
  26. region: "{{ aws_region }}"
  27. key_name: "{{ aws_key }}"
  28. instance_type: "{{ item.aws_flavor }}"
  29. image: "{{ item.aws_image | default(aws_image) }}"
  30. wait: yes
  31. group: "{{ item.aws_security_group }}"
  32. count: 1
  33. vpc_subnet_id: "{{ aws_subnet }}"
  34. assign_public_ip: yes
  35. instance_tags: "{{ aws_instance_tags }}"
  36. volumes: "{{ item.aws_volumes | default(omit) }}"
  37. register: ec2
  38. with_items: "{{ aws_instances }}"
  39. vars:
  40. aws_instance_tags: |
  41. {
  42. "kubernetes.io/cluster/{{ aws_cluster_id }}": "true",
  43. "Name": "{{ item.name }}",
  44. "ansible-groups": "{{ item.ansible_groups | join(',') }}",
  45. "ansible-node-group": "{{ item.node_group }}",
  46. }
  47. - name: Add machine to inventory
  48. add_host:
  49. name: "{{ item.instances.0.tags['Name'] }}"
  50. ansible_host: "{{ item.instances.0.dns_name }}"
  51. ansible_user: "{{ item.instances.0.aws_user | default(aws_user)}}"
  52. groups: "{{ item.instances.0.tags['ansible-groups'].split(',') }}"
  53. aws_region: "{{ aws_region }}"
  54. aws_ip: "{{ item.instances.0.public_ip }}"
  55. aws_id: "{{ item.instances.0.id }}"
  56. openshift_node_group_name: "{{ item.instances.0.tags['ansible-node-group'] }}"
  57. with_items: "{{ ec2.results }}"
  58. - name: write the inventory
  59. template:
  60. src: ./template-inventory.j2
  61. dest: "inventory/hosts"
  62. - name: Refresh inventory to ensure new instances exist in inventory
  63. meta: refresh_inventory
  64. - hosts: all
  65. gather_facts: no
  66. become: true
  67. tasks:
  68. - wait_for_connection: {}
  69. - setup: {}
  70. - import_playbook: ../../playbooks/openshift-node/network_manager.yml
  71. - import_playbook: ../../playbooks/prerequisites.yml
  72. - import_playbook: ../../playbooks/deploy_cluster.yml