name: openstack/cinder/cinder_ansible_tasks
enabled: {{ enable_cinder | bool }}
container:
  image: "{{ kolla_toolbox_image }}:{{ kolla_toolbox_tag }}"
  parameters:
    - key: volume
      value: "kolla_logs_{{ deployment_id }}_{{ timestamp }}:/var/log/kolla"
task:
  mem: {{ toolbox_mem }}
  cpus: {{ toolbox_cpus }}
commands:
  create_database:
    run_once: True
    dependencies:
     - path: mariadb/bootstrap
    command: {{ ansible_task_cmd }}
      -m mysql_db
      -a "login_host='{{ database_address }}'
          login_port='{{ mariadb_port }}'
          login_user='{{ database_user }}'
          login_password='{{ database_password }}'
          name='{{ cinder_database_name }}'"
  database_user_create:
    run_once: True
    dependencies:
     - path: cinder_ansible_tasks/create_database
    command: {{ ansible_task_cmd }}
      -m mysql_user
      -a "login_host='{{ database_address }}'
          login_port='{{ mariadb_port }}'
          login_user='{{ database_user }}'
          login_password='{{ database_password }}'
          name='{{ cinder_database_name }}'
          password='{{ cinder_database_password }}'
          host='%'
          priv='{{ cinder_database_name }}.*:ALL'
          append_privs='yes'"
  register_endpoint_v1:
    run_once: True
    dependencies:
     - path: cinder-api/db_sync
     - path: keystone_ansible_tasks/running
    command: {{ ansible_task_cmd }}
      -m kolla_keystone_service
      -a "service_name=cinder
          service_type=volume
          description='Openstack Block Storage'
          endpoint_region={{ openstack_region_name }}
          admin_url='http://{{ cinder_api_host }}:{{ cinder_api_port }}/v2/%(tenant_id)s'
          internal_url='http://{{ cinder_api_host }}:{{ cinder_api_port }}/v2/%(tenant_id)s'
          public_url='http://{{ cinder_api_host }}:{{ cinder_api_port }}/v2/%(tenant_id)s'
          region_name={{ openstack_region_name }}
          auth={{ '{{ openstack_cinder_auth }}' }}"
      -e "{'openstack_cinder_auth':{{ openstack_cinder_auth }}}"
  register_endpoint_v2:
    run_once: True
    dependencies:
     - path: cinder-api/db_sync
     - path: keystone_ansible_tasks/running
    command: {{ ansible_task_cmd }}
      -m kolla_keystone_service
      -a "service_name=cinderv2
          service_type=volumev2
          description='Openstack Block Storage'
          endpoint_region={{ openstack_region_name }}
          admin_url='http://{{ cinder_api_host }}:{{ cinder_api_port }}/v2/%(tenant_id)s'
          internal_url='http://{{ cinder_api_host }}:{{ cinder_api_port }}/v2/%(tenant_id)s'
          public_url='http://{{ cinder_api_host }}:{{ cinder_api_port }}/v2/%(tenant_id)s'
          region_name={{ openstack_region_name }}
          auth={{ '{{ openstack_cinder_auth }}' }}"
      -e "{'openstack_cinder_auth':{{ openstack_cinder_auth }}}"
  create_user:
    run_once: True
    dependencies:
     - path: cinder-api/db_sync
     - path: keystone_ansible_tasks/running
    command: {{ ansible_task_cmd }}
      -m kolla_keystone_user
      -a "project=service
          user=cinder
          password={{ cinder_keystone_password }}
          role=admin
          region_name={{ openstack_region_name }}
          auth={{ '{{ openstack_cinder_auth }}' }}"
      -e "{'openstack_cinder_auth':{{ openstack_cinder_auth }}}"
