aboutsummaryrefslogtreecommitdiffstats
path: root/deploy/adapters/ansible
diff options
context:
space:
mode:
authorcarey.xu <carey.xuhan@huawei.com>2015-12-04 09:33:48 +0800
committercarey.xu <carey.xuhan@huawei.com>2015-12-08 19:36:47 +0800
commitf691dbc6f7b6d686012fce2f4f6ce59d4549d0fe (patch)
treee596b2a8e610a6b12bce4878cf2a3cdc0e929f20 /deploy/adapters/ansible
parent4d32ee565ecd829a2ec767cae6d8cd23df8e6263 (diff)
rabbitmq script refactor
JIRA: COMPASS-177 Change-Id: I66698ac27a974c9c375e8da9fcb91f49f89227ed Signed-off-by: carey.xu <carey.xuhan@huawei.com>
Diffstat (limited to 'deploy/adapters/ansible')
-rw-r--r--deploy/adapters/ansible/roles/ha/templates/haproxy.cfg13
-rw-r--r--deploy/adapters/ansible/roles/mq/tasks/main.yml7
-rw-r--r--deploy/adapters/ansible/roles/mq/tasks/rabbitmq.yml45
-rw-r--r--deploy/adapters/ansible/roles/mq/tasks/rabbitmq_cluster.yml22
-rw-r--r--deploy/adapters/ansible/roles/mq/tasks/rabbitmq_config.yml15
-rwxr-xr-xdeploy/adapters/ansible/roles/mq/tasks/rabbitmq_install.yml68
6 files changed, 102 insertions, 68 deletions
diff --git a/deploy/adapters/ansible/roles/ha/templates/haproxy.cfg b/deploy/adapters/ansible/roles/ha/templates/haproxy.cfg
index 3d76a5bc..0778bb13 100644
--- a/deploy/adapters/ansible/roles/ha/templates/haproxy.cfg
+++ b/deploy/adapters/ansible/roles/ha/templates/haproxy.cfg
@@ -38,6 +38,19 @@ listen proxy-mysql
{% endif %}
{% endfor %}
+listen proxy-rabbit
+ bind {{ internal_vip.ip }}:5672
+ bind {{ public_vip.ip }}:5672
+
+ option tcpka
+ option tcplog
+ timeout client 3h
+ timeout server 3h
+ balance source
+{% for host,ip in haproxy_hosts.items() %}
+ server {{ host }} {{ ip }}:5672 weight 1 check inter 2000 rise 2 fall 5
+{% endfor %}
+
listen proxy-glance_registry_cluster
bind {{ internal_vip.ip }}:9191
bind {{ public_vip.ip }}:9191
diff --git a/deploy/adapters/ansible/roles/mq/tasks/main.yml b/deploy/adapters/ansible/roles/mq/tasks/main.yml
index 47e41a25..84d4a94e 100644
--- a/deploy/adapters/ansible/roles/mq/tasks/main.yml
+++ b/deploy/adapters/ansible/roles/mq/tasks/main.yml
@@ -1,6 +1,7 @@
---
- include_vars: "{{ ansible_os_family }}.yml"
-- include: rabbitmq.yml
-#- include: rabbitmq_cluster.yml
-# when: HA_CLUSTER is defined
+- include: rabbitmq_install.yml
+
+- include: rabbitmq_config.yml
+ when: inventory_hostname == haproxy_hosts.keys()[0]
diff --git a/deploy/adapters/ansible/roles/mq/tasks/rabbitmq.yml b/deploy/adapters/ansible/roles/mq/tasks/rabbitmq.yml
deleted file mode 100644
index edfc8a7a..00000000
--- a/deploy/adapters/ansible/roles/mq/tasks/rabbitmq.yml
+++ /dev/null
@@ -1,45 +0,0 @@
----
-- name: create rabbitmq directory
- file: path=/etc/rabbitmq state=directory mode=0755
-
-- name: copy rabbitmq config file
- template: src=rabbitmq-env.conf dest=/etc/rabbitmq/rabbitmq-env.conf mode=0755
-
-- name: install rabbitmq-server
- action: "{{ ansible_pkg_mgr }} name=rabbitmq-server state=present"
- with_items: packages | union(packages_noarch)
-
-- name: stop rabbitmq-server
- service: name=rabbitmq-server
- state=stopped
-
-- name: update .erlang.cookie
- template: src=.erlang.cookie dest=/var/lib/rabbitmq/.erlang.cookie
- group=rabbitmq
- owner=rabbitmq
- mode=0400
- when: ERLANG_TOKEN is defined
-
-- name: start and enable rabbitmq-server
- service: name=rabbitmq-server
- state=started
- enabled=yes
-
-- name: generate mq service list
- shell: echo {{ item }} >> /opt/service
- with_items: services_noarch
-
-- name: modify rabbitmq password
- command: rabbitmqctl change_password guest {{ RABBIT_PASS }}
- when: "RABBIT_USER is defined and RABBIT_USER == 'guest'"
- ignore_errors: True
-
-- name: add rabbitmq user
- command: rabbitmqctl add_user {{ RABBIT_USER }} {{ RABBIT_PASS }}
- when: "RABBIT_USER is defined and RABBIT_USER != 'guest'"
- ignore_errors: True
-
-- name: set rabbitmq user permission
- command: rabbitmqctl set_permissions -p / {{ RABBIT_USER }} ".*" ".*" ".*"
- when: "RABBIT_USER is defined and RABBIT_USER != 'guest'"
-
diff --git a/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_cluster.yml b/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_cluster.yml
index fdc18a65..8b0ce9a9 100644
--- a/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_cluster.yml
+++ b/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_cluster.yml
@@ -1,27 +1,9 @@
---
- name: stop rabbitmq app
- command: rabbitmqctl stop_app
- run_once: True
-
-- name: rabbitmqctl reset
- command: rabbitmqctl reset
- run_once: True
-
-- name: stop rabbitmq
- shell: rabbitmqctl stop
-
-- name: set detach
- shell: rabbitmq-server -detached
+ shell: rabbitmqctl stop_app; sleep 3
- name: join cluster
- command: rabbitmqctl join_cluster rabbit@{{ item }}
- when: item != inventory_hostname and HA_CLUSTER[item] == ''
- with_items:
- groups['controller']
+ command: rabbitmqctl join_cluster rabbit@{{ haproxy_hosts.keys()[0] }}
- name: start rabbitmq app
command: rabbitmqctl start_app
-
-- name: set the HA policy
- rabbitmq_policy: name=ha-all pattern='^(?!amq\.).*' tags="ha-mode=all"
-
diff --git a/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_config.yml b/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_config.yml
new file mode 100644
index 00000000..5eeccd65
--- /dev/null
+++ b/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_config.yml
@@ -0,0 +1,15 @@
+---
+- name: remove default guest user is removed
+ rabbitmq_user:
+ user: guest
+ state: absent
+
+- name: add rabbitmq user
+ rabbitmq_user:
+ user='{{ RABBIT_USER }}'
+ password='{{ RABBIT_PASS }}'
+ vhost=/
+ configure_priv=.*
+ write_priv=.*
+ read_priv=.*
+ state=present
diff --git a/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_install.yml b/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_install.yml
new file mode 100755
index 00000000..559fa423
--- /dev/null
+++ b/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_install.yml
@@ -0,0 +1,68 @@
+---
+- name: create rabbitmq directory
+ file: path=/etc/rabbitmq state=directory mode=0755
+
+- name: disable auto start
+ copy:
+ content: "#!/bin/sh\nexit 101"
+ dest: "/usr/sbin/policy-rc.d"
+ mode: 0755
+ when: ansible_os_family == "Debian"
+
+- name: install rabbitmq-server
+ action: "{{ ansible_pkg_mgr }} name=rabbitmq-server state=present"
+ with_items: packages | union(packages_noarch)
+
+- name: enable auto start
+ file:
+ path=/usr/sbin/policy-rc.d
+ state=absent
+ when: ansible_os_family == "Debian"
+
+- name: make sure rabbitmq-server stopped
+ service:
+ name: rabbitmq-server
+ state: stopped
+ enabled: yes
+
+- name: replace cookie
+ copy:
+ content: "{{ ERLANG_TOKEN }}"
+ dest: /var/lib/rabbitmq/.erlang.cookie
+ mode: 0400
+ owner: rabbitmq
+ group: rabbitmq
+
+- name: replace config
+ copy:
+ content: "RABBITMQ_NODE_IP_ADDRESS={{ internal_ip }}"
+ dest: /etc/rabbitmq/rabbitmq-env.conf
+ mode: 0400
+ owner: rabbitmq
+ group: rabbitmq
+
+- name: set open file limit for rabbitmq
+ copy:
+ content: "ulimit -n 65536"
+ dest: /etc/default/rabbitmq-server
+ mode: 0400
+ owner: rabbitmq
+ group: rabbitmq
+
+- name: restart rabbitmq-server
+ service:
+ name: rabbitmq-server
+ state: restarted
+
+- name: enable queue mirroring
+ rabbitmq_policy:
+ name: "ha-all"
+ pattern: '^(?!amq\.).*'
+ tags: "ha-mode=all"
+
+- include: rabbitmq_cluster.yml
+ when: inventory_hostname != haproxy_hosts.keys()[0]
+
+- name: generate mq service list
+ shell: echo {{ item }} >> /opt/service
+ with_items: services_noarch