---
- name: Prepare Swift containers list
  set_fact:
    swift_containers:
      - { name: swift_account_server, group: swift-account-server }
      - { name: swift_account_auditor, group: swift-account-server }
      - { name: swift_account_replicator, group: swift-account-server }
      - { name: swift_account_reaper, group: swift-account-server }
      - { name: swift_rsyncd, group: swift-account-server }
      - { name: swift_container_server, group: swift-container-server }
      - { name: swift_container_auditor, group: swift-container-server }
      - { name: swift_container_replicator, group: swift-container-server }
      - { name: swift_container_updater, group: swift-container-server }
      - { name: swift_rsyncd, group: swift-container-server }
      - { name: swift_object_server, group: swift-object-server }
      - { name: swift_object_auditor, group: swift-object-server }
      - { name: swift_object_replicator, group: swift-object-server }
      - { name: swift_object_updater, group: swift-object-server }
      - { name: swift_object_expirer, group: swift-object-server }
      - { name: swift_rsyncd, group: swift-object-server }

# Upgrade swift storage nodes first
- include_tasks: config.yml
  when: inventory_hostname in groups['swift-account-server'] or
        inventory_hostname in groups['swift-container-server'] or
        inventory_hostname in groups['swift-object-server']

# TODO(donghm): Below tasks should be run in serial nodes to
# decrease downtime. Update once the module ansible strategy for
# rolling upgrade will be finished.
- name: Gracefully shutdown swift services in storage nodes
  become: true
  kolla_container:
    common_options: "{{ docker_common_options }}"
    action: "stop_container"
    name: "{{ item.name }}"
  when: inventory_hostname in groups[item.group]
  with_items:
    - "{{ swift_containers }}"

- import_tasks: start.yml
  vars:
    run_start_swift_proxy_server: "no"

# Upgrade swift proxy nodes
- include_tasks: config.yml
  when: inventory_hostname in groups['swift-proxy-server']

- name: Gracefully shutdown swift proxy services in proxy nodes
  become: true
  kolla_container:
    common_options: "{{ docker_common_options }}"
    action: "stop_container"
    name: "swift_proxy_server"
  when: inventory_hostname in groups['swift-proxy-server']

- name: Start new swift proxy server container
  become: true
  kolla_container:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ swift_proxy_server_image_full }}"
    name: "swift_proxy_server"
    volumes:
      - "{{ node_config_directory }}/swift/:/var/lib/kolla/swift/:ro"
      - "{{ node_config_directory }}/swift-proxy-server/:{{ container_config_directory }}/:ro"
      - "/etc/localtime:/etc/localtime:ro"
  when: inventory_hostname in groups['swift-proxy-server']
