openstack-ansible-os_neutron/tasks/providers/ovn_cluster_setup.yml

87 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: "{{ item }}"
state: stopped
with_items:
- ovn-northd
- ovn-central
- 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-central.j2
dest: "/etc/default/ovn-central"
when:
- "inventory_hostname == neutron_ovn_primary_cluster_node"
- _check_cluster_db.rc != 0
- not leader_node
notify:
- start ovn-central service
- restart ovn-central 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-central.j2
dest: "/etc/default/ovn-central"
when:
- _check_cluster_db.rc != 0
notify:
- start ovn-central service
- restart ovn-central service