---
- apt: pkg={{ item }}
  with_items:
    - cryptsetup
    - lvm2
    - tgt
    - nbd-client

- file: dest=/etc/tgt/conf.d state=directory
- template: src=etc/tgt/targets.conf dest=/etc/tgt/targets.conf mode=0644
- template: src=etc/tgt/conf.d/cinder_tgt.conf dest=/etc/tgt/conf.d/cinder_tgt.conf mode=0644

- service: name=tgt state=started

# TODO: allow for device-backed VGs in addition to file-backed VGs
- name: cinder volume group
  cinder_volume_group: >
    file={{ cinder.volume_file }}
    size={{ cinder.volume_file_size }}
    passphrase={{ cinder.passphrase }}

- name: create cinder-volumes crypttab entry
  crypttab: state=present target=cinder-volumes source=/opt/stack/cinder-volumes opts=luks,aes,noauto

- name: cinder-volume start script
  template: src=etc/init/cinder-volume.conf dest=/etc/init/cinder-volume.conf mode=0644

- name: cinder-volume is running
  service: name=cinder-volume state=started

---
- apt: pkg={{ item }}
  with_items:
    - cryptsetup
    - lvm2
    - tgt
    - nbd-client

- file: dest=/etc/tgt/conf.d state=directory
- template: src=etc/tgt/targets.conf dest=/etc/tgt/targets.conf mode=0644
- template: src=etc/tgt/conf.d/cinder_tgt.conf dest=/etc/tgt/conf.d/cinder_tgt.conf mode=0644

- service: name=tgt state=started

# TODO: allow for device-backed VGs in addition to file-backed VGs
- name: cinder volume group
  cinder_volume_group: >
    file={{ cinder.volume_file }}
    size={{ cinder.volume_file_size }}
    {% if cinder.passphrase is defined %}
    passphrase={{ cinder.passphrase }}
    {% endif %}

- name: create cinder-volumes crypttab entry
  crypttab: state=present target=cinder-volumes source=/opt/stack/cinder-volumes opts=luks,aes,noauto

- name: cinder-volume start script
  template: src=etc/init/cinder-volume.conf dest=/etc/init/cinder-volume.conf mode=0644

- name: cinder-volume is running
  service: name=cinder-volume state=started

Use cinder.passphrase only if it is defined.
Use cinder.passphrase only if it is defined.
