Add ability to create COE template

Creation of cluster templates is pretty routine operation wich
might be easily automated with ansible.

Depends-On: https://review.opendev.org/710245
Change-Id: Ib7f99714502ba94604b8f0bb997c77a768af6d1d
This commit is contained in:
Dmitriy Rabotyagov 2020-02-17 13:15:32 +02:00
parent 2c46e51869
commit 51fe8d4897
5 changed files with 144 additions and 46 deletions

View File

@ -127,15 +127,38 @@ magnum_trustee_domain_admin_roles: ['admin']
magnum_cluster_user_trust: True
#Glance images
magnum_glance_images: []
## Example Glance Image - Fedora Atomic
# - name: fedora-atomic-latest #Name of the image in Glance
# disk_format: qcow2 #Disk format (e.g. qcow2)
# image_format: bare #Image format
# public: true #Boolean - is the image public
# file: https://dl.fedoraproject.org/pub/alt/atomic/stable/Fedora-29-updates-20190820.0/AtomicHost/x86_64/images/Fedora-AtomicHost-29-20190820.0.x86_64.qcow2
# file: https://builds.coreos.fedoraproject.org/prod/streams/stable/builds/31.20200210.3.0/x86_64/fedora-coreos-31.20200210.3.0-openstack.x86_64.qcow2.xz
# distro: fedora-atomic #Value for the os_distro metadata
# checksum: "sha1:7c1a88749d31a3828ac6a6b02e82d64f4c5823a5"
# checksum: "sha256:9a5252e24b82a5edb1ce75b05653f59895685b0f1028112462e908a12deae518"
magnum_glance_images: []
# Define cluster templates to create. It should be list of
# dictionaries with keys that are supported by os_coe_cluster_template
# module (https://docs.ansible.com/ansible/latest/modules/os_coe_cluster_template_module.html)
#magnum_cluster_templates:
# - name: k8s
# cloud: default
# coe: kubernetes
# docker_volume_size: 50
# external_network_id: public
# network_driver: flannel
magnum_cluster_templates: []
# Create extra flavors to be used by magnum cluster template. It should be list
# of dictionaries with keys that are supported by os_nova_flavor module
# (https://docs.ansible.com/ansible/latest/modules/os_nova_flavor_module.html)
#magnum_flavors:
# - name: k8s-pod
# cloud: default
# ram: 256
# vcpus: 1
# disk: 5
magnum_flavors: []
# Set the directory where the downloaded images will be stored
# on the magnum_service_setup_host host. If the host is localhost,

View File

@ -0,0 +1,8 @@
---
features:
- |
Added variables `magnum_cluster_templates` and `magnum_flavors`
which allow deployers to define coe cluster template and nova flavors
creation during role execution. These variables may contain list of
resources to add. All keys supported by appropriate ansible modules
may be passed as items in the list.

View File

@ -38,46 +38,3 @@
notify:
- Restart magnum services
- Restart uwsgi services
- name: Add magnum image
delegate_to: "{{ magnum_service_setup_host }}"
run_once: true
vars:
ansible_python_interpreter: "{{ magnum_service_setup_host_python_interpreter }}"
block:
- name: Create image download directory
file:
path: "{{ magnum_image_path }}"
state: directory
mode: "0750"
owner: "{{ magnum_image_path_owner }}"
- name: Download images
get_url:
url: "{{ item.file }}"
dest: "{{ magnum_image_path }}/{{ item.file | basename }}"
checksum: "{{ item.checksum | default(omit) }}"
register: download_image
until: download_image is success
retries: 5
delay: 10
with_items: "{{ magnum_glance_images }}"
- name: Upload images to Glance
os_image:
cloud: default
state: present
endpoint_type: admin
verify: "{{ not keystone_service_adminuri_insecure }}"
name: "{{ item.name }}"
disk_format: "{{ item.disk_format }}"
container_format: "{{ item.image_format }}"
is_public: "{{ item.public }}"
filename: "{{ magnum_image_path }}/{{ item.file | basename }}"
properties:
os_distro: "{{ item.distro }}"
register: upload_image
until: upload_image is success
retries: 5
delay: 10
with_items: "{{ magnum_glance_images }}"

105
tasks/magnum_resources.yml Normal file
View File

@ -0,0 +1,105 @@
---
# Copyright 2020, VEXXHOST, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Create magnum resources
delegate_to: "{{ magnum_service_setup_host }}"
vars:
ansible_python_interpreter: "{{ magnum_service_setup_host_python_interpreter }}"
block:
- name: Create image download directory
file:
path: "{{ magnum_image_path }}"
state: directory
mode: "0750"
owner: "{{ magnum_image_path_owner }}"
when: magnum_glance_images
- name: Download images
get_url:
url: "{{ item.file }}"
dest: "{{ magnum_image_path }}/{{ item.file | basename }}"
checksum: "{{ item.checksum | default(omit) }}"
register: download_image
until: download_image is success
retries: 5
delay: 10
with_items: "{{ magnum_glance_images }}"
- name: Upload images to Glance
os_image:
cloud: "{{ item.cloud | default('default') }}"
state: "{{ item.state | default('present') }}"
interface: "{{ item.interface | default('admin') }}"
validate_certs: "{{ not keystone_service_adminuri_insecure }}"
name: "{{ item.name }}"
disk_format: "{{ item.disk_format }}"
container_format: "{{ item.image_format }}"
is_public: "{{ item.public }}"
filename: "{{ magnum_image_path }}/{{ item.file | basename }}"
properties:
os_distro: "{{ item.distro }}"
register: upload_image
until: upload_image is success
retries: 5
delay: 10
with_items: "{{ magnum_glance_images }}"
- name: Create flavors for Magnum
os_nova_flavor:
cloud: "{{ item.cloud | default('default') }}"
state: "{{ item.state | default('present') }}"
is_public: "{{ item.is_public | default(omit) }}"
interface: "{{ item.interface | default('admin') }}"
validate_certs: "{{ not keystone_service_adminuri_insecure }}"
region_name: "{{ item.region_name | default(magnum_service_region) }}"
name: "{{ item.name }}"
ram: "{{ item.ram }}"
vcpus: "{{ item.vcpus }}"
disk: "{{ item.disk | default(0) }}"
swap: "{{ item.swap | default(0) }}"
ephemeral: "{{ item.ephemeral | default(omit) }}"
extra_specs: "{{ item.extra_specs | default(omit) }}"
flavorid: "{{ item.flavorid | default(omit) }}"
rxtx_factor: "{{ item.rxtx_factor | default(omit) }}"
with_items: "{{ magnum_flavors }}"
- name: Create Magnum cluster templates
os_coe_cluster_template:
cloud: "{{ item.cloud | default('default') }}"
state: "{{ item.state | default('present') }}"
interface: "{{ item.interface | default('admin') }}"
validate_certs: "{{ not keystone_service_adminuri_insecure }}"
region_name: "{{ item.region_name | default(magnum_service_region) }}"
coe: "{{ item.coe }}"
dns_nameserver: "{{ item.dns_nameserver | default(omit) }}"
docker_storage_driver: "{{ item.docker_storage_driver | default(omit) }}"
docker_volume_size: "{{ item.docker_volume_size | default(omit) }}"
external_network_id: "{{ item.external_network_id | default(omit) }}"
fixed_network: "{{ item.fixed_network | default(omit) }}"
fixed_subnet: "{{ item.fixed_subnet | default(omit) }}"
flavor_id: "{{ item.flavor_id }}"
floating_ip_enabled: "{{ item.floating_ip_enabled | default(omit) }}"
image_id: "{{ item.image_id }}"
keypair_id: "{{ item.keypair_id | default(omit) }}"
labels: "{{ item.labels | default(omit) }}"
master_flavor_id: "{{ item.master_flavor_id }}"
master_lb_enabled: "{{ item.master_lb_enabled | default(omit) }}"
name: "{{ item.name }}"
network_driver: "{{ item.network_driver }}"
public: "{{ item.public | default(omit) }}"
registry_enabled: "{{ item.registry_enabled | default(omit) }}"
server_type: "{{ item.server_type | default(omit) }}"
volume_driver: "{{ item.volume_driver | default(omit) }}"
with_items: "{{ magnum_cluster_templates }}"

View File

@ -123,3 +123,8 @@
- name: Flush handlers
meta: flush_handlers
- import_tasks: magnum_resources.yml
when: inventory_hostname == groups['magnum_all'][0]
tags:
- magnum-config