launch.yml 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. "expirationDate": "{{ item.aws_expiration_date | default(aws_expiration_date) }}"
  47. }
  48. - name: Add machine to inventory
  49. add_host:
  50. name: "{{ item.instances.0.tags['Name'] }}"
  51. ansible_host: "{{ item.instances.0.dns_name }}"
  52. ansible_user: "{{ item.instances.0.aws_user | default(aws_user)}}"
  53. groups: "{{ item.instances.0.tags['ansible-groups'].split(',') }}"
  54. aws_region: "{{ aws_region }}"
  55. aws_ip: "{{ item.instances.0.public_ip }}"
  56. aws_id: "{{ item.instances.0.id }}"
  57. openshift_node_group_name: "{{ item.instances.0.tags['ansible-node-group'] }}"
  58. with_items: "{{ ec2.results }}"
  59. - name: write the inventory
  60. template:
  61. src: ./template-inventory.j2
  62. dest: "inventory/hosts"
  63. - name: Refresh inventory to ensure new instances exist in inventory
  64. meta: refresh_inventory
  65. - hosts: all
  66. gather_facts: no
  67. become: true
  68. tasks:
  69. - wait_for_connection: {}
  70. - setup: {}
  71. - import_playbook: ../../playbooks/openshift-node/network_manager.yml
  72. - import_playbook: ../../playbooks/prerequisites.yml
  73. - import_playbook: ../../playbooks/deploy_cluster.yml