openstack-ansible-os_nova/tasks/nova_db_post_setup.yml

106 lines
4.5 KiB
YAML

---
# Copyright 2017, 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: Set the delegated task facts
set_fact:
_db_nova_bin: "{{ hostvars[nova_conductor_setup_host]['nova_bin'] | default(nova_bin) }}"
_db_nova_system_user_name: "{{ hostvars[nova_conductor_setup_host]['nova_system_user_name'] | default(nova_system_user_name) }}"
# This needs to be done after Compute hosts are added.
- name: Perform a cell_v2 discover
command: >-
{{ _db_nova_bin }}/nova-manage cell_v2 discover_hosts{{ (debug | bool) | ternary(' --verbose', '') }}{{
(nova_ironic_used | bool) | ternary(' --by-service', '') }}
become: yes
become_user: "{{ _db_nova_system_user_name }}"
changed_when: false
# If it exits with partial updates (exit status 1) it should be called again,
# even if some updates initially generated errors,
# because some updates may depend on others having completed. If it exits with status 2,
# intervention is required to resolve the issue causing remaining updates to fail.
# It should be considered successfully completed only when the exit status is 0.
- name: Perform online data migrations
command: "{{ _db_nova_bin }}/nova-manage db online_data_migrations"
become: yes
become_user: "{{ _db_nova_system_user_name }}"
changed_when: false
when:
- hostvars[nova_conductor_setup_host]['ansible_local']['openstack_ansible']['nova']['need_online_data_migrations'] | bool
retries: 5
delay: 3
until: "data_migrations.rc in [0, 2]"
register: data_migrations
- name: Disable the online migrations requirement
delegate_to: "{{ item }}"
ini_file:
dest: "/etc/ansible/facts.d/openstack_ansible.fact"
section: nova
option: need_online_data_migrations
value: False
mode: "0644"
with_items: "{{ groups[nova_services['nova-conductor']['group']] }}"
when:
- data_migrations is not skipped
- data_migrations is succeeded
- name: Create service and timer for archiving deleted records
include_role:
name: systemd_service
vars:
systemd_service_restart_changed: false
systemd_user_name: "{{ nova_system_user_name }}"
systemd_group_name: "{{ nova_system_group_name }}"
systemd_tempd_prefix: openstack
systemd_slice_name: "{{ nova_system_slice_name }}"
systemd_lock_dir: "{{ nova_lock_dir }}"
systemd_services:
- service_name: "nova-archive-deleted"
execstarts:
- /bin/sh -c "{{ _db_nova_bin }}/nova-manage db archive_deleted_rows --until-complete --all-cells --before \"$(date -d '{{ nova_archive_deleted_before }}' +'%%Y-%%m-%%d %%H:%%M')\" {{ (nova_archive_deleted_purge) | ternary('--purge', '') }} {{ (nova_archive_task_log) | ternary('--task-log', '') }}" # noqa: yaml[line-length]
environment:
UMASK: '0640'
UMASK_DIR: '0750'
program_sandboxing:
RuntimeDirectory: 'nova-archive-deleted'
enabled: "{{ nova_archive_deleted }}"
timer:
state: "{{ nova_archive_deleted | ternary('started', 'stopped') }}"
enabled: "{{ nova_archive_deleted }}"
options:
OnCalendar: "{{ nova_archive_deleted_on_calendar }}"
RandomizedDelaySec: "{{ nova_archive_deleted_randomized_delay_sec }}"
Persistent: true
Unit: "nova-archive-deleted.service"
- service_name: "nova-purge-deleted"
execstarts:
- /bin/sh -c "{{ _db_nova_bin }}/nova-manage db purge --all-cells --before \"$(date -d '{{ nova_purge_deleted_before }}' +'%%Y-%%m-%%d %%H:%%M')\"" # noqa: yaml[line-length]
environment:
UMASK: '0640'
UMASK_DIR: '0750'
program_sandboxing:
RuntimeDirectory: 'nova-purge-deleted'
enabled: "{{ nova_purge_deleted }}"
timer:
state: "{{ nova_purge_deleted | ternary('started', 'stopped') }}"
enabled: "{{ nova_purge_deleted }}"
options:
OnCalendar: "{{ nova_purge_deleted_on_calendar }}"
RandomizedDelaySec: "{{ nova_purge_deleted_randomized_delay_sec }}"
Persistent: true
Unit: "nova-purge-deleted.service"