e45107b4fd
Current command/shell modules for ovn cluster setup while fetching current deployment state do not actually have changed_when: false which causes these tasks to end up in "Changed" state Change-Id: Id4b947d0b7aaa54eb3bbe58d2593ad6b49009b5c
114 lines
3.5 KiB
YAML
114 lines
3.5 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
|
|
changed_when: false
|
|
register: _check_cluster_db
|
|
|
|
# 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: "{{ container }}"
|
|
with_items: "{{ groups['neutron_ovn_northd'] }}"
|
|
loop_control:
|
|
loop_var: container
|
|
run_once: true
|
|
failed_when: false
|
|
changed_when: false
|
|
register: _find_leader
|
|
|
|
# set leader_node variable
|
|
- name: Set leader_node fact
|
|
set_fact:
|
|
leader_node: "{{ (_find_leader.results | selectattr('stdout', 'search', 'leader')) | map(attribute='container') | 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 }}"
|
|
mode: "0644"
|
|
when:
|
|
- "inventory_hostname == neutron_ovn_primary_cluster_node"
|
|
- _check_cluster_db.rc != 0
|
|
- not leader_node
|
|
register: ovn_northd_opts
|
|
|
|
- name: Start ovn service
|
|
service:
|
|
name: "{{ neutron_ovn_northd_service_name }}"
|
|
state: started
|
|
when:
|
|
- "inventory_hostname == neutron_ovn_primary_cluster_node"
|
|
- _check_cluster_db.rc != 0
|
|
- not leader_node
|
|
- ovn_northd_opts.changed
|
|
|
|
- name: Configure connection settings for ovn-nb and ovn-sb
|
|
command: "{{ cmd }}"
|
|
changed_when: false
|
|
with_items:
|
|
- "ovn-nbctl --inactivity-probe={{ neutron_ovn_nb_inactivity_probe }} set-connection p{{ ovn_proto }}:6641"
|
|
- "ovn-sbctl --inactivity-probe={{ neutron_ovn_sb_inactivity_probe }} set-connection p{{ ovn_proto }}:6642"
|
|
when:
|
|
- "inventory_hostname == neutron_ovn_primary_cluster_node"
|
|
- _check_cluster_db.rc != 0
|
|
- not leader_node
|
|
- ovn_northd_opts.changed
|
|
loop_control:
|
|
loop_var: cmd
|
|
register: _ovn_connection_settings
|
|
until: _ovn_connection_settings is success
|
|
retries: 5
|
|
delay: 2
|
|
tags:
|
|
- neutron_ovn-config
|
|
|
|
# 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 }}"
|
|
mode: "0644"
|
|
when:
|
|
- _check_cluster_db.rc != 0
|
|
notify:
|
|
- start ovn service
|
|
- restart ovn service
|