|
| 1 | +--- |
| 2 | +# Create and deploy a cluster with the Assisted Installer |
| 3 | +# |
| 4 | +# Example Usage: |
| 5 | +# |
| 6 | +# ansible-playbook -i ansible/inventory/cloud42.local ansible/mno-deploy.yml |
| 7 | +# |
| 8 | + |
| 9 | +- name: Prep cluster to add hosts |
| 10 | + hosts: bastion |
| 11 | + vars_files: |
| 12 | + - vars/lab.yml |
| 13 | + - vars/all.yml |
| 14 | + gather_facts: false |
| 15 | + tasks: |
| 16 | + - name: Set assisted installer connection |
| 17 | + set_fact: |
| 18 | + assisted_installer_host: "{{ groups['bastion'][0] }}" |
| 19 | + assisted_installer_port: "8090" |
| 20 | + |
| 21 | + - name: Get cluster status |
| 22 | + uri: |
| 23 | + url: "http://{{ assisted_installer_host }}:{{ assisted_installer_port }}/api/assisted-install/v2/clusters/{{ ai_cluster_id }}" |
| 24 | + method: GET |
| 25 | + body_format: json |
| 26 | + status_code: [200] |
| 27 | + return_content: true |
| 28 | + register: cluster_data |
| 29 | + failed_when: cluster_data.json.status not in ['installed', 'adding-hosts'] |
| 30 | + |
| 31 | + - name: Set cluster status to adding-hosts |
| 32 | + uri: |
| 33 | + url: "http://{{ assisted_installer_host }}:{{ assisted_installer_port }}/api/assisted-install/v2/clusters/{{ ai_cluster_id }}/actions/allow-add-workers" |
| 34 | + method: POST |
| 35 | + body_format: json |
| 36 | + status_code: [201, 202] |
| 37 | + when: cluster_data.json.status == 'installed' |
| 38 | + |
| 39 | + - name: Get infra-env |
| 40 | + uri: |
| 41 | + url: "http://{{ assisted_installer_host }}:{{ assisted_installer_port }}/api/assisted-install/v2/clusters/{{ ai_cluster_id }}" |
| 42 | + method: GET |
| 43 | + body_format: json |
| 44 | + status_code: [200] |
| 45 | + return_content: true |
| 46 | + register: infra_env_return |
| 47 | + |
| 48 | + - name: Set ai_infraenv_id |
| 49 | + set_fact: |
| 50 | + ai_infraenv_id: "{{ infra_env_return.json.hosts[0].infra_env_id }}" |
| 51 | + |
| 52 | + - name: Get infra-env static_network_config |
| 53 | + uri: |
| 54 | + url: "http://{{ assisted_installer_host }}:{{ assisted_installer_port }}/api/assisted-install/v2/infra-envs/{{ ai_infraenv_id }}" |
| 55 | + method: GET |
| 56 | + body_format: json |
| 57 | + status_code: [200] |
| 58 | + return_content: true |
| 59 | + register: infra_env_return |
| 60 | + |
| 61 | + - name: Set ai_infraenv_static_config |
| 62 | + set_fact: |
| 63 | + ai_infraenv_static_config: "{{ infra_env_return.json.static_network_config }}" |
| 64 | + |
| 65 | + - name: Set empty static network configuration |
| 66 | + set_fact: |
| 67 | + static_network_config: [] |
| 68 | + |
| 69 | + - name: Generate Static Network Config for VMs |
| 70 | + ansible.builtin.include_role: |
| 71 | + name: create-ai-cluster |
| 72 | + tasks_from: static_network_config |
| 73 | + vars: |
| 74 | + hybrid_worker_count: "{{ add_worker_count }}" |
| 75 | + loop: "{{ groups['hv_vm'][:hybrid_worker_count | int] }}" |
| 76 | + |
| 77 | + - name: show ai_infraenv_static_config |
| 78 | + debug: |
| 79 | + var: ai_infraenv_static_config |
| 80 | + |
| 81 | + - name: show static_network_config |
| 82 | + debug: |
| 83 | + var: static_network_config |
| 84 | + |
| 85 | + - name: Set static network composite |
| 86 | + set_fact: |
| 87 | + static_network_config_comp: "{{ static_network_config + ai_infraenv_static_config }}" |
| 88 | + |
| 89 | + - name: show static_network_config composite |
| 90 | + debug: |
| 91 | + var: static_network_config_comp |
| 92 | + |
| 93 | + - name: Update static config |
| 94 | + uri: |
| 95 | + url: "http://{{ assisted_installer_host }}:{{ assisted_installer_port }}/api/assisted-install/v2/infra-envs/{{ ai_infraenv_id }}" |
| 96 | + body: { |
| 97 | + "static_network_config": "{{ static_network_config + ai_infraenv_static_config }}" |
| 98 | + } |
| 99 | + method: PATCH |
| 100 | + body_format: json |
| 101 | + status_code: [201] |
| 102 | + return_content: true |
| 103 | + |
| 104 | + |
| 105 | +- name: Boot / Install VMs |
| 106 | + hosts: bastion |
| 107 | + vars_files: |
| 108 | + - vars/lab.yml |
| 109 | + - vars/all.yml |
| 110 | + roles: |
| 111 | + - generate-discovery-iso |
| 112 | + - role: boot-iso |
| 113 | + vars: |
| 114 | + inventory_group: hv_vm |
| 115 | + index: "{{ add_worker_count }}" |
| 116 | + virtual_media_iso: "discovery.iso" |
| 117 | + - role: wait-hosts-discovered |
| 118 | + vars: |
| 119 | + inventory_nodes: "{{ groups['hv_vm'][:add_worker_count|int] }}" |
| 120 | + discover_nodes: "{{ groups['hv_vm'][:add_worker_count|int] }}" |
| 121 | + - add-hosts-install |
0 commit comments