Ansible Rabbitmq support

Adds initial support for Rabbitmq in Ansible using the CONFIG_EXTERNAL methods.

Additionally, this refactors some of the Rabbitmq config script to allow for
reuse by CONFIG_EXTERNAL.

Partially Implements: blueprint ansible-service

Change-Id: I1765548f7e4f1258eb8a49e2a23242955f52655d
This commit is contained in:
Sam Yaple 2015-07-01 17:23:13 +00:00
parent efbfd7912b
commit c97ccd6a5f
17 changed files with 208 additions and 72 deletions

View File

@ -0,0 +1,22 @@
---
project_name: "rabbitmq"
####################
# Docker
####################
docker_message_broker_registry: "{{ docker_registry }}"
docker_message_broker_namespace: "{{ docker_namespace }}"
kolla_message_broker_base_distro: "{{ kolla_base_distro }}"
kolla_message_broker_install_type: "{{ kolla_install_type }}"
kolla_message_broker_container_name: "rabbitmq"
docker_message_broker_image: "{{ docker_message_broker_registry }}{{ docker_message_broker_namespace }}/{{ kolla_message_broker_base_distro }}-{{ kolla_message_broker_install_type }}-{{ kolla_message_broker_container_name }}"
docker_message_broker_tag: "{{ openstack_release }}"
docker_message_broker_image_full: "{{ docker_message_broker_image }}:{{ docker_message_broker_tag }}"
####################
# Message-Broker
####################
rabbitmq_user: "openstack"
rabbitmq_cluster_name: "openstack"

View File

@ -0,0 +1,37 @@
---
# TODO(SamYaple): Improve check with a custom docker module to check if alive
- name: Checking if a rabbitmq_data exists
command: docker inspect rabbitmq_data
register: exists
changed_when: False
failed_when: False
always_run: True
- include: ../../start.yml
vars:
container_command: "/bin/sleep infinity"
container_image: "{{ docker_message_broker_image_full }}"
container_name: "rabbitmq_data"
container_volumes:
- "/var/lib/rabbitmq/"
- include: ../../start.yml
vars:
container_detach: "False"
container_environment:
KOLLA_BOOTSTRAP:
KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
RABBITMQ_CLUSTER_COOKIE: "{{ rabbitmq_cluster_cookie }}"
container_image: "{{ docker_message_broker_image_full }}"
container_name: "rabbitmq_bootstrap"
container_volumes:
- "{{ node_config_directory }}/rabbitmq/:/opt/kolla/rabbitmq/:ro"
container_volumes_from:
- "rabbitmq_data"
when: exists.rc != 0
- name: Cleaning up boostrap container
docker:
image: "{{ docker_message_broker_image_full }}"
name: "rabbitmq_bootstrap"
state: "absent"

View File

@ -0,0 +1,16 @@
---
- name: Ensuring config directory exists
file:
path: "{{ node_config_directory }}/rabbitmq/"
state: "directory"
recurse: "yes"
- name: Copying over config(s)
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
with_items:
- { src: "roles/message-broker/templates/rabbitmq-env.conf.j2",
dest: "{{ node_config_directory }}/rabbitmq/rabbitmq-env.conf" }
- { src: "roles/message-broker/templates/rabbitmq.config.j2",
dest: "{{ node_config_directory }}/rabbitmq/rabbitmq.config" }

View File

@ -1,7 +1,6 @@
--- ---
- name: Bringing up rabbitmq service(s) - include: config.yml
docker_compose:
project_name: rabbitmq - include: bootstrap.yml
compose_file: "{{ koalla_directory }}/compose/rabbitmq.yml"
command: up - include: start.yml
no_recreate: true

View File

@ -0,0 +1,11 @@
---
- include: ../../start.yml
vars:
container_environment:
KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
container_image: "{{ docker_message_broker_image_full }}"
container_name: "rabbitmq"
container_volumes:
- "{{ node_config_directory }}/rabbitmq/:/opt/kolla/rabbitmq/:ro"
container_volumes_from:
- "rabbitmq_data"

View File

@ -0,0 +1 @@
RABBITMQ_NODENAME=rabbit

View File

@ -0,0 +1,9 @@
[
{rabbit, [
{cluster_nodes, [{% for host in groups['database'] %}'rabbit@{{ hostvars[host]['ansible_hostname'] }}'{% if not loop.last %},{% endif %}{% endfor %}]},
{default_user, <<"{{ rabbitmq_user }}">>},
{default_pass, <<"{{ rabbitmq_password }}">>}
]}
].
% EOF

View File

@ -13,7 +13,7 @@
docker: docker:
command: "{{ container_command | default(None) }}" command: "{{ container_command | default(None) }}"
detach: "{{ container_detach | default('True') }}" detach: "{{ container_detach | default('True') }}"
env: "{{ container_environment | default(None) }}" env: "{{ container_environment | default({}) }}"
docker_api_version: "{{ docker_api_version }}" docker_api_version: "{{ docker_api_version }}"
image: "{{ container_image }}" image: "{{ container_image }}"
insecure_registry: "{{ docker_insecure_registry }}" insecure_registry: "{{ docker_insecure_registry }}"

View File

@ -8,7 +8,7 @@ RUN yum -y install \
/usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_management /usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_management
COPY rabbitmq.config rabbitmq-env.conf /etc/rabbitmq/ COPY rabbitmq.config rabbitmq-env.conf /etc/rabbitmq/
COPY config-rabbit.sh /opt/kolla/config-rabbit.sh COPY config-rabbit.sh config-external.sh config-internal.sh /opt/kolla/
COPY start.sh /start.sh COPY start.sh /start.sh
CMD ["/start.sh"] CMD ["/start.sh"]

View File

@ -0,0 +1 @@
../../../common/rabbitmq/config-external.sh

View File

@ -0,0 +1 @@
../../../common/rabbitmq/config-internal.sh

View File

@ -1,57 +0,0 @@
#!/bin/bash
. /opt/kolla/kolla-common.sh
check_required_vars RABBITMQ_PASS RABBITMQ_USER
RABBITMQ_CLUSTER_CONFIGURATION=""
function configure_files {
sed -i '
s|@RABBITMQ_USER@|'"$RABBITMQ_USER"'|g
s|@RABBITMQ_PASS@|'"$RABBITMQ_PASS"'|g
s|@RABBITMQ_CLUSTER_CONFIGURATION@|'"$RABBITMQ_CLUSTER_CONFIGURATION"'|g
' /etc/rabbitmq/rabbitmq.config
sed -i '
s|@RABBITMQ_LOG_BASE@|'"$RABBITMQ_LOG_BASE"'|g
' /etc/rabbitmq/rabbitmq-env.conf
}
function configure_cluster {
check_required_vars RABBITMQ_CLUSTER_COOKIE RABBITMQ_CLUSTER_NODES
echo "${RABBITMQ_CLUSTER_COOKIE}" > /var/lib/rabbitmq/.erlang.cookie
chown rabbitmq /var/lib/rabbitmq/.erlang.cookie
chmod 700 /var/lib/rabbitmq/.erlang.cookie
HOSTNAME=""
IP_ADDRESS=""
DELIMETER=""
for node in ${RABBITMQ_CLUSTER_NODES}; do
HOSTNAME=`echo ${node} | cut -d'@' -f1`
IP_ADDRESS=`echo ${node} | cut -d'@' -f2`
CLUSTER_NODES="${CLUSTER_NODES}${DELIMETER}rabbit@${HOSTNAME}"
echo "${IP_ADDRESS} ${HOSTNAME}" >> /etc/hosts
DELIMETER=","
done
RABBITMQ_CLUSTER_CONFIGURATION="{cluster_nodes, {[$CLUSTER_NODES], disc}},"
}
function configure_rabbit {
if [ "$RABBITMQ_CLUSTER_NODES" ] && [ "$RABBITMQ_CLUSTER_COOKIE" ]; then
configure_cluster
elif [ "$RABBITMQ_SERVICE_HOST" ]; then
# work around:
# https://bugs.launchpad.net/ubuntu/+source/rabbitmq-server/+bug/653405
echo "${RABBITMQ_SERVICE_HOST} `/usr/bin/hostname -s`" > /etc/hosts
else
echo "You need RABBITMQ_SERVICE_HOST or RABBITMQ_CLUSTER_NODES & " \
" RABBITMQ_CLUSTER_COOKIES variables"
exit 1
fi
configure_files
}

View File

@ -0,0 +1 @@
../../../common/rabbitmq/config-rabbit.sh

View File

@ -0,0 +1,14 @@
#!/bin/bash
# Cluster configuration
if [[ -f /opt/kolla/rabbitmq/rabbitmq.config ]]; then
cp -af /opt/kolla/rabbitmq/rabbitmq.config /etc/rabbitmq/rabbitmq.config
chown rabbitmq: /etc/rabbitmq/rabbitmq.config
chmod 0600 /etc/rabbitmq/rabbitmq.config
fi
if [[ -f /opt/kolla/rabbitmq/rabbitmq-env.conf ]]; then
cp -af /opt/kolla/rabbitmq/rabbitmq-env.conf /etc/rabbitmq/rabbitmq-env.conf
chown rabbitmq: /etc/rabbitmq/rabbitmq-env.conf
chmod 0600 /etc/rabbitmq/rabbitmq-env.conf
fi

View File

@ -0,0 +1,10 @@
#!/bin/bash
. /opt/kolla/kolla-common.sh
. /opt/kolla/config-rabbit.sh
check_required_vars RABBITMQ_PASS RABBITMQ_USER
configure_rabbit
exec /usr/sbin/rabbitmq-server

View File

@ -0,0 +1,55 @@
#!/bin/bash
RABBITMQ_CLUSTER_CONFIGURATION=""
function configure_files {
sed -i '
s|@RABBITMQ_USER@|'"$RABBITMQ_USER"'|g
s|@RABBITMQ_PASS@|'"$RABBITMQ_PASS"'|g
s|@RABBITMQ_CLUSTER_CONFIGURATION@|'"$RABBITMQ_CLUSTER_CONFIGURATION"'|g
' /etc/rabbitmq/rabbitmq.config
sed -i '
s|@RABBITMQ_LOG_BASE@|'"$RABBITMQ_LOG_BASE"'|g
' /etc/rabbitmq/rabbitmq-env.conf
}
function set_rabbitmq_cookie {
echo "${RABBITMQ_CLUSTER_COOKIE}" > /var/lib/rabbitmq/.erlang.cookie
chown rabbitmq: /var/lib/rabbitmq/.erlang.cookie
chmod 400 /var/lib/rabbitmq/.erlang.cookie
}
function configure_cluster {
check_required_vars RABBITMQ_CLUSTER_COOKIE RABBITMQ_CLUSTER_NODES
set_rabbitmq_cookie
HOSTNAME=""
IP_ADDRESS=""
DELIMETER=""
for node in ${RABBITMQ_CLUSTER_NODES}; do
HOSTNAME=`echo ${node} | cut -d'@' -f1`
IP_ADDRESS=`echo ${node} | cut -d'@' -f2`
CLUSTER_NODES="${CLUSTER_NODES}${DELIMETER}rabbit@${HOSTNAME}"
echo "${IP_ADDRESS} ${HOSTNAME}" >> /etc/hosts
DELIMETER=","
done
RABBITMQ_CLUSTER_CONFIGURATION="{cluster_nodes, {[$CLUSTER_NODES], disc}},"
}
function configure_rabbit {
if [ "$RABBITMQ_CLUSTER_NODES" ] && [ "$RABBITMQ_CLUSTER_COOKIE" ]; then
configure_cluster
elif [ "$RABBITMQ_SERVICE_HOST" ]; then
# work around:
# https://bugs.launchpad.net/ubuntu/+source/rabbitmq-server/+bug/653405
echo "${RABBITMQ_SERVICE_HOST} `/usr/bin/hostname -s`" > /etc/hosts
else
echo "You need RABBITMQ_SERVICE_HOST or RABBITMQ_CLUSTER_NODES & " \
" RABBITMQ_CLUSTER_COOKIES variables"
exit 1
fi
configure_files
}

View File

@ -1,7 +1,23 @@
#!/bin/bash #!/bin/bash
. /opt/kolla/config-rabbit.sh set -o errexit
configure_rabbit CMD="/usr/sbin/rabbitmq-server"
ARGS=""
exec /usr/sbin/rabbitmq-server # loading common functions
source /opt/kolla/kolla-common.sh
# config-internal script exec out of this function, it does not return here
set_configs
# loading functions
source /opt/kolla/config-rabbit.sh
# This catches all cases of the BOOTSTRAP variable being set, including empty
if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then
set_rabbitmq_cookie
exit 0
fi
$CMD $ARGS

View File

@ -1,7 +1,6 @@
--- ---
# TODO: SamYaple # TODO(SamYaple): This file should have generated values by default. Propose
# This file should have generated values by default. Propose Ansible vault for # Ansible vault for locking down the secrets properly.
# locking down the secrets properly.
################### ###################
@ -26,4 +25,5 @@ keystone_database_password: "password"
#################### ####################
# RabbitMQ options # RabbitMQ options
#################### ####################
rabbitmq_password: "password"
rabbitmq_cluster_cookie: "password"