name: openstack/keystone/keystone_ansible_tasks
enabled: {{ enable_keystone | bool }}
container:
  image: "{{ kolla_toolbox_image }}:{{ kolla_toolbox_tag }}"
  parameters:
    - key: volume
      value: "kolla_logs_{{ deployment_id }}_{{ timestamp }}:/var/log/kolla"
task:
  mem: {{ keystone_init_mem }}
  cpus: {{ keystone_init_cpus }}
commands:
  create_database:
    run_once: True
    retries: 3
    delay: 5
    dependencies:
     - path: mariadb/daemon
    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='{{ keystone_database_name }}'"
  database_user_create:
    run_once: True
    retries: 3
    delay: 5
    dependencies:
     - path: keystone_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='{{ keystone_database_name }}'
          password='{{ keystone_database_password }}'
          host='%'
          priv='{{ keystone_database_name }}.*:ALL'
          append_privs='yes'"
  admin_creds:
    run_once: True
    retries: 3
    delay: 5
    dependencies:
     - path: keystone-api/db_sync
    command: {{ ansible_task_cmd }}
      -m kolla_keystone_user
      -a "project=admin
          user=admin
          password={{ keystone_admin_password }}
          role=admin
          region_name={{ openstack_region_name }}
          auth_type=admin_token
          auth={{ '{{ openstack_keystone_token_auth }}' }}"
      -e "{'openstack_keystone_token_auth':{{ openstack_keystone_token_auth }}}"
  register_endpoint:
    run_once: True
    retries: 3
    delay: 5
    dependencies:
     - path: keystone-api/db_sync
    command: {{ ansible_task_cmd }}
      -m kolla_keystone_service
      -a "service_name=keystone
          service_type=identity
          description='Openstack Identity'
          endpoint_region={{ openstack_region_name }}
          admin_url='http://{{ keystone_auth_host }}:{{ keystone_admin_port }}'
          internal_url='http://{{ keystone_auth_host }}:{{ keystone_admin_port }}'
          public_url='http://{{ keystone_auth_host }}:{{ keystone_public_port }}'
          region_name={{ openstack_region_name }}
          auth_type=admin_token
          auth={{ '{{ openstack_keystone_token_auth }}' }}"
      -e "{'openstack_keystone_token_auth':{{ openstack_keystone_token_auth }}}"
  running:
    run_once: True
    retries: 10
    delay: 5
    dependencies:
     - path: keystone-api/db_sync
    command: {{ ansible_task_cmd }}
      -m kolla_sanity
      -a "service=keystone
          project=service
          user=admin
          password={{ keystone_admin_password }}
          role=admin
          region_name={{ openstack_region_name }}
          auth={{ '{{ openstack_keystone_auth }}' }}"
      -e "{'openstack_keystone_auth':{{ openstack_keystone_auth }}}"
