create_machineset.yml 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ---
  2. - name: Create machineset_name
  3. set_fact:
  4. machineset_name: "{{ item.metadata.name ~ '-centos'}}"
  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. selector:
  15. matchLabels:
  16. machine.openshift.io/cluster-api-machineset: "{{ machineset_name }}"
  17. template:
  18. metadata:
  19. labels:
  20. machine.openshift.io/cluster-api-machineset: "{{ machineset_name }}"
  21. spec:
  22. providerSpec:
  23. value:
  24. ami:
  25. id: "{{ openshift_aws_scaleup_ami }}"
  26. keyName: "{{ openshift_aws_scaleup_key }}"
  27. - name: Import machineset definition
  28. k8s:
  29. kubeconfig: "{{ kubeconfig_path }}"
  30. definition: "{{ machineset | to_yaml }}"
  31. - name: wait for machine to be created
  32. k8s_facts:
  33. api_version: machine.openshift.io/v1beta1
  34. kubeconfig: "{{ kubeconfig_path }}"
  35. namespace: openshift-machine-api
  36. kind: Machine
  37. label_selectors:
  38. - "machine.openshift.io/cluster-api-machineset={{ machineset_name }}"
  39. register: new_machine
  40. retries: 36
  41. delay: 5
  42. until:
  43. - new_machine.resources is defined
  44. - new_machine.resources | length > 0
  45. - new_machine.resources[0].status is defined
  46. - new_machine.resources[0].status.providerStatus is defined
  47. - new_machine.resources[0].status.providerStatus.instanceState is defined
  48. - new_machine.resources[0].status.providerStatus.instanceState == 'running'
  49. - name: add machine to the inventory
  50. add_host:
  51. name: "{{ new_machine.resources[0].status.addresses | selectattr('type', 'match', '^InternalIP$') | map(attribute='address') | first }}"
  52. node_name: "{{ new_machine.resources[0].status.addresses | selectattr('type', 'match', '^InternalDNS$') | map(attribute='address') | first }}"
  53. groups: new_workers
  54. ansible_ssh_common_args: "-o ProxyCommand=\"ssh -o IdentityFile='{{ openshift_aws_scaleup_key_path | default('/opt/app-root/src/.ssh/id_rsa') }}' -o StrictHostKeyChecking=no -W %h:%p -q core@{{ ssh_bastion }}\""