Add sahara ansible role

Change-Id: I75b58248bfc4e86cace75faa82526d55a9ebbdbf
Partially-Implements: blueprint sahara-role
This commit is contained in:
zhubingbing 2016-08-04 17:20:20 +00:00
parent 5d8878de6d
commit 0c9debe893
22 changed files with 424 additions and 0 deletions

View File

@ -165,6 +165,8 @@ swift_account_server_port: "6001"
swift_container_server_port: "6002"
swift_rsync_port: "10873"
sahara_api_port: "8386"
heat_api_port: "8004"
heat_api_cfn_port: "8000"
@ -249,6 +251,7 @@ enable_neutron_lbaas: "no"
enable_neutron_qos: "no"
enable_neutron_agent_ha: "no"
enable_rally: "no"
enable_sahara: "no"
enable_swift: "no"
enable_tempest: "no"
enable_watcher: "no"

View File

@ -81,6 +81,9 @@ control
[magnum:children]
control
[sahara:children]
control
[mistral:children]
control
@ -282,6 +285,13 @@ gnocchi
[gnocchi-metricd:children]
gnocchi
# Sahara
[sahara-api:children]
sahara
[sahara-engine:children]
sahara
# Ceilometer
[ceilometer-api:children]
ceilometer

View File

@ -98,6 +98,9 @@ storage
[magnum:children]
control
[sahara:children]
control
[mistral:children]
control
@ -266,6 +269,13 @@ magnum
[magnum-conductor:children]
magnum
# Sahara
[sahara-api:children]
sahara
[sahara-engine:children]
sahara
# Mistral
[mistral-api:children]
mistral

View File

@ -369,6 +369,23 @@ listen watcher_api_external
{% endif %}
{% endif %}
{% if enable_sahara | bool %}
listen sahara_api
bind {{ kolla_internal_vip_address }}:{{ sahara_api_port }}
{% for host in groups['sahara-api'] %}
server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}:{{ sahara_api_port }} check inter 2000 rise 2 fall 5
{% endfor %}
{% if haproxy_enable_external_vip | bool %}
listen sahara_api_external
bind {{ kolla_external_vip_address }}:{{ sahara_api_port }} {{ tls_bind_info }}
{% for host in groups['sahara-api'] %}
server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}:{{ sahara_api_port }} check inter 2000rise 2 fall 5
{% endfor %}
{% endif %}
{% endif %}
{% if enable_ceph | bool and enable_ceph_rgw | bool %}
listen radosgw
bind {{ kolla_internal_vip_address }}:{{ rgw_port }}

View File

@ -0,0 +1,36 @@
---
project_name: "sahara"
####################
# Database
####################
sahara_database_name: "sahara"
sahara_database_user: "sahara"
sahara_database_address: "{{ kolla_internal_fqdn }}:{{ database_port }}"
####################
# Docker
####################
sahara_engine_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ kolla_install_type }}-sahara-engine"
sahara_engine_tag: "{{ openstack_release }}"
sahara_engine_image_full: "{{ sahara_engine_image }}:{{ sahara_engine_tag }}"
sahara_api_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ kolla_install_type }}-sahara-api"
sahara_api_tag: "{{ openstack_release }}"
sahara_api_image_full: "{{ sahara_api_image }}:{{ sahara_api_tag }}"
####################
# OpenStack
####################
sahara_admin_endpoint: "{{ admin_protocol }}://{{ kolla_internal_fqdn }}:{{ sahara_api_port }}"
sahara_internal_endpoint: "{{ internal_protocol }}://{{ kolla_internal_fqdn }}:{{ sahara_api_port }}"
sahara_public_endpoint: "{{ public_protocol }}://{{ kolla_external_fqdn }}:{{ sahara_api_port }}"
sahara_logging_debug: "{{ openstack_logging_debug }}"
sahara_keystone_user: "sahara"
openstack_sahara_auth: "{'auth_url':'{{ openstack_auth.auth_url }}','username':'{{ openstack_auth.username }}','password':'{{ openstack_auth.password }}','project_name':'{{ openstack_auth.project_name }}','domain_name':'default'}"

View File

@ -0,0 +1,3 @@
---
dependencies:
- { role: common }

View File

@ -0,0 +1,41 @@
---
- name: Creating sahara database
command: docker exec -t kolla_toolbox /usr/bin/ansible localhost
-m mysql_db
-a "login_host='{{ database_address }}'
login_port='{{ database_port }}'
login_user='{{ database_user }}'
login_password='{{ database_password }}'
name='{{ sahara_database_name }}'"
register: database
changed_when: "{{ database.stdout.find('localhost | SUCCESS => ') != -1 and
(database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}"
failed_when: database.stdout.split()[2] != 'SUCCESS'
run_once: True
delegate_to: "{{ groups['sahara-api'][0] }}"
- name: Reading json from variable
set_fact:
database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}"
- name: Creating sahara database user and setting permissions
command: docker exec -t kolla_toolbox /usr/bin/ansible localhost
-m mysql_user
-a "login_host='{{ database_address }}'
login_port='{{ database_port }}'
login_user='{{ database_user }}'
login_password='{{ database_password }}'
name='{{ sahara_database_name }}'
password='{{ sahara_database_password }}'
host='%'
priv='{{ sahara_database_name }}.*:ALL'
append_privs='yes'"
register: database_user_create
changed_when: "{{ database_user_create.stdout.find('localhost | SUCCESS => ') != -1 and
(database_user_create.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}"
failed_when: database_user_create.stdout.split()[2] != 'SUCCESS'
run_once: True
delegate_to: "{{ groups['sahara-api'][0] }}"
- include: bootstrap_service.yml
when: database_created

View File

@ -0,0 +1,21 @@
---
- name: Running Sahara bootstrap container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
detach: False
environment:
KOLLA_BOOTSTRAP:
KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
image: "{{ sahara_api_image_full }}"
labels:
BOOTSTRAP:
name: "bootstrap_sahara"
restart_policy: "never"
volumes:
- "{{ node_config_directory }}/sahara-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
- "sahara:/var/lib/sahara/"
run_once: True
delegate_to: "{{ groups['sahara-api'][0] }}"

View File

@ -0,0 +1,34 @@
---
- name: Ensuring config directories exist
file:
path: "{{ node_config_directory }}/{{ item }}"
state: "directory"
recurse: yes
with_items:
- "sahara-api"
- "sahara-engine"
- name: Copying over config.json files for services
template:
src: "{{ item }}.json.j2"
dest: "{{ node_config_directory }}/{{ item }}/config.json"
with_items:
- "sahara-api"
- "sahara-engine"
- name: Copying over sahara.conf
merge_configs:
vars:
service_name: "{{ item }}"
sources:
- "{{ role_path }}/templates/sahara.conf.j2"
- "{{ node_custom_config }}/global.conf"
- "{{ node_custom_config }}/database.conf"
- "{{ node_custom_config }}/messaging.conf"
- "{{ node_custom_config }}/sahara.conf"
- "{{ node_custom_config }}/sahara/{{ item }}.conf"
- "{{ node_custom_config }}/sahara/{{ inventory_hostname }}/sahara.conf"
dest: "{{ node_config_directory }}/{{ item }}/sahara.conf"
with_items:
- "sahara-api"
- "sahara-engine"

View File

@ -0,0 +1,14 @@
---
- include: register.yml
when: inventory_hostname in groups['sahara-api']
- include: config.yml
when: inventory_hostname in groups['sahara-api'] or
inventory_hostname in groups['sahara-engine']
- include: bootstrap.yml
when: inventory_hostname in groups['sahara-api']
- include: start.yml
when: inventory_hostname in groups['sahara-api'] or
inventory_hostname in groups['sahara-engine']

View File

@ -0,0 +1,69 @@
---
- name: Ensuring the containers up
kolla_docker:
name: "{{ item.name }}"
action: "get_container_state"
register: container_state
failed_when: container_state.Running == false
when: inventory_hostname in groups[item.group]
with_items:
- { name: sahara_api, group: sahara-api }
- { name: sahara_engine, group: sahara-engine }
- include: config.yml
- name: Check the configs
command: docker exec {{ item.name }} /usr/local/bin/kolla_set_configs --check
changed_when: false
failed_when: false
register: check_results
when: inventory_hostname in groups[item.group]
with_items:
- { name: sahara_api, group: sahara-api }
- { name: sahara_engine, group: sahara-engine }
# NOTE(jeffrey4l): when config_strategy == 'COPY_ALWAYS'
# and container env['KOLLA_CONFIG_STRATEGY'] == 'COPY_ONCE',
# just remove the container and start again
- name: Containers config strategy
kolla_docker:
name: "{{ item.name }}"
action: "get_container_env"
register: container_envs
when: inventory_hostname in groups[item.group]
with_items:
- { name: sahara_api, group: sahara-api }
- { name: sahara_engine, group: sahara-engine }
- name: Remove the containers
kolla_docker:
name: "{{ item[0]['name'] }}"
action: "remove_container"
register: remove_containers
when:
- inventory_hostname in groups[item[0]['group']]
- config_strategy == "COPY_ONCE" or item[1]['KOLLA_CONFIG_STRATEGY'] == 'COPY_ONCE'
- item[2]['rc'] == 1
with_together:
- [{ name: sahara_api, group: sahara-api },
{ name: sahara_engine, group: sahara-engine },]
- "{{ container_envs.results }}"
- "{{ check_results.results }}"
- include: start.yml
when: remove_containers.changed
- name: Restart containers
kolla_docker:
name: "{{ item[0]['name'] }}"
action: "restart_container"
when:
- inventory_hostname in groups[item[0]['group']]
- config_strategy == 'COPY_ALWAYS'
- item[1]['KOLLA_CONFIG_STRATEGY'] != 'COPY_ONCE'
- item[2]['rc'] == 1
with_together:
- [{ name: sahara_api, group: sahara-api },
{ name: sahara_engine, group: sahara-engine },]
- "{{ container_envs.results }}"
- "{{ check_results.results }}"

View File

@ -0,0 +1,2 @@
---
- include: "{{ action }}.yml"

View File

@ -0,0 +1,14 @@
---
- name: Pulling sahara-engine image
kolla_docker:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ sahara_engine_image_full }}"
when: inventory_hostname in groups['sahara-engine']
- name: Pulling sahara-api image
kolla_docker:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ sahara_api_image_full }}"
when: inventory_hostname in groups['sahara-api']

View File

@ -0,0 +1,5 @@
---
- include: do_reconfigure.yml
serial: "30%"
when: inventory_hostname in groups['sahara-api']
or inventory_hostname in groups['sahara-engine']

View File

@ -0,0 +1,40 @@
---
- name: Creating the Sahara service and endpoint
command: docker exec -t kolla_toolbox /usr/bin/ansible localhost
-m kolla_keystone_service
-a "service_name=sahara
service_type=data_processing
description='Sahara Data Processing'
endpoint_region={{ openstack_region_name }}
url='{{ item.url }}'
interface='{{ item.interface }}'
region_name={{ openstack_region_name }}
auth={{ '{{ openstack_sahara_auth }}' }}"
-e "{'openstack_sahara_auth':{{ openstack_sahara_auth }}}"
register: sahara_endpoint
changed_when: "{{ sahara_endpoint.stdout.find('localhost | SUCCESS => ') != -1 and (sahara_endpoint.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}"
until: sahara_endpoint.stdout.split()[2] == 'SUCCESS'
retries: 10
delay: 5
run_once: True
with_items:
- {'interface': 'admin', 'url': '{{ sahara_admin_endpoint }}'}
- {'interface': 'internal', 'url': '{{ sahara_internal_endpoint }}'}
- {'interface': 'public', 'url': '{{ sahara_public_endpoint }}'}
- name: Creating the Sahara project, user, and role
command: docker exec -t kolla_toolbox /usr/bin/ansible localhost
-m kolla_keystone_user
-a "project=service
user=sahara
password={{ sahara_keystone_password }}
role=admin
region_name={{ openstack_region_name }}
auth={{ '{{ openstack_sahara_auth }}' }}"
-e "{'openstack_sahara_auth':{{ openstack_sahara_auth }}}"
register: sahara_user
changed_when: "{{ sahara_user.stdout.find('localhost | SUCCESS => ') != -1 and (sahara_user.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}"
until: sahara_user.stdout.split()[2] == 'SUCCESS'
retries: 10
delay: 5
run_once: True

View File

@ -0,0 +1,24 @@
---
- name: Starting sahara-api container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
image: "{{ sahara_api_image_full }}"
name: "sahara_api"
volumes:
- "{{ node_config_directory }}/sahara-api/:{{ container_config_directory }}/:ro"
- "sahara:/var/lib/sahara/"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['sahara-api']
- name: Starting sahara-engine container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
image: "{{ sahara_engine_image_full }}"
name: "sahara_engine"
volumes:
- "{{ node_config_directory }}/sahara-engine/:{{ container_config_directory }}/:ro"
- "sahara:/var/lib/sahara/"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['sahara-engine']

View File

@ -0,0 +1,11 @@
{
"command": "sahara-api --config-file /etc/sahara/sahara.conf",
"config_files": [
{
"source": "{{ container_config_directory }}/sahara.conf",
"dest": "/etc/sahara/sahara.conf",
"owner": "sahara",
"perm": "0600"
}
]
}

View File

@ -0,0 +1,11 @@
{
"command": "sahara-engine --config-file /etc/sahara/sahara.conf",
"config_files": [
{
"source": "{{ container_config_directory }}/sahara.conf",
"dest": "/etc/sahara/sahara.conf",
"owner": "sahara",
"perm": "0600"
}
]
}

View File

@ -0,0 +1,45 @@
[DEFAULT]
debug = {{ sahara_logging_debug }}
log_dir = /var/log/kolla/sahara
port = {{ sahara_api_port }}
host = {{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}
transport_url = rabbit://{% for host in groups['rabbitmq'] %}{{ rabbitmq_user }}:{{ rabbitmq_password }}@{{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}:{{ rabbitmq_port }}{% if not loop.last %},{% endif %}{% endfor %}
use_neutron = True
api_workers = 2
use_floating_ips = False
use_namespaces = True
[database]
connection = mysql+pymysql://{{ sahara_database_user }}:{{ sahara_database_password }}@{{ sahara_database_address }}/{{ sahara_database_name }}
[keystone_authtoken]
auth_uri = {{ internal_protocol }}://{{ kolla_internal_fqdn }}:{{ keystone_public_port }}
project_domain_name = default
project_name = service
user_domain_name = default
username = {{ sahara_keystone_user }}
password = {{ sahara_keystone_password }}
auth_url = {{ admin_protocol }}://{{ kolla_internal_fqdn }}:{{ keystone_admin_port }}
auth_type = password
memcache_security_strategy = ENCRYPT
memcache_secret_key = {{ memcache_secret_key }}
{% if orchestration_engine == 'KUBERNETES' %}
memcache_servers = {{ memcached_servers }}
{% else %}
memcached_servers = {% for host in groups['memcached'] %}{{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}:{{ memcached_port }}{% if not loop.last %},{% endif %}{% endfor %}
{% endif %}
[service_credentials]
auth_url = {{ internal_protocol }}://{{ kolla_internal_fqdn }}:{{ keystone_public_port }}
region_name = {{ openstack_region_name }}
password = {{ sahara_keystone_password }}
username = {{ sahara_keystone_user }}
project_name = service
project_domain_id = default
user_domain_id = default
auth_type = password
[profiler]
enabled = False

View File

@ -198,6 +198,14 @@
tags: mistral,
when: enable_mistral | bool }
- hosts:
- sahara-api
- sahara-engine
roles:
- { role: sahara,
tags: sahara,
when: enable_sahara | bool }
- hosts:
- mongodb
roles:

View File

@ -47,6 +47,9 @@ cinder_keystone_password:
cloudkitty_database_password:
cloudkitty_keystone_password:
sahara_database_password:
sahara_keystone_password:
swift_keystone_password:
swift_hash_path_suffix:
swift_hash_path_prefix:

View File

@ -0,0 +1,3 @@
---
features:
- Implement Sahara ansible role