create_machineset.yml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ---
  2. - name: Create machineset_name
  3. set_fact:
  4. machineset_name: "{{ item.metadata.name ~ '-rhel'}}"
  5. - name: Update machineset definition
  6. set_fact:
  7. machineset: "{{ item | combine(dict_edit, recursive=True) }}"
  8. vars:
  9. dict_edit:
  10. metadata:
  11. name: "{{ machineset_name }}"
  12. resourceVersion: ""
  13. spec:
  14. replicas: 1
  15. selector:
  16. matchLabels:
  17. machine.openshift.io/cluster-api-machineset: "{{ machineset_name }}"
  18. template:
  19. metadata:
  20. labels:
  21. machine.openshift.io/cluster-api-machineset: "{{ machineset_name }}"
  22. spec:
  23. providerSpec:
  24. value:
  25. ami:
  26. id: "{{ openshift_aws_scaleup_ami }}"
  27. keyName: "{{ openshift_aws_scaleup_key }}"
  28. - name: Import machineset definition
  29. k8s:
  30. kubeconfig: "{{ kubeconfig_path }}"
  31. definition: "{{ machineset | to_yaml }}"
  32. - block:
  33. - name: Wait for machine to be created
  34. k8s_facts:
  35. api_version: machine.openshift.io/v1beta1
  36. kubeconfig: "{{ kubeconfig_path }}"
  37. namespace: openshift-machine-api
  38. kind: Machine
  39. label_selectors:
  40. - "machine.openshift.io/cluster-api-machineset={{ machineset_name }}"
  41. register: new_machine
  42. retries: 36
  43. delay: 5
  44. until:
  45. - new_machine.resources is defined
  46. - new_machine.resources | length > 0
  47. - new_machine.resources[0].status is defined
  48. - new_machine.resources[0].status.providerStatus is defined
  49. - new_machine.resources[0].status.providerStatus.instanceState is defined
  50. - new_machine.resources[0].status.providerStatus.instanceState == 'running'
  51. failed_when:
  52. - new_machine.resources is defined
  53. - new_machine.resources | length > 0
  54. - new_machine.resources[0].status is defined
  55. - new_machine.resources[0].status.phase == 'Failed'
  56. rescue:
  57. - name: Machine creation failed
  58. fail:
  59. msg: "Machine creation failed, error: {{ new_machine.resources[0].status.errorMessage }}"
  60. - name: Add machine to the inventory
  61. add_host:
  62. name: "{{ new_machine.resources[0].status.addresses | selectattr('type', 'match', '^InternalIP$') | map(attribute='address') | first }}"
  63. node_name: "{{ new_machine.resources[0].status.addresses | selectattr('type', 'match', '^InternalDNS$') | map(attribute='address') | first }}"
  64. groups: new_workers
  65. ansible_ssh_common_args: "-o ProxyCommand=\"ssh -o IdentityFile='{{ openshift_aws_scaleup_key_path | default('/opt/app-root/src/.ssh/id_rsa') }}' -o ConnectTimeout=30 -o ConnectionAttempts=100 -o StrictHostKeyChecking=no -W %h:%p -q core@{{ ssh_bastion }}\""