openstack-ansible-os_neutron/tasks/neutron_db_setup.yml
Jesse Pretorius f027faf6b5 Simplify database migrations
Instead of using a module to check for migrations,
we now execute the expand every time the venv is
updated. We also implement a simple check for
offline migrations and do the proper server shut
down and execution as per [1].

The integrated playbook will target all
neutron-server hosts at once when executing the
role to make sure that the db contract is done
with them all offline.

[1] https://docs.openstack.org/developer/neutron/devref/upgrade.html

Change-Id: I7dfef45e1ed8a8dfa464f1b3d20c90ae3348ce2e
2017-06-20 15:19:33 +00:00

78 lines
2.5 KiB
YAML

---
# Copyright 2014, Rackspace US, 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: Perform a DB expand
command: "{{ neutron_bin }}/neutron-db-manage upgrade --expand"
become: yes
become_user: "{{ neutron_system_user_name }}"
when:
- "ansible_local['openstack_ansible']['neutron']['need_db_expand'] | bool"
run_once: yes
- name: Check for available offline migrations
command: "{{ neutron_bin }}/neutron-db-manage has_offline_migrations"
register: _offline_migrations_check
changed_when: false
failed_when:
- "_offline_migrations_check.rc == 1"
- "'Need to apply migrations from neutron contract branch' not in _offline_migrations_check.stdout"
run_once: yes
- name: Set the fact for the required offline migrations
ini_file:
dest: "/etc/ansible/facts.d/openstack_ansible.fact"
section: neutron
option: "need_db_contract"
value: "{{ ('Need to apply migrations from neutron contract branch' in _offline_migrations_check.stdout) | bool }}"
- name: Refresh local facts
setup:
filter: ansible_local
gather_subset: "!all"
- name: Stop Neutron server
service:
name: "neutron-server"
state: stopped
when:
- "ansible_local['openstack_ansible']['neutron']['need_db_contract'] | bool"
- name: Perform a DB contract
command: "{{ neutron_bin }}/neutron-db-manage upgrade --contract"
become: yes
become_user: "{{ neutron_system_user_name }}"
when:
- "ansible_local['openstack_ansible']['neutron']['need_db_contract'] | bool"
run_once: yes
- name: Start Neutron server
service:
name: "neutron-server"
state: started
when:
- "ansible_local['openstack_ansible']['neutron']['need_db_contract'] | bool"
- name: Disable the db sync local facts
ini_file:
dest: "/etc/ansible/facts.d/openstack_ansible.fact"
section: neutron
option: "{{ item.name }}"
value: "{{ item.state }}"
with_items:
- name: "need_db_expand"
state: "False"
- name: "need_db_contract"
state: "False"