---
- name: "Setting Docker Facts"
  set_fact:
    docker_storage_block_device: "{{ docker_storage_block_device | default(default_docker_storage_block_device) }}"
    docker_storage_volume_group: "{{ docker_storage_volume_group | default(default_docker_storage_volume_group) }}"

- name: "Install Docker"
  yum:
    name: docker
    state: latest
    update_cache: yes
  notify:
    - enable docker

- name: "Check for existing Docker Storage device"
  command: pvs
  register: pvs

- name: "Set Docker Storage fact if already configured"
  set_fact:
    docker_storage_setup: true
  when: pvs.stdout | search(docker_storage_block_device ~ '.*' ~ docker_storage_volume_group)

- name: "Configure Docker Storage Setup"
  template:
    src: docker-storage-setup.j2
    dest: /etc/sysconfig/docker-storage-setup
  when: docker_storage_setup is undefined
  notify:
    - restart docker
