---
- name: Looking up disks for Swift
  become: true
  command: "{{ kolla_container_engine }} exec -t kolla_toolbox sudo -E ansible localhost
    -m find_disks
    -a \"name={{ swift_devices_name }}
        match_mode={{ swift_devices_match_mode }}\""
  register: swift_disk_lookup
  changed_when: swift_disk_lookup.stdout.find('localhost | SUCCESS => ') != -1 and
                    (swift_disk_lookup.stdout.split('localhost | SUCCESS => ')[1] | from_json).changed
  failed_when: swift_disk_lookup.stdout.split()[2] != 'SUCCESS'
  when: inventory_hostname in groups['swift-account-server'] or
        inventory_hostname in groups['swift-container-server'] or
        inventory_hostname in groups['swift-object-server']

- name: Reading data from variable
  set_fact:
    swift_disks: "{{ (swift_disk_lookup.stdout.split('localhost | SUCCESS => ')[1] | from_json).disks | from_json }}"
  when: inventory_hostname in groups['swift-account-server'] or
        inventory_hostname in groups['swift-container-server'] or
        inventory_hostname in groups['swift-object-server']

- name: Mounting Swift disks
  become: true
  mount:
    src: "UUID={{ item.fs_uuid }}"
    fstype: xfs
    opts: "noatime,nodiratime,logbufs=8"
    state: mounted
    name: "{{ swift_devices_mount_point }}/{{ item['fs_label'] }}"
  with_items: "{{ swift_disks }}"
  when: inventory_hostname in groups['swift-account-server'] or
        inventory_hostname in groups['swift-container-server'] or
        inventory_hostname in groups['swift-object-server']

- name: Starting swift-rsyncd container
  become: true
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ swift_rsyncd_image_full }}"
    name: "swift_rsyncd"
    volumes:
      - "{{ node_config_directory }}/swift-rsyncd/:{{ container_config_directory }}/:ro"
      - "{{ swift_devices_mount_point }}:{{ swift_devices_mount_point }}:shared"
      - "/etc/localtime:/etc/localtime:ro"
  when: inventory_hostname in groups['swift-account-server'] or
        inventory_hostname in groups['swift-container-server'] or
        inventory_hostname in groups['swift-object-server']

- name: Starting swift-account-server container
  become: true
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    name: "swift_account_server"
    image: "{{ swift_account_image_full }}"
    volumes:
      - "{{ node_config_directory }}/swift/:/var/lib/kolla/swift/:ro"
      - "{{ node_config_directory }}/swift-account-server/:{{ container_config_directory }}/:ro"
      - "{{ swift_devices_mount_point }}:{{ swift_devices_mount_point }}:shared"
      - "/etc/localtime:/etc/localtime:ro"
  when: inventory_hostname in groups['swift-account-server']

- name: Starting swift-account-auditor container
  become: true
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ swift_account_image_full }}"
    name: "swift_account_auditor"
    volumes:
      - "{{ node_config_directory }}/swift/:/var/lib/kolla/swift/:ro"
      - "{{ node_config_directory }}/swift-account-auditor/:{{ container_config_directory }}/:ro"
      - "{{ swift_devices_mount_point }}:{{ swift_devices_mount_point }}:shared"
      - "/etc/localtime:/etc/localtime:ro"
      - "swift_recon_cache:/var/cache/swift"
  when: inventory_hostname in groups['swift-account-server']

- name: Starting swift-account-replication-server container
  become: true
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    environment:
      RSYNC_CONNECT_PROG: "nc %H {{ swift_rsync_port }}"
    image: "{{ swift_account_image_full }}"
    name: "swift_account_replication_server"
    volumes:
      - "{{ node_config_directory }}/swift/:/var/lib/kolla/swift/:ro"
      - "{{ node_config_directory }}/swift-account-replication-server/:{{ container_config_directory }}/:ro"
      - "{{ swift_devices_mount_point }}:{{ swift_devices_mount_point }}:shared"
      - "/etc/localtime:/etc/localtime:ro"
  when:
    - inventory_hostname in groups['swift-account-server']
    - swift_has_replication_network

- name: Starting swift-account-replicator container
  become: true
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    environment:
      RSYNC_CONNECT_PROG: "nc %H {{ swift_rsync_port }}"
    image: "{{ swift_account_image_full }}"
    name: "swift_account_replicator"
    volumes:
      - "{{ node_config_directory }}/swift/:/var/lib/kolla/swift/:ro"
      - "{{ node_config_directory }}/swift-account-replicator/:{{ container_config_directory }}/:ro"
      - "{{ swift_devices_mount_point }}:{{ swift_devices_mount_point }}:shared"
      - "/etc/localtime:/etc/localtime:ro"
      - "swift_recon_cache:/var/cache/swift"
  when: inventory_hostname in groups['swift-account-server']

- name: Starting swift-account-reaper container
  become: true
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ swift_account_image_full }}"
    name: "swift_account_reaper"
    volumes:
      - "{{ node_config_directory }}/swift/:/var/lib/kolla/swift/:ro"
      - "{{ node_config_directory }}/swift-account-reaper/:{{ container_config_directory }}/:ro"
      - "{{ swift_devices_mount_point }}:{{ swift_devices_mount_point }}:shared"
      - "/etc/localtime:/etc/localtime:ro"
  when: inventory_hostname in groups['swift-account-server']

- name: Starting swift-container-server container
  become: true
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ swift_container_image_full }}"
    name: "swift_container_server"
    volumes:
      - "{{ node_config_directory }}/swift/:/var/lib/kolla/swift/:ro"
      - "{{ node_config_directory }}/swift-container-server/:{{ container_config_directory }}/:ro"
      - "{{ swift_devices_mount_point }}:{{ swift_devices_mount_point }}:shared"
      - "/etc/localtime:/etc/localtime:ro"
  when: inventory_hostname in groups['swift-container-server']

- name: Starting swift-container-auditor container
  become: true
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ swift_container_image_full }}"
    name: "swift_container_auditor"
    volumes:
      - "{{ node_config_directory }}/swift/:/var/lib/kolla/swift/:ro"
      - "{{ node_config_directory }}/swift-container-auditor/:{{ container_config_directory }}/:ro"
      - "{{ swift_devices_mount_point }}:{{ swift_devices_mount_point }}:shared"
      - "/etc/localtime:/etc/localtime:ro"
      - "swift_recon_cache:/var/cache/swift"
  when: inventory_hostname in groups['swift-container-server']

- name: Starting swift-container-replication-server container
  become: true
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    environment:
      RSYNC_CONNECT_PROG: "nc %H {{ swift_rsync_port }}"
    image: "{{ swift_container_image_full }}"
    name: "swift_container_replication_server"
    volumes:
      - "{{ node_config_directory }}/swift/:/var/lib/kolla/swift/:ro"
      - "{{ node_config_directory }}/swift-container-replication-server/:{{ container_config_directory }}/:ro"
      - "{{ swift_devices_mount_point }}:{{ swift_devices_mount_point }}:shared"
      - "/etc/localtime:/etc/localtime:ro"
  when:
    - inventory_hostname in groups['swift-container-server']
    - swift_has_replication_network

- name: Starting swift-container-replicator container
  become: true
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    environment:
      RSYNC_CONNECT_PROG: "nc %H {{ swift_rsync_port }}"
    image: "{{ swift_container_image_full }}"
    name: "swift_container_replicator"
    volumes:
      - "{{ node_config_directory }}/swift/:/var/lib/kolla/swift/:ro"
      - "{{ node_config_directory }}/swift-container-replicator/:{{ container_config_directory }}/:ro"
      - "{{ swift_devices_mount_point }}:{{ swift_devices_mount_point }}:shared"
      - "/etc/localtime:/etc/localtime:ro"
      - "swift_recon_cache:/var/cache/swift"
  when: inventory_hostname in groups['swift-container-server']

- name: Starting swift-container-updater container
  become: true
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ swift_container_image_full }}"
    name: "swift_container_updater"
    volumes:
      - "{{ node_config_directory }}/swift/:/var/lib/kolla/swift/:ro"
      - "{{ node_config_directory }}/swift-container-updater/:{{ container_config_directory }}/:ro"
      - "{{ swift_devices_mount_point }}:{{ swift_devices_mount_point }}:shared"
      - "/etc/localtime:/etc/localtime:ro"
      - "swift_recon_cache:/var/cache/swift"
  when: inventory_hostname in groups['swift-container-server']

- name: Starting swift-object-server container
  become: true
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ swift_object_image_full }}"
    name: "swift_object_server"
    volumes:
      - "{{ node_config_directory }}/swift/:/var/lib/kolla/swift/:ro"
      - "{{ node_config_directory }}/swift-object-server/:{{ container_config_directory }}/:ro"
      - "{{ swift_devices_mount_point }}:{{ swift_devices_mount_point }}:shared"
      - "/etc/localtime:/etc/localtime:ro"
      - "swift_recon_cache:/var/cache/swift:ro"
  when: inventory_hostname in groups['swift-object-server']

- name: Starting swift-object-auditor container
  become: true
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ swift_object_image_full }}"
    name: "swift_object_auditor"
    volumes:
      - "{{ node_config_directory }}/swift/:/var/lib/kolla/swift/:ro"
      - "{{ node_config_directory }}/swift-object-auditor/:{{ container_config_directory }}/:ro"
      - "{{ swift_devices_mount_point }}:{{ swift_devices_mount_point }}:shared"
      - "/etc/localtime:/etc/localtime:ro"
      - "swift_recon_cache:/var/cache/swift"
  when: inventory_hostname in groups['swift-object-server']

- name: Starting swift-object-replication-server container
  become: true
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    environment:
      RSYNC_CONNECT_PROG: "nc %H {{ swift_rsync_port }}"
    image: "{{ swift_object_image_full }}"
    name: "swift_object_replication_server"
    volumes:
      - "{{ node_config_directory }}/swift/:/var/lib/kolla/swift/:ro"
      - "{{ node_config_directory }}/swift-object-replication-server/:{{ container_config_directory }}/:ro"
      - "{{ swift_devices_mount_point }}:{{ swift_devices_mount_point }}:shared"
      - "/etc/localtime:/etc/localtime:ro"
  when:
    - inventory_hostname in groups['swift-object-server']
    - swift_has_replication_network

- name: Starting swift-object-replicator container
  become: true
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    environment:
      RSYNC_CONNECT_PROG: "nc %H {{ swift_rsync_port }}"
    image: "{{ swift_object_image_full }}"
    name: "swift_object_replicator"
    volumes:
      - "{{ node_config_directory }}/swift/:/var/lib/kolla/swift/:ro"
      - "{{ node_config_directory }}/swift-object-replicator/:{{ container_config_directory }}/:ro"
      - "{{ swift_devices_mount_point }}:{{ swift_devices_mount_point }}:shared"
      - "/etc/localtime:/etc/localtime:ro"
      - "swift_recon_cache:/var/cache/swift"
  when: inventory_hostname in groups['swift-object-server']

- name: Starting swift-object-updater container
  become: true
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ swift_object_image_full }}"
    name: "swift_object_updater"
    volumes:
      - "{{ node_config_directory }}/swift/:/var/lib/kolla/swift/:ro"
      - "{{ node_config_directory }}/swift-object-updater/:{{ container_config_directory }}/:ro"
      - "{{ swift_devices_mount_point }}:{{ swift_devices_mount_point }}:shared"
      - "/etc/localtime:/etc/localtime:ro"
      - "swift_recon_cache:/var/cache/swift"
  when: inventory_hostname in groups['swift-object-server']

- name: Starting swift-object-expirer container
  become: true
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ swift_object_expirer_image_full }}"
    name: "swift_object_expirer"
    volumes:
      - "{{ node_config_directory }}/swift/:/var/lib/kolla/swift/:ro"
      - "{{ node_config_directory }}/swift-object-expirer/:{{ container_config_directory }}/:ro"
      - "{{ swift_devices_mount_point }}:{{ swift_devices_mount_point }}:shared"
      - "/etc/localtime:/etc/localtime:ro"
      - "swift_recon_cache:/var/cache/swift"
  when: inventory_hostname in groups['swift-object-server']

- name: Starting swift-proxy-server container
  become: true
  kolla_docker:
    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'] and
        run_start_swift_proxy_server | bool
