Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ansible/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ cinder_api_port: "8776"
# Trove
trove_api_port: "8779"

# Zaqar
zaqar_port: "8889"
zaqar_mongodb_nodes: ""
mongo_primary_node: ""

# Neutron
neutron_api_port: "9696"

# RabbitMQ
rabbit_port: "5673"

# MongoDB
mongo_port: "27017"

# Docker registry
eayunstack_registry_port: "5010"
docker_registry: "{{ master_ip }}:{{eayunstack_registry_port}}"
Expand Down
2 changes: 2 additions & 0 deletions ansible/passwords.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
trove_database_password:
trove_keystone_password:
zaqar_database_password:
zaqar_keystone_password:
4 changes: 4 additions & 0 deletions ansible/roles/fuel/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ eayunstack_docker_images:
image_name: "{{ eayunstack_docker_prefix }}/trove-db-sync"
file_name: "eayunstack_trove_db_sync.latest"
push: "True"
zaqar_server:
image_name: "{{ eayunstack_docker_prefix }}/zaqar-base"
file_name: "eayunstack_zaqar_server.latest"
push: "True"

eayunstack_registry_diretory: "/var/lib/eayunstack-registry"
eayunstack_registry_port: "5010"
Expand Down
1 change: 1 addition & 0 deletions ansible/roles/haproxy/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
trove_haproxy_order: "300"
zaqar_haproxy_order: "301"
6 changes: 6 additions & 0 deletions ansible/roles/haproxy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
src: "trove-api-haproxy.conf.j2"
dest: "{{ haproxy_config_base }}/{{ trove_haproxy_order }}-trove-api.cfg"
notify: Reload HAProxy

- name: Copying over zaqar haproxy conf files
template:
src: "zaqar-server-haproxy.conf.j2"
dest: "{{ haproxy_config_base }}/{{ zaqar_haproxy_order }}-zaqar-server.cfg"
notify: Reload HAProxy
10 changes: 10 additions & 0 deletions ansible/roles/haproxy/templates/zaqar-server-haproxy.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
listen zaqar-server
bind {{ management_vip }}:{{ zaqar_port }}
bind {{ public_vip }}:{{ zaqar_port }}
mode http
option httpchk
option httplog
option httpclose
{% for host in groups['controller'] %}
server {{hostvars[host]['ansible_hostname']}} {{ hostvars[host]['ansible_' + hostvars[host]['network_scheme']['roles']['management']|replace('-', '_')]['ipv4']['address'] }}:{{zaqar_port}} check inter 10s fastinter 2s downinter 3s rise 3 fall 3
{% endfor %}
44 changes: 44 additions & 0 deletions ansible/roles/zaqar/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
project_name: zaqar

zaqar_sys_uid: 971
zaqar_sys_gid: 971
zaqar_sys_homedir: "/var/lib/zaqar"

zaqar_services:
zaqar-server:
container_name: zaqar_server
image: "{{ zaqar_base_image }}"
volumes:
- "{{ zaqar_sys_homedir }}:{{ zaqar_sys_homedir }}"
- "{{ eayunstack_config_base }}/{{ project_name }}:{{ zaqar_config_diretory }}:ro"
- "{{ timezone_path }}:/etc/localtime:ro"
- "{{ eayunstack_log_base }}/{{ project_name }}:{{ zaqar_log_directory }}"

zaqar_config_diretory: /etc/zaqar
zaqar_config_files:
zaqar.conf:
handlers:
- Restart zaqar-server container
uwsgi.conf:
handlers:
- Restart zaqar-server container

zaqar_public_endpoint: "http://{{ public_vip }}:{{ zaqar_port }}"
zaqar_internal_endpoint: "http://{{ management_vip }}:{{ zaqar_port }}"
zaqar_admin_endpoint: "http://{{ management_vip }}:{{ zaqar_port }}"

zaqar_endpoints:
publicurl: "{{ zaqar_public_endpoint }}"
internalurl: "{{ zaqar_internal_endpoint }}"
adminurl: "{{ zaqar_admin_endpoint }}"

zaqar_log_directory: "/var/log/{{ project_name }}"
zaqar_logging_debug: "True"
zaqar_mongodb_uri: "mongodb+replicaSet://zaqar:{{ zaqar_database_password }}@{{ zaqar_mongodb_nodes }}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zaqar_mongodb_nodes 这个看起来只能执行 ansible-play 时通过命令直接赋值了?

那 zaqar_database_password 看起来稍微麻烦一点,这个变量是 genpwd.py 生成写到 eayunstack_passwords_file 里去的,但是实际目前没有创建 MongoDB 用户的 task (后面被注释了?),所以目前只能是 genpwd.py 之后,手动去创建?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯 这个目前还没做


zaqar_base_image: "{{ docker_registry }}/{{ eayunstack_docker_prefix }}/zaqar-base"

zaqar_logrotate_conf:
rotate: "4"
minsize: "30M"
49 changes: 49 additions & 0 deletions ansible/roles/zaqar/files/logging.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[loggers]
Copy link
Copy Markdown
Contributor

@zhaochao zhaochao Dec 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logging.conf 这个文件稍微研究了下,没找到是哪里用到了,所以怀疑实际上只有 zaqar.conf 里的 log_file 起作用?

另外之前有一个 commit 64a6c47 ,由于目前 docker 版本较低,不能保留 stderr 日志,所以也需要改一下。(如果是 logging.conf 起作用的话,需要改这个文件,不然应该是和 Trove 之一样的直接改 zaqar.conf ) 。

keys=root,server,combined

[formatters]
keys=normal,normal_with_name,debug

[handlers]
keys=production,file,devel

[logger_root]
level=NOTSET
handlers=devel

[logger_server]
level=DEBUG
handlers=devel
qualname=zaqar-server

[logger_combined]
level=DEBUG
handlers=devel
qualname=zaqar-combined

[handler_production]
class=handlers.SysLogHandler
level=ERROR
formatter=normal_with_name
args=(('localhost', handlers.SYSLOG_UDP_PORT), handlers.SysLogHandler.LOG_USER)

[handler_file]
class=FileHandler
level=DEBUG
formatter=normal_with_name
args=('zaqar.log', 'w')

[handler_devel]
class=StreamHandler
level=NOTSET
formatter=debug
args=(sys.stdout,)

[formatter_normal]
format=%(asctime)s %(levelname)s %(message)s

[formatter_normal_with_name]
format=(%(name)s): %(asctime)s %(levelname)s %(message)s

[formatter_debug]
format=(%(name)s): %(asctime)s %(levelname)s %(module)s %(funcName)s %(message)s
61 changes: 61 additions & 0 deletions ansible/roles/zaqar/files/policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"context_is_admin": "role:admin",
"admin_or_owner": "is_admin:True or project_id:%(project_id)s",
"default": "rule:admin_or_owner",

"queues:get_all": "",
"queues:create": "",
"queues:get": "",
"queues:delete": "",
"queues:update": "",
"queues:stats": "",
"queues:share": "",
"queues:purge": "",

"topics:get_all": "",
"topics:create": "",
"topics:get": "",
"topics:delete": "",
"topics:update": "",

"monitors:get_all": "",
"monitors:get": "",

"messages:publish": "",
"messages:consume": "",
"messages:get_all": "",
"messages:create": "",
"messages:get": "",
"messages:delete": "",
"messages:delete_all": "",
"messages:consume_delete": "",
"messages:consume_delete_all": "",

"claims:get_all": "",
"claims:create": "",
"claims:get": "",
"claims:delete": "",
"claims:update": "",

"subscription:get_all": "",
"subscription:create": "",
"subscription:get": "",
"subscription:delete": "",
"subscription:update": "",
"subscription:confirm": "",

"pools:get_all": "rule:context_is_admin",
"pools:create": "rule:context_is_admin",
"pools:get": "rule:context_is_admin",
"pools:delete": "rule:context_is_admin",
"pools:update": "rule:context_is_admin",

"flavors:get_all": "",
"flavors:create": "rule:context_is_admin",
"flavors:get": "",
"flavors:delete": "rule:context_is_admin",
"flavors:update": "rule:context_is_admin",

"ping:get": "",
"health:get": "rule:context_is_admin"
}
19 changes: 19 additions & 0 deletions ansible/roles/zaqar/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Restart zaqar-server container
vars:
service_name: "zaqar-server"
service: "{{ zaqar_services[service_name] }}"
zaqar_conf: "{{ zaqar_confs.results|selectattr('item.key', 'match', 'zaqar.conf')|first }}"
uwsgi_conf: "{{ zaqar_confs.results|selectattr('item.key', 'match', 'uwsgi.conf')|first }}"
zaqar_server_container: "{{ check_zaqar_containers.results|selectattr('item.key', 'match', service_name)|first }}"
kolla_docker:
action: "recreate_or_restart_container"
name: "{{ service.container_name }}"
image: "{{ service.image }}"
volumes: "{{ service.volumes }}"
environment:
DAEMON: "zaqar-server"
restart_policy: "{{ docker_restart_policy }}"
when: zaqar_conf.changed | bool
or uwsgi_conf.changed | bool
or zaqar_server_container.changed | bool
72 changes: 72 additions & 0 deletions ansible/roles/zaqar/tasks/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
- name: Ensuring system group exist
group:
name: zaqar
gid: "{{ zaqar_sys_gid }}"

- name: Ensuring system user exist
user:
name: zaqar
comment: "zaqar Daemons"
uid: "{{ zaqar_sys_uid }}"
group: zaqar
groups: zaqar
home: "{{ zaqar_sys_homedir }}"
shell: "/sbin/nologin"

- name: Ensuring config directory exist
file:
path: "{{ eayunstack_config_base }}/{{ project_name }}"
state: "directory"
recurse: yes

- name: Ensuring log directory exist
file:
path: "{{ eayunstack_log_base }}/{{ project_name }}"
state: "directory"
owner: zaqar

- name: Copy policy.json
copy:
src: policy.json
dest: "{{ eayunstack_config_base }}/{{ project_name }}/"

- name: Copy logging.conf
copy:
src: logging.conf
dest: "{{ eayunstack_config_base }}/{{ project_name }}/"

- name: Copy zaqar-logrotate config
template:
src: zaqar-logrotate.conf.j2
dest: "/etc/logrotate.d/eayunstack-docker-{{ project_name }}"

- name: Copying over zaqar conf files
template:
src: "{{ item.key }}.j2"
dest: "{{ eayunstack_config_base }}/{{ project_name }}/{{ item.key }}"
register: zaqar_confs
with_dict: "{{ zaqar_config_files }}"
notify: "{{ item.value.handlers | default([]) }}"

- name: Check zaqar containers
kolla_docker:
action: "compare_container"
name: "{{ item.value.container_name }}"
image: "{{ item.value.image }}"
volumes: "{{ item.value.volumes }}"
restart_policy: "{{ docker_restart_policy }}"
with_dict: "{{ zaqar_services }}"
register: check_zaqar_containers
notify:
- "Restart {{ item.key }} container"

- name: Ensuring iptables for zaqar
iptables:
action: insert
chain: INPUT
protocol: tcp
match: multiport
destination_port: "{{ zaqar_port }}"
jump: ACCEPT
notify: "Save iptables rules"
46 changes: 46 additions & 0 deletions ansible/roles/zaqar/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
- name: ensure zaqar tenant, user
run_once: True
keystone:
region_name: "{{ keystone_region }}"
endpoint: "{{ keystone_admin_endpoint_v3 }}"
token: "{{ keystone.admin_token }}"
command: "{{ item.command }}"
user_name: "zaqar"
password: "{{ zaqar_keystone_password }}"
project_name: "{{ item.tenant | default(None) }}"
role_name: "{{ item.role | default(None) }}"
service_name: "{{ item.service_name | default(None) }}"
service_type: "{{ item.service_type | default(None) }}"
description: "{{ item.description | default(None) }}"
with_items:
- { command: 'ensure_user' }
- { command: 'ensure_user_role', tenant: 'services', role: 'admin' }
- { command: 'ensure_service', service_name: 'zaqar', service_type: 'messaging', description: 'Zaqar Messaging Service' }

- name: ensure zaqar endpoint
run_once: True
keystone_v2_endpoint:
region_name: "{{ keystone_region }}"
endpoint: "{{ keystone_admin_endpoint_v2 }}"
token: "{{ keystone.admin_token }}"
service_name: "zaqar"
service_type: "messaging"
endpoint_dict: "{{ zaqar_endpoints }}"

#- name: Creating zaqar mongodb user and setting permissions
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释部份需要保留的话,要说明一下原因,不然就直接去掉了。

# mongodb_user:
# login_password: "{{ ceilometer.db_password }}"
# login_user: admin
# login_host: "{{ mongo_primary_node }}"
# database: admin
# name: zaqar
# password: "{{ zaqar_database_password }}"
# roles: root
# state: present


- include: pull.yml

- include: config.yml


6 changes: 6 additions & 0 deletions ansible/roles/zaqar/tasks/pull.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Pulling zaqar images
kolla_docker:
action: "pull_image"
image: "{{ zaqar_base_image }}"

7 changes: 7 additions & 0 deletions ansible/roles/zaqar/templates/uwsgi.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[uwsgi]
strict = true
http = :{{ zaqar_port }}
processes = 32
threads = 4
wsgi-file = /usr/lib/python2.7/site-packages/zaqar/transport/wsgi/app.py
callable = app
8 changes: 8 additions & 0 deletions ansible/roles/zaqar/templates/zaqar-logrotate.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{ eayunstack_log_base }}/{{ project_name}}/*.log {
weekly
rotate {{ zaqar_logrotate_conf.rotate }}
minsize {{ zaqar_logrotate_conf.minsize }}
compress
missingok
notifempty
}
10 changes: 10 additions & 0 deletions ansible/roles/zaqar/templates/zaqar-server-haproxy.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
listen zaqar-server
bind {{ management_vip }}:{{ zaqar_port }}
bind {{ public_vip }}:{{ zaqar_port }}
mode http
option httpchk
option httplog
option httpclose
{% for host in groups['controller'] %}
server {{hostvars[host]['ansible_hostname']}} {{ hostvars[host]['ansible_' + hostvars[host]['network_scheme']['roles']['management']|replace('-', '_')]['ipv4']['address'] }}:{{zaqar_port}} check inter 10s fastinter 2s downinter 3s rise 3 fall 3
{% endfor %}
Loading