---
- name: Starting openvswitch-db container
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ openvswitch_db_image_full }}"
    name: "openvswitch_db"
    volumes:
      - "{{ node_config_directory }}/openvswitch-db-server/:{{ container_config_directory }}/:ro"
      - "/etc/localtime:/etc/localtime:ro"
      - "/run:/run:shared"
      - "kolla_logs:/var/log/kolla/"
      - "openvswitch_db:/var/lib/openvswitch/"
  when:
    - (inventory_hostname in groups['compute']
       or (enable_manila | bool and inventory_hostname in groups['manila-share'])
       or inventory_hostname in groups['neutron-dhcp-agent']
       or inventory_hostname in groups['neutron-l3-agent']
       or inventory_hostname in groups['neutron-metadata-agent']
       or inventory_hostname in groups['neutron-vpnaas-agent'])
    - neutron_plugin_agent == "openvswitch"

- name: Waiting the openvswitch_db service to be ready
  command: docker exec openvswitch_db ovs-vsctl --no-wait show
  register: check_result
  until: check_result | success
  changed_when: False
  retries: 30
  delay: 2
  when:
    - (inventory_hostname in groups['compute']
       or (enable_manila | bool and inventory_hostname in groups['manila-share'])
       or inventory_hostname in groups['neutron-dhcp-agent']
       or inventory_hostname in groups['neutron-l3-agent']
       or inventory_hostname in groups['neutron-metadata-agent']
       or inventory_hostname in groups['neutron-vpnaas-agent'])
    - neutron_plugin_agent == "openvswitch"

- name: Ensuring OVS bridge is properly setup
  command: docker exec openvswitch_db /usr/local/bin/kolla_ensure_openvswitch_configured {{ item.0 }} {{ item.1 }}
  register: status
  changed_when: status.stdout.find('changed') != -1
  when:
    - (inventory_hostname in groups['compute']
       or (enable_manila | bool and inventory_hostname in groups['manila-share'])
       or inventory_hostname in groups['neutron-dhcp-agent']
       or inventory_hostname in groups['neutron-l3-agent']
       or inventory_hostname in groups['neutron-metadata-agent']
       or inventory_hostname in groups['neutron-vpnaas-agent'])
    - neutron_plugin_agent == "openvswitch"
  with_together:
    - "{{ neutron_bridge_name.split(',') }}"
    - "{{ neutron_external_interface.split(',') }}"

- name: Starting openvswitch-vswitchd container
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ openvswitch_vswitchd_image_full }}"
    name: "openvswitch_vswitchd"
    privileged: True
    volumes:
      - "{{ node_config_directory }}/openvswitch-vswitchd/:{{ container_config_directory }}/:ro"
      - "/etc/localtime:/etc/localtime:ro"
      - "/lib/modules:/lib/modules:ro"
      - "/run:/run:shared"
      - "kolla_logs:/var/log/kolla/"
  when:
    - (inventory_hostname in groups['compute']
       or (enable_manila | bool and inventory_hostname in groups['manila-share'])
       or inventory_hostname in groups['neutron-dhcp-agent']
       or inventory_hostname in groups['neutron-l3-agent']
       or inventory_hostname in groups['neutron-metadata-agent']
       or inventory_hostname in groups['neutron-vpnaas-agent'])
    - neutron_plugin_agent == "openvswitch"

- name: Starting neutron-server container
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ neutron_server_image_full }}"
    name: "neutron_server"
    volumes:
      - "{{ node_config_directory }}/neutron-server/:{{ container_config_directory }}/:ro"
      - "/etc/localtime:/etc/localtime:ro"
      - "kolla_logs:/var/log/kolla/"
  when: inventory_hostname in groups['neutron-server']

- name: Starting neutron-openvswitch-agent container
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ neutron_openvswitch_agent_image_full }}"
    name: "neutron_openvswitch_agent"
    privileged: True
    volumes:
      - "{{ node_config_directory }}/neutron-openvswitch-agent/:{{ container_config_directory }}/:ro"
      - "/etc/localtime:/etc/localtime:ro"
      - "/lib/modules:/lib/modules:ro"
      - "/run:/run:shared"
      - "kolla_logs:/var/log/kolla/"
  when:
    - (
        ( inventory_hostname in groups['compute']
          or (enable_manila | bool and inventory_hostname in groups['manila-share'])
          or inventory_hostname in groups['neutron-dhcp-agent']
          or inventory_hostname in groups['neutron-l3-agent']
          or inventory_hostname in groups['neutron-metadata-agent']
          or inventory_hostname in groups['neutron-vpnaas-agent']
          and not enable_nova_fake | bool
        ) or
        ( inventory_hostname in groups['neutron-dhcp-agent']
          or inventory_hostname in groups['neutron-l3-agent']
          or inventory_hostname in groups['neutron-metadata-agent']
          or inventory_hostname in groups['neutron-vpnaas-agent']
          and enable_nova_fake | bool
        )
      )
    - neutron_plugin_agent == "openvswitch"

- name: Starting neutron-sfc-agent container
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ neutron_sfc_agent_image_full }}"
    name: "neutron_sfc_agent"
    privileged: True
    volumes:
      - "{{ node_config_directory }}/neutron-sfc-agent/:{{ container_config_directory }}/:ro"
      - "/etc/localtime:/etc/localtime:ro"
      - "/lib/modules:/lib/modules:ro"
      - "/run:/run:shared"
      - "kolla_logs:/var/log/kolla/"
  when:
    - (
        ( inventory_hostname in groups['compute']
          or (enable_manila | bool and inventory_hostname in groups['manila-share'])
          or inventory_hostname in groups['neutron-dhcp-agent']
          or inventory_hostname in groups['neutron-l3-agent']
          or inventory_hostname in groups['neutron-metadata-agent']
          and not enable_nova_fake | bool
        ) or
        ( inventory_hostname in groups['neutron-dhcp-agent']
          or inventory_hostname in groups['neutron-l3-agent']
          or inventory_hostname in groups['neutron-metadata-agent']
          and enable_nova_fake | bool
        )
      )
    - neutron_plugin_agent == "sfc"

- name: Starting neutron-openvswitch-agent container for fake nova compute
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ neutron_openvswitch_agent_image_full }}"
    name: "neutron_openvswitch_agent_fake_{{ item }}"
    privileged: True
    volumes:
      - "{{ node_config_directory }}/neutron-openvswitch-agent-fake-{{ item }}/:{{ container_config_directory }}/:ro"
      - "/etc/localtime:/etc/localtime:ro"
      - "/lib/modules:/lib/modules:ro"
      - "/run:/run:shared"
      - "kolla_logs:/var/log/kolla/"
  with_sequence: start=1 end={{ num_nova_fake_per_node }}
  when:
    - inventory_hostname in groups['compute']
    - neutron_plugin_agent == "openvswitch"
    - enable_nova_fake | bool

- name: Starting neutron-sfc-agent container for fake nova compute
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ neutron_sfc_agent_image_full }}"
    name: "neutron_sfc_agent_fake_{{ item }}"
    privileged: True
    volumes:
      - "{{ node_config_directory }}/neutron-sfc-agent-fake-{{ item }}/:{{ container_config_directory }}/:ro"
      - "/etc/localtime:/etc/localtime:ro"
      - "/lib/modules:/lib/modules:ro"
      - "/run:/run:shared"
      - "kolla_logs:/var/log/kolla/"
  with_sequence: start=1 end={{ num_nova_fake_per_node }}
  when:
    - inventory_hostname in groups['compute']
    - neutron_plugin_agent == "sfc"
    - enable_nova_fake | bool

- name: Starting neutron-linuxbridge-agent container
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    environment:
      KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
      NEUTRON_BRIDGE: "br-ex"
      NEUTRON_INTERFACE: "{{ neutron_external_interface }}"
    image: "{{ neutron_linuxbridge_agent_image_full }}"
    name: "neutron_linuxbridge_agent"
    privileged: True
    volumes:
      - "{{ node_config_directory }}/neutron-linuxbridge-agent/:{{ container_config_directory }}/:ro"
      - "/etc/localtime:/etc/localtime:ro"
      - "/lib/modules:/lib/modules:ro"
      - "/run:/run:shared"
      - "kolla_logs:/var/log/kolla/"
  when:
    - (inventory_hostname in groups['compute']
       or (enable_manila | bool and inventory_hostname in groups['manila-share'])
       or inventory_hostname in groups['neutron-dhcp-agent']
       or inventory_hostname in groups['neutron-l3-agent']
       or inventory_hostname in groups['neutron-metadata-agent']
       or inventory_hostname in groups['neutron-vpnaas-agent'])
    - neutron_plugin_agent == "linuxbridge"

- name: Starting neutron-dhcp-agent container
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ neutron_dhcp_agent_image_full }}"
    name: "neutron_dhcp_agent"
    privileged: True
    volumes:
      - "{{ node_config_directory }}/neutron-dhcp-agent/:{{ container_config_directory }}/:ro"
      - "/etc/localtime:/etc/localtime:ro"
      - "/run/:/run/:shared"
      - "/run/netns/:/run/netns/:shared"
      - "neutron_metadata_socket:/var/lib/neutron/kolla/"
      - "kolla_logs:/var/log/kolla/"
  when:
    - inventory_hostname in groups['neutron-dhcp-agent']

- name: Starting neutron-l3-agent container
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ neutron_l3_agent_image_full }}"
    name: "neutron_l3_agent"
    privileged: True
    volumes:
      - "{{ node_config_directory }}/neutron-l3-agent/:{{ container_config_directory }}/:ro"
      - "/etc/localtime:/etc/localtime:ro"
      - "/run:/run:shared"
      - "/run/netns/:/run/netns/:shared"
      - "neutron_metadata_socket:/var/lib/neutron/kolla/"
      - "kolla_logs:/var/log/kolla/"
  when:
    - (inventory_hostname in groups['neutron-l3-agent']
       or (inventory_hostname in groups['compute'] and enable_neutron_dvr | bool))
    - not enable_neutron_vpnaas | bool

- name: Starting neutron-lbaas-agent container
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ neutron_lbaas_agent_image_full }}"
    name: "neutron_lbaas_agent"
    privileged: True
    volumes:
      - "{{ node_config_directory }}/neutron-lbaas-agent/:{{ container_config_directory }}/:ro"
      - "/etc/localtime:/etc/localtime:ro"
      - "/run:/run:shared"
      - "/run/netns/:/run/netns/:shared"
      - "neutron_metadata_socket:/var/lib/neutron/kolla/"
      - "kolla_logs:/var/log/kolla/"
  when:
    - enable_neutron_lbaas | bool
    - inventory_hostname in groups['neutron-lbaas-agent']

- name: Starting neutron-metadata-agent container
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ neutron_metadata_agent_image_full }}"
    name: "neutron_metadata_agent"
    privileged: True
    volumes:
      - "{{ node_config_directory }}/neutron-metadata-agent/:{{ container_config_directory }}/:ro"
      - "/etc/localtime:/etc/localtime:ro"
      - "/run/netns/:/run/netns/:shared"
      - "neutron_metadata_socket:/var/lib/neutron/kolla/"
      - "kolla_logs:/var/log/kolla/"
  when:
    - (inventory_hostname in groups['neutron-metadata-agent']
       or (inventory_hostname in groups['compute'] and enable_neutron_dvr | bool))

- name: Starting neutron-vpnaas-agent container
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ neutron_vpnaas_agent_image_full }}"
    name: "neutron_vpnaas_agent"
    privileged: True
    volumes:
      - "{{ node_config_directory }}/neutron-vpnaas-agent/:{{ container_config_directory }}/:ro"
      - "/etc/localtime:/etc/localtime:ro"
      - "/run:/run:shared"
      - "/run/netns/:/run/netns/:shared"
      - "neutron_metadata_socket:/var/lib/neutron/kolla/"
      - "kolla_logs:/var/log/kolla/"
  when:
    - enable_neutron_vpnaas | bool
    - inventory_hostname in groups['neutron-vpnaas-agent']