---
- name: stop neutron_api containers
  ansible.builtin.systemd:
    name: tripleo_neutron_api
    state: stopped

- name: get neutron_server image url
  command: podman ps -a --filter "name=neutron_api" --format {% raw %}"{{.Image}}"{% endraw %}
  register: neutron_server_image

- name: sync neutron db with OVN db
  command: podman run --name {{ ovn_db_sync_container }}
    -v /var/log/containers/neutron:/var/log/neutron:Z
    -v /var/lib/config-data/puppet-generated/neutron/etc/neutron:/etc/neutron:Z
    --privileged=True --network host --user root
    {{ neutron_server_image.stdout }}
    neutron-ovn-db-sync-util --config-file /etc/neutron/neutron.conf
    --config-file /etc/neutron/plugins/ml2/ml2_conf.ini
    --log-file /var/log/neutron/neutron-db-sync.log
    --ovn-neutron_sync_mode migrate
    --debug
  when: ovn_central is defined

- name: remove db-sync container
  command: podman rm -f {{ ovn_db_sync_container }}
  when: ovn_central is defined

- name: start neutron_api containers
  ansible.builtin.systemd:
    name: tripleo_neutron_api
    state: started

- name: Pause and let ovn-controllers settle before doing the final activation (5 minute)
  pause: minutes=5
