|
| 1 | +- name: Play to bootstrap project and user for capi mgmt cluster |
| 2 | + hosts: localhost |
| 3 | + gather_facts: true |
| 4 | + vars_files: |
| 5 | + - vars/main.yml |
| 6 | + - vars/{{ ansible_distribution | lower }}.yml |
| 7 | + environment: "{{ os_admin_env | default({}) }}" |
| 8 | + pre_tasks: |
| 9 | + - name: check that the admin password is provided |
| 10 | + ansible.builtin.assert: |
| 11 | + that: |
| 12 | + - os_admin_password is defined |
| 13 | + - os_admin_password | length > 0 |
| 14 | + fail_msg: > |
| 15 | + password for the admin user is required |
| 16 | + provide the admin password with -e os_admin_password=<passwd> |
| 17 | + - name: check that the password capi_mgmt_user is provided |
| 18 | + ansible.builtin.assert: |
| 19 | + that: |
| 20 | + - os_user_password is defined |
| 21 | + - os_user_password | length > 0 |
| 22 | + fail_msg: > |
| 23 | + password for the capi mgmt user is required |
| 24 | + provide the password for capi mgmt user with -e os_user_password=<passwd> |
| 25 | + this will be password for creating the capi mgmt user |
| 26 | + tasks: |
| 27 | + - name: Create the project for capi mgmt cluster |
| 28 | + openstack.cloud.project: |
| 29 | + name: "{{ capi_mgmt_project_name }}" |
| 30 | + domain: "{{ capi_mgmt_project_domain }}" |
| 31 | + description: "capi mgmt cluster project" |
| 32 | + is_enabled: True |
| 33 | + state: present |
| 34 | + |
| 35 | + - name: Create the user for the capi mgmt cluster |
| 36 | + openstack.cloud.identity_user: |
| 37 | + name: "{{ capi_mgmt_user_name }}" |
| 38 | + domain: "{{ capi_mgmt_user_domain }}" |
| 39 | + description: "capi mgmt cluster user" |
| 40 | + state: present |
| 41 | + password: "{{ os_user_password }}" |
| 42 | + default_project: "{{ capi_mgmt_project_name }}" |
| 43 | + |
| 44 | + - name: Assign the admin role to the capi mgmt user |
| 45 | + openstack.cloud.role_assignment: |
| 46 | + user: "{{ capi_mgmt_user_name }}" |
| 47 | + role: admin |
| 48 | + project: "{{ capi_mgmt_project_name }}" |
| 49 | + domain: service |
| 50 | + |
| 51 | + - name: Modify the quotas for the capi mgmt cluster project |
| 52 | + openstack.cloud.quota: |
| 53 | + name: "{{ capi_mgmt_project_name }}" |
| 54 | + cores: 30 |
| 55 | + volumes: 20 |
| 56 | + snapshots: 20 |
| 57 | + instances: 20 |
| 58 | + |
| 59 | + - name: Persist the capi mgmt user creds |
| 60 | + ansible.builtin.set_fact: |
| 61 | + capi_mgmt_os_env: "{{ capi_mgmt_env }}" |
| 62 | + |
| 63 | +- name: Playbook to create capi mgmt cluster infra |
| 64 | + hosts: localhost |
| 65 | + gather_facts: true |
| 66 | + environment: "{{ capi_mgmt_os_env | default({}) }}" |
| 67 | + roles: |
| 68 | + - capi_cluster |
| 69 | + |
| 70 | +- name: Playbook to deploy kubernetes cluster on capi mgmt cluster vms |
| 71 | + hosts: capi_mgmt_bootstrp_vm |
| 72 | + gather_facts: true |
| 73 | + become: true |
| 74 | + tasks: |
| 75 | + - name: ping the capi mgmt cluster bootstrp vm fip |
| 76 | + ansible.builtin.ping: |
| 77 | + |
| 78 | + - name: copy the ssh key to the bootstrp vm |
| 79 | + ansible.builtin.copy: |
| 80 | + src: "{{ ansible_env.HOME }}/capi_mgmt_private_key" |
| 81 | + dest: /home/ubuntu/capi_mgmt_cluster_keypair |
| 82 | + mode: 0400 |
| 83 | + |
| 84 | + - name: copy the capi mgmt cluster inventory to the bootstrp vm |
| 85 | + ansible.builtin.copy: |
| 86 | + src: /var/tmp/capi-mgmt-inventory.ini |
| 87 | + dest: /home/ubuntu/capi-mgmt-inventory.ini |
| 88 | + |
| 89 | + - name: copy the capi mgmt cluster vars to the bootstrp vm |
| 90 | + ansible.builtin.copy: |
| 91 | + src: /var/tmp/capi-cluster-vars.yml |
| 92 | + dest: /home/ubuntu/capi-cluster-vars.yml |
| 93 | + |
| 94 | + - name: check if dns overrides exists on the localhost |
| 95 | + ansible.builtin.stat: |
| 96 | + path: /var/tmp/capi-cluster-dns-vars.yml |
| 97 | + delegate_to: localhost |
| 98 | + register: _capi_dns_vars_file |
| 99 | + |
| 100 | + - name: copy the dns vars to the bootstrp vm |
| 101 | + ansible.builtin.copy: |
| 102 | + src: /var/tmp/capi-cluster-dns-vars.yml |
| 103 | + dest: /home/ubuntu/capi-cluster-dns-vars.yml |
| 104 | + when: _capi_dns_vars_file.stat.exists |
| 105 | + |
| 106 | + - name: copy the shell script to the install the cluster on the bootstrp vm |
| 107 | + ansible.builtin.copy: |
| 108 | + src: /var/tmp/capi-cluster-install.sh |
| 109 | + dest: /home/ubuntu/capi-cluster-install.sh |
| 110 | + mode: u+x |
| 111 | + |
| 112 | + - name: copy the etcd backup script to the bootstrp vm |
| 113 | + ansible.builtin.copy: |
| 114 | + src: /var/tmp/etcd-backup.sh |
| 115 | + dest: /usr/local/bin/etcd-backup.sh |
| 116 | + mode: u+x |
| 117 | + |
| 118 | + - name: Notify the user about the script logs |
| 119 | + ansible.builtin.debug: |
| 120 | + msg: > |
| 121 | + "installing capi-mgmt-cluster; check /var/log/capi-mgmt-cluster-install.log on |
| 122 | + {{ inventory_hostname }} for further details" |
| 123 | +
|
| 124 | + - name: run the script to install the capi-mgmt-cluster |
| 125 | + ansible.builtin.command: |
| 126 | + cmd: /home/ubuntu/capi-cluster-install.sh |
| 127 | + async: 1800 |
| 128 | + poll: 0 |
| 129 | + register: _capi_cluster_install_script |
| 130 | + |
| 131 | + - name: check the status of the script until script is running |
| 132 | + ansible.builtin.async_status: |
| 133 | + jid: "{{ _capi_cluster_install_script.ansible_job_id }}" |
| 134 | + register: _capi_cluster_install_script_result |
| 135 | + until: _capi_cluster_install_script_result is finished |
| 136 | + retries: 180 |
| 137 | + delay: 10 |
| 138 | + |
| 139 | + - name: print message if the script runs without any issue |
| 140 | + ansible.builtin.debug: |
| 141 | + msg: > |
| 142 | + capi cluster install script went without any issues; the management |
| 143 | + cluster has been installed |
| 144 | + when: |
| 145 | + - _capi_cluster_install_script_result.rc is defined |
| 146 | + - _capi_cluster_install_script_result.rc == 0 |
| 147 | + |
| 148 | + - name: copy the kubeconfig from the capi mgmt cluster |
| 149 | + ansible.builtin.fetch: |
| 150 | + src: /etc/kubernetes/admin.conf |
| 151 | + dest: /var/tmp/capi_mgmt_cluster.kubeconfig |
| 152 | + flat: yes |
| 153 | + when: |
| 154 | + - _capi_cluster_install_script_result.rc is defined |
| 155 | + - _capi_cluster_install_script_result.rc == 0 |
0 commit comments