openstack-ansible-os_neutron/tasks/providers/ovn_cluster_setup.yml
Satish Patel 97d409a911 Add support of OVN for CentOS-8-Stream
This patch will adjust some variable for C8-Stream job to fix
OVN deployment for CentOS-8-Stream. Renamed ovn-central with
ovn-northd for more generic name.

Change-Id: Ifdb773f9f539469e21d37075f6b88259eb1ffa3e
2021-08-12 03:44:45 +00:00

84 lines
2.6 KiB
YAML

---
# (c) 2021, Satish Patel <satish.txt@gmail.com>
#
# Copyright
#
# 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.
# checking if ovn db are clustered or not, if not then this is fresh node.
- name: Check if ovn db is clustered
command: ovsdb-tool db-is-clustered /var/lib/ovn/ovnnb_db.db
ignore_errors: true
failed_when: false
register: _check_cluster_db
tags:
- skip_ansible_lint
# We need to clean existing ovn db/lock file before cluster join.
- name: Clean up db/lock files before creating ovn cluster
when:
- _check_cluster_db.rc != 0
block:
- name: Stop ovn services
service:
name: "{{ neutron_ovn_northd_service_name }}"
state: stopped
- name: Clean up ovn db directory
file:
path: /var/lib/ovn/
state: absent
# We are finding leader node so new nodes use leader to join cluster.
- name: Find leader node in ovn cluster
shell: ovs-appctl -t /var/run/ovn/ovnnb_db.ctl cluster/status OVN_Northbound | sed 's/ //g' | grep -oP '(?<=Role:).*'
args:
executable: /bin/bash
ignore_errors: true
delegate_to: "{{ item }}"
with_items: "{{ groups['neutron_ovn_northd'] }}"
run_once: true
failed_when: false
register: _find_leader
tags:
- skip_ansible_lint
# set leader_node variable
- name: Set leader_node fact
set_fact:
leader_node: "{{ (_find_leader.results | selectattr('stdout', 'search', 'leader')) | map(attribute='item') | list }}"
# This play only run first time to build cluster using primary node.
- name: Setup ovn cluster using primary node.
template:
src: ovn-northd-opts.j2
dest: "{{ neutron_ovn_northd_opts_file }}"
when:
- "inventory_hostname == neutron_ovn_primary_cluster_node"
- _check_cluster_db.rc != 0
- not leader_node
notify:
- start ovn service
- restart ovn service
# This play will add nodes in existing cluster using leader_node var.
- name: Join new nodes to ovn cluster using leader node
template:
src: ovn-northd-opts.j2
dest: "{{ neutron_ovn_northd_opts_file }}"
when:
- _check_cluster_db.rc != 0
notify:
- start ovn service
- restart ovn service