launch.yml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. - name: Make sure hostname is set to public ansible host
  71. hostname:
  72. name: "{{ ansible_host }}"
  73. - name: Detecting Operating System
  74. shell: ls /run/ostree-booted
  75. ignore_errors: yes
  76. failed_when: false
  77. register: ostree_output
  78. - name: Update all packages
  79. package:
  80. name: '*'
  81. state: latest
  82. when: ostree_output.rc != 0
  83. register: yum_update
  84. - name: Update Atomic system
  85. command: atomic host upgrade
  86. when: ostree_output.rc == 0
  87. register: ostree_update
  88. - name: Reboot machines
  89. shell: sleep 5 && systemctl reboot
  90. async: 1
  91. poll: 0
  92. ignore_errors: true
  93. when: yum_update | changed or ostree_update | changed
  94. - name: Wait for connection
  95. wait_for_connection:
  96. connect_timeout: 20
  97. sleep: 5
  98. delay: 5
  99. timeout: 300
  100. - setup: {}
  101. - import_playbook: ../../playbooks/openshift-node/network_manager.yml
  102. - import_playbook: ../../playbooks/prerequisites.yml
  103. - import_playbook: ../../playbooks/deploy_cluster.yml