Skip to content

Commit 0cf00af

Browse files
authored
ansible role for deploy capi mgmt cluster for magnum capi driver (rackerlabs#1465)
* add ansible automation for deploying capi mgmt cluster on genestack cloud * update lb pool deletion task to a handler and use command module instead of shell module * update the playbook to load the variables from a vars file instead of defining them from the main playbook * move the vars from ubuntu.yml to main.yml
1 parent cf358f0 commit 0cf00af

23 files changed

+1215
-0
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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

ansible/playbooks/vars/main.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
os_endpoint_type: public
3+
os_interface: "{{ os_endpoint_type }}"
4+
os_username: admin
5+
os_project_name: admin
6+
os_tenant_name: '{{ os_project_name }}'
7+
os_auth_type: password
8+
os_admin_password: ''
9+
os_auth_url: http://keystone.pikachu.jabronis.dev/v3
10+
os_user_domain_name: default
11+
os_project_domain_name: default
12+
os_region_name: RegionOne
13+
os_identity_api_version: 3
14+
os_auth_version: 3
15+
nova_endpoint_type: "{{ os_endpoint_type }}"
16+
capi_mgmt_project_name: capi-mgmt-cluster-project
17+
capi_mgmt_user_name: capi-mgmt-user
18+
capi_mgmt_project_domain: service
19+
capi_mgmt_user_domain: service
20+
os_user_password: ''
21+
22+
os_admin_env:
23+
OS_ENDPOINT_TYPE: "{{ os_endpoint_type }}"
24+
OS_INTERFACE: "{{ os_interface }}"
25+
OS_USERNAME: "{{ os_username }}"
26+
OS_PASSWORD: "{{ os_admin_password }}"
27+
OS_PROJECT_NAME: "{{ os_project_name }}"
28+
OS_TENANT_NAME: 'admin'
29+
OS_AUTH_TYPE: password
30+
OS_AUTH_URL: "{{ os_auth_url }}"
31+
OS_USER_DOMAIN_NAME: "{{ os_user_domain_name }}"
32+
OS_PROJECT_DOMAIN_NAME: "{{ os_project_domain_name }}"
33+
OS_REGION_NAME: "{{ os_region_name }}"
34+
OS_IDENTITY_API_VERSION: "{{ os_identity_api_version }}"
35+
OS_AUTH_VERSION: "{{ os_auth_version }}"
36+
NOVA_ENDPOINT_TYPE: "{{ nova_endpoint_type }}"
37+
38+
capi_mgmt_env:
39+
OS_ENDPOINT_TYPE: "{{ os_endpoint_type | default('public') }}"
40+
OS_INTERFACE: "{{ os_interface | default('public') }}"
41+
OS_AUTH_URL: http://keystone.pikachu.jabronis.dev/v3
42+
OS_USERNAME: "{{ capi_mgmt_user_name }}"
43+
OS_PASSWORD: "{{ os_user_password }}"
44+
OS_PROJECT_NAME: "{{ capi_mgmt_project_name }}"
45+
OS_USER_DOMAIN_NAME: service
46+
OS_PROJECT_DOMAIN_NAME: service
47+
OS_AUTH_TYPE: password
48+
OS_REGION_NAME: "{{ os_region_name | default('RegionOne') }}"
49+
OS_IDENTITY_API_VERSION: "{{ os_identity_api_version }}"
50+
OS_AUTH_VERSION: "{{ os_auth_version }}"
51+
NOVA_ENDPOINT_TYPE: "{{ nova_endpoint_type }}"
52+
KUBECONFIG: "{{ ansible_env.HOME }}/.kube/config"

ansible/playbooks/vars/ubuntu.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# provide variables specific to ubuntu distro
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
CAPI CLUSTER
2+
=========
3+
4+
This is the ansible role for creating the infra for installing capi mgmt cluster on a genestack cloud
5+
6+
Requirements
7+
------------
8+
9+
These are the infra level requirements for the role to create the required infra for the capi mgmt cluster:
10+
* cinder-volume service enabled: Currently the role only supports bfv instances; so cinder-volume should be enabled
11+
* external network: A pre-created shared external neutron network (either flat or vlan) to be used for the role
12+
* keystone admin credentials: when running the role; keystone admin user credentials would be required
13+
* octavia service enabled: role creates loadbalancer for the capi mgmt cluster; so octavia should be enabled
14+
15+
These are the network level requirements for the role to create the capi mgmt cluster:
16+
* dns server: Atleast one dns server to be defined:
17+
- dns server should be reachable from the external neutron network used with the role
18+
- dns server should be able resolve external endpoints for the openstack services on genestack cloud
19+
* external network reachability:
20+
- the external network should be reachable from the ansible control node from where the playbook is run
21+
- the external network should be able reach the public endpoints for openstack services
22+
23+
There are a few other requirements for this role as well:
24+
* openstack sdk installed: On the ansible control node openstack-sdk should be installed (generally genestack venv is sufficient)
25+
* sufficient storage space on glance: the role will upload a ubuntu-24 image; should the backend for glance should have sufficient space
26+
* currently there is no provision to include custom tls certs; so if the openstack endpoints are behind a tls gateway then the certs should be
27+
signed by a well-known CA like verisign etc; self signed certs will cause failures with magnum after the mgmt cluster is deployed
28+
29+
Role Variables
30+
--------------
31+
32+
These are the role variables:
33+
* required role variables:
34+
- ext_net_id: external neutron network ID (should already exist)
35+
- os_admin_password: keystone admin password
36+
- os_user_password: password for the new user to be created for capi-mgmt-cluster-project
37+
- capi_mgmt_dns_servers: dns server to be used for the capi mgmt cluster
38+
- capi_boot_from_volume: should be set to true (default)
39+
40+
* other important role variables:
41+
- capi_mgmt_cluster_flavor: flavor the capi mgmt cluster vms (flavor name and specs)
42+
- capi_mgmt_cluster_volume_type: volume type for the capi mgmt cluster (defaults to lvmdriver-1)
43+
- capi_mgmt_cluster_volumes: can be used to define the size of the volumes for capi mgmt cluster vms
44+
- capi_mgmt_etcd_backup_volume: can be used to define the size of the etcd backup volume and volume type
45+
46+
Refer to defaults/main.yml with the role directory for more details on the variables
47+
48+
Dependencies
49+
------------
50+
51+
There are no external dependencies for the role; basic genestack venv should be sufficient
52+
53+
Example Playbook
54+
----------------
55+
56+
The playbook which includes the role for capi mgmt cluster infra should be used as below:
57+
58+
```
59+
ansible-playbook capi-mgmt-main.yaml -e os_admin_password=<keystone_admin_passwd> -e os_user_password=rack1234 -e ext_net_id='7f84bb82-996e-4520-a2f0-50a9602de363'
60+
```
61+
62+
Author Information
63+
------------------
64+
65+
Name: Punit Shankar Kundal\
66+
Email: punitshankar.kundal@rackspace.com

0 commit comments

Comments
 (0)