Add ceph backend for cinder

installer-type: kolla
deploy-scenario: os-nosdn-nofeature

Change-Id: I0657fa33f878051d798031bf449fc03fe6fe803a
diff --git a/playbooks/roles/configure-targethosts/tasks/install-packages-Debian.yml b/playbooks/roles/configure-targethosts/tasks/install-packages-Debian.yml
index 05b9a76..ab8cf63 100644
--- a/playbooks/roles/configure-targethosts/tasks/install-packages-Debian.yml
+++ b/playbooks/roles/configure-targethosts/tasks/install-packages-Debian.yml
@@ -33,6 +33,7 @@
     - "lvm2"
     - "nfs-kernel-server"
     - "tzdata"
+    - "parted"
 
 # NOTE: raw install is required to support cloud images which do not have python installed
 # This is copied from kolla-ansible: ansible/roles/baremetal/tasks/pre-install.yml
diff --git a/playbooks/roles/configure-targethosts/tasks/install-packages-RedHat.yml b/playbooks/roles/configure-targethosts/tasks/install-packages-RedHat.yml
index 4c46f95..29a64b3 100644
--- a/playbooks/roles/configure-targethosts/tasks/install-packages-RedHat.yml
+++ b/playbooks/roles/configure-targethosts/tasks/install-packages-RedHat.yml
@@ -30,5 +30,6 @@
     - "lvm2"
     - "nfs-kernel-server"
     - "tzdata"
+    - "parted"
 
 # vim: set ts=2 sw=2 expandtab:
diff --git a/playbooks/roles/configure-targethosts/tasks/main.yml b/playbooks/roles/configure-targethosts/tasks/main.yml
index e33f6be..3fde5ec 100644
--- a/playbooks/roles/configure-targethosts/tasks/main.yml
+++ b/playbooks/roles/configure-targethosts/tasks/main.yml
@@ -21,7 +21,7 @@
 - include: install-packages.yml
 - include: sync-time.yml
 - include: create-swap.yml
-- include: prepare-cinder-lvm-backend.yml
-- include: prepare-cinder-nfs-backup.yml
+- include: prepare-cinder-{{ cinder_storage_driver }}.yml
+- include: prepare-cinder-backup-{{ cinder_storage_backup_driver }}.yml
 
 # vim: set ts=2 sw=2 expandtab:
diff --git a/playbooks/roles/configure-targethosts/tasks/prepare-cinder-nfs-backup.yml b/playbooks/roles/configure-targethosts/tasks/prepare-cinder-backup-nfs.yml
similarity index 100%
rename from playbooks/roles/configure-targethosts/tasks/prepare-cinder-nfs-backup.yml
rename to playbooks/roles/configure-targethosts/tasks/prepare-cinder-backup-nfs.yml
diff --git a/playbooks/roles/configure-targethosts/tasks/prepare-cinder-lvm-backend.yml b/playbooks/roles/configure-targethosts/tasks/prepare-cinder-ceph.yml
similarity index 79%
copy from playbooks/roles/configure-targethosts/tasks/prepare-cinder-lvm-backend.yml
copy to playbooks/roles/configure-targethosts/tasks/prepare-cinder-ceph.yml
index 4052305..60bbe62 100644
--- a/playbooks/roles/configure-targethosts/tasks/prepare-cinder-lvm-backend.yml
+++ b/playbooks/roles/configure-targethosts/tasks/prepare-cinder-ceph.yml
@@ -16,15 +16,6 @@
 #
 # SPDX-License-Identifier: Apache-2.0
 # ============LICENSE_END=========================================================
-- name: Run pvscan
-  command: "pvscan"
-  changed_when: false
-
-- name: Remove cinder-volumes volume group if it exists
-  lvg:
-    vg: cinder-volumes
-    state: absent
-  ignore_errors: yes
 
 - name: Check for cinder image
   stat:
@@ -38,10 +29,6 @@
     register: cinder_device
     ignore_errors: yes
 
-  - name: Delete PV on loopback device
-    command: "pvremove {{ cinder_device.stdout }}"
-    ignore_errors: yes
-
   - name: Delete loopback device
     command: "losetup -d {{ cinder_device.stdout }}"
     ignore_errors: yes
@@ -73,19 +60,22 @@
     dest: "/etc/systemd/system/cinder-loopback.service"
   become: true
 
+- name: Force systemd to reread service configs
+  systemd:
+    daemon_reload: yes
+
 - name: Enable and start cinder loopback service
   systemd:
     name: cinder-loopback
     enabled: true
     state: started
 
-- name: Create PV on the loopback device
-  command: "pvcreate {{ loopback_device_name }}"
-  changed_when: false
-
-- name: Add cinder-volumes volume group
-  lvg:
-    vg: cinder-volumes
-    pvs: "{{ loopback_device_name }}"
+- name: Create Ceph RBD partition
+  parted:
+    label: gpt
+    state: present
+    device: "{{ loopback_device_name }}"
+    number: 1
+    name: "{{ ceph_partition_name }}"
 
 # vim: set ts=2 sw=2 expandtab:
diff --git a/playbooks/roles/configure-targethosts/tasks/prepare-cinder-lvm-backend.yml b/playbooks/roles/configure-targethosts/tasks/prepare-cinder-lvm.yml
similarity index 96%
rename from playbooks/roles/configure-targethosts/tasks/prepare-cinder-lvm-backend.yml
rename to playbooks/roles/configure-targethosts/tasks/prepare-cinder-lvm.yml
index 4052305..19c35f1 100644
--- a/playbooks/roles/configure-targethosts/tasks/prepare-cinder-lvm-backend.yml
+++ b/playbooks/roles/configure-targethosts/tasks/prepare-cinder-lvm.yml
@@ -73,6 +73,10 @@
     dest: "/etc/systemd/system/cinder-loopback.service"
   become: true
 
+- name: Force systemd to reread service configs
+  systemd:
+    daemon_reload: yes
+
 - name: Enable and start cinder loopback service
   systemd:
     name: cinder-loopback