# This is the playbook used by ovn-migration.sh.

#
# Backup the controllers to have a backup in case the
# migration fails leaving the testbed on a broken status.
#

- name: Backup controllers pre-migration
  hosts: localhost
  roles:
    - recovery-backup
  tags:
    - recovery-backup


#
# Pre migration and validation tasks will make sure that the initial cloud
# is functional, and will create resources which will be checked after
# migration.
#


- name: Pre migration and validation tasks
  hosts: localhost
  roles:
    - pre-migration
  tags:
    - pre-migration


#
# This step is executed before migration, and will backup some config
# files related to containers before those get lost.
#

- name: Backup tripleo container config files on the nodes
  hosts: ovn-controllers
  roles:
    - backup
  tags:
    - setup


- name: Stop ml2/ovs resources
  hosts: ovn-controllers
  roles:
    - stop-agents
  tags:
    - migration


#
# TripleO / Director is executed to deploy ovn using "br-migration" for the
# dataplane, while br-int is left intact to avoid dataplane disruption.
#

- name: Set up OVN and configure it using tripleo
  hosts: localhost
  roles:
    - tripleo-update
  tags:
    - setup
  become: false


#
# Once everything is migrated prepare everything by syncing the neutron DB
# into the OVN NB database, and then switching the dataplane to br-int
# letting ovn-controller take control, afterwards any remaining neutron
# resources, namespaces or processes which are not needed anymore are
# cleaned up.
#

- name: Do the DB sync and dataplane switch
  hosts: ovn-controllers, ovn-dbs
  roles:
    - migration
  vars:
      ovn_bridge: br-int
  tags:
    - migration


#
# Verify that the initial resources are still reachable, remove them,
# and afterwards create new resources and repeat the connectivity tests.
#

- name: Post migration
  hosts: localhost
  roles:
    - delete-neutron-resources
    - post-migration
  tags:
    - post-migration


#
# Final validation after tripleo update to br-int
#

- name: Final validation
  hosts: localhost
  vars:
      validate_premigration_resources: false
  roles:
    - post-migration
  tags:
    - final-validation


#
# Announce that it's done and ready.
#

- hosts: localhost
  tasks:
  - name: Migration successful.
    debug:
      msg: Migration from ML2OVS to OVN is now complete.

