create_machineset.yml 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. 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. - name: wait for machine to be created
  33. k8s_facts:
  34. api_version: machine.openshift.io/v1beta1
  35. kubeconfig: "{{ kubeconfig_path }}"
  36. namespace: openshift-machine-api
  37. kind: Machine
  38. label_selectors:
  39. - "machine.openshift.io/cluster-api-machineset={{ machineset_name }}"
  40. register: new_machine
  41. retries: 36
  42. delay: 5
  43. until:
  44. - new_machine.resources is defined
  45. - new_machine.resources | length > 0
  46. - new_machine.resources[0].status is defined
  47. - new_machine.resources[0].status.providerStatus is defined
  48. - new_machine.resources[0].status.providerStatus.instanceState is defined
  49. - new_machine.resources[0].status.providerStatus.instanceState == 'running'
  50. - name: add machine to the inventory
  51. add_host:
  52. name: "{{ new_machine.resources[0].status.addresses | selectattr('type', 'match', '^InternalIP$') | map(attribute='address') | first }}"
  53. node_name: "{{ new_machine.resources[0].status.addresses | selectattr('type', 'match', '^InternalDNS$') | map(attribute='address') | first }}"
  54. groups: new_workers
  55. 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 }}\""