Execution
Date 08 Dec 2025 13:39:52 +0000
Duration 00:35:02.03
Controller aio1.openstack.local
User root
Versions
Ansible 2.18.6
ara 1.7.4 / 1.7.4
Python 3.12.3
Summary
2 Hosts
1377 Tasks
1365 Results
104 Plays
504 Files
0 Records

File: /home/zuul/src/opendev.org/openstack/openstack-ansible-os_neutron/tasks/providers/ovn_cluster_setup.yml

---
# (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
  ansible.builtin.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
      ansible.builtin.service:
        name: "{{ neutron_ovn_northd_service_name }}"
        state: stopped

    - name: Clean up ovn db directory
      ansible.builtin.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
  ansible.builtin.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
  ansible.builtin.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.
  ansible.builtin.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
  ansible.builtin.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
  ansible.builtin.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
  ansible.builtin.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