Add keepalived to ansible
Adds the needed ansible bits to support keepalived Closes-Bug: #1479934 Change-Id: Iace29b23a0e923b1f5dc9a4f5bc0f88afce3ae62 Partially-Implements: blueprint ansible-service
This commit is contained in:
parent
731d5205cb
commit
ab9f652113
@ -14,3 +14,14 @@ kolla_haproxy_container_name: "haproxy"
|
||||
docker_haproxy_image: "{{ docker_haproxy_registry }}{{ docker_haproxy_namespace }}/{{ kolla_haproxy_base_distro }}-{{ kolla_haproxy_install_type }}-{{ kolla_haproxy_container_name }}"
|
||||
docker_haproxy_tag: "{{ openstack_release }}"
|
||||
docker_haproxy_image_full: "{{ docker_haproxy_image }}:{{ docker_haproxy_tag }}"
|
||||
|
||||
|
||||
docker_keepalived_registry: "{{ docker_registry }}"
|
||||
docker_keepalived_namespace: "{{ docker_namespace }}"
|
||||
kolla_keepalived_base_distro: "{{ kolla_base_distro }}"
|
||||
kolla_keepalived_install_type: "{{ kolla_install_type }}"
|
||||
kolla_keepalived_container_name: "keepalived"
|
||||
|
||||
docker_keepalived_image: "{{ docker_keepalived_registry }}{{ docker_keepalived_namespace }}/{{ kolla_keepalived_base_distro }}-{{ kolla_keepalived_install_type }}-{{ kolla_keepalived_container_name }}"
|
||||
docker_keepalived_tag: "{{ openstack_release }}"
|
||||
docker_keepalived_image_full: "{{ docker_keepalived_image }}:{{ docker_keepalived_tag }}"
|
||||
|
@ -12,3 +12,14 @@
|
||||
|
||||
- name: Allowing non-local IP binding
|
||||
sysctl: name="net.ipv4.ip_nonlocal_bind" value=1 sysctl_set=yes
|
||||
|
||||
- name: Ensuring config directory exists
|
||||
file:
|
||||
path: "{{ node_config_directory }}/keepalived/"
|
||||
state: "directory"
|
||||
recurse: "yes"
|
||||
|
||||
- name: Copying over config(s)
|
||||
template:
|
||||
src: "keepalived.conf.j2"
|
||||
dest: "{{ node_config_directory }}/keepalived/keepalived.conf"
|
||||
|
@ -1,4 +1,14 @@
|
||||
---
|
||||
- include: ../../start.yml
|
||||
vars:
|
||||
container_image: "{{ docker_keepalived_image_full }}"
|
||||
container_name: "keepalived"
|
||||
container_privileged: "True"
|
||||
container_volumes:
|
||||
- "{{ node_config_directory }}/keepalived/:/opt/kolla/keepalived/:ro"
|
||||
container_environment:
|
||||
KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
|
||||
|
||||
- include: ../../start.yml
|
||||
vars:
|
||||
container_image: "{{ docker_haproxy_image_full }}"
|
||||
|
19
ansible/roles/haproxy/templates/keepalived.conf.j2
Normal file
19
ansible/roles/haproxy/templates/keepalived.conf.j2
Normal file
@ -0,0 +1,19 @@
|
||||
vrrp_script check_alive {
|
||||
script "/check_alive.sh"
|
||||
interval 2
|
||||
weight -10
|
||||
}
|
||||
|
||||
vrrp_instance Floating {
|
||||
state MASTER
|
||||
interface {{ api_interface }}
|
||||
virtual_router_id 51
|
||||
priority {{ groups['database'].index(inventory_hostname) }}
|
||||
advert_int 1
|
||||
virtual_ipaddress {
|
||||
{{ kolla_internal_address }}
|
||||
}
|
||||
track_script {
|
||||
check_alive
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ RUN yum -y install \
|
||||
&& yum clean all
|
||||
|
||||
COPY keepalived.conf /etc/keepalived/
|
||||
|
||||
COPY start.sh check_alive.sh /
|
||||
COPY config-internal.sh config-external.sh /opt/kolla/
|
||||
|
||||
CMD ["/start.sh"]
|
||||
|
1
docker/centos/binary/keepalived/config-external.sh
Symbolic link
1
docker/centos/binary/keepalived/config-external.sh
Symbolic link
@ -0,0 +1 @@
|
||||
../../../common/keepalived/config-external.sh
|
1
docker/centos/binary/keepalived/config-internal.sh
Symbolic link
1
docker/centos/binary/keepalived/config-internal.sh
Symbolic link
@ -0,0 +1 @@
|
||||
../../../common/keepalived/config-internal.sh
|
11
docker/common/keepalived/config-external.sh
Executable file
11
docker/common/keepalived/config-external.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
SOURCE="/opt/kolla/keepalived/keepalived.conf"
|
||||
TARGET="/etc/keepalived/keepalived.conf"
|
||||
OWNER="root"
|
||||
|
||||
if [[ -f "$SOURCE" ]]; then
|
||||
rm $TARGET
|
||||
cp $SOURCE $TARGET
|
||||
chown ${OWNER}: $TARGET
|
||||
chmod 0644 $TARGET
|
||||
fi
|
31
docker/common/keepalived/config-internal.sh
Executable file
31
docker/common/keepalived/config-internal.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
. /opt/kolla/kolla-common.sh
|
||||
|
||||
check_required_vars KEEPALIVED_HOST_PRIORITIES \
|
||||
PUBLIC_INTERFACE \
|
||||
PUBLIC_IP
|
||||
|
||||
MY_HOSTNAME=`hostname`
|
||||
|
||||
# here we unpack KEEPALIVED_HOST_PRIORITIES hostname:priority pairs and match
|
||||
# them with current hostname, if it's there
|
||||
for i in ${KEEPALIVED_HOST_PRIORITIES//,/ }; do
|
||||
HOST_PRIORITY=(${i//:/ })
|
||||
if [ "$MY_HOSTNAME" == "${HOST_PRIORITY[0]}" ]; then
|
||||
KEEPALIVED_PRIORITY=${HOST_PRIORITY[1]}
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$KEEPALIVED_PRIORITY" ]; then
|
||||
echo "ERROR: missing hostname in KEEPALIVED_HOST_PRIORITIES: $MY_HOSTNAME" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sed -i '
|
||||
s|@PUBLIC_INTERFACE@|'$PUBLIC_INTERFACE'|g
|
||||
s|@PUBLIC_IP@|'$PUBLIC_IP'|g
|
||||
s|@KEEPALIVED_PRIORITY@|'$KEEPALIVED_PRIORITY'|g
|
||||
' /etc/keepalived/keepalived.conf
|
||||
|
||||
exec /usr/sbin/keepalived -nld -p /run/keepalived.pid
|
@ -1,31 +1,13 @@
|
||||
#!/bin/bash
|
||||
set -o errexit
|
||||
|
||||
. /opt/kolla/kolla-common.sh
|
||||
CMD="/usr/sbin/keepalived"
|
||||
ARGS="-nld -p /run/keepalived.pid"
|
||||
|
||||
check_required_vars KEEPALIVED_HOST_PRIORITIES \
|
||||
PUBLIC_INTERFACE \
|
||||
PUBLIC_IP
|
||||
# Loading common functions.
|
||||
source /opt/kolla/kolla-common.sh
|
||||
|
||||
MY_HOSTNAME=`hostname`
|
||||
# Config-internal script exec out of this function, it does not return here.
|
||||
set_configs
|
||||
|
||||
# here we unpack KEEPALIVED_HOST_PRIORITIES hostname:priority pairs and match
|
||||
# them with current hostname, if it's there
|
||||
for i in ${KEEPALIVED_HOST_PRIORITIES//,/ }; do
|
||||
HOST_PRIORITY=(${i//:/ })
|
||||
if [ "$MY_HOSTNAME" == "${HOST_PRIORITY[0]}" ]; then
|
||||
KEEPALIVED_PRIORITY=${HOST_PRIORITY[1]}
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$KEEPALIVED_PRIORITY" ]; then
|
||||
echo "ERROR: missing hostname in KEEPALIVED_HOST_PRIORITIES: $MY_HOSTNAME" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sed -i '
|
||||
s|@PUBLIC_INTERFACE@|'$PUBLIC_INTERFACE'|g
|
||||
s|@PUBLIC_IP@|'$PUBLIC_IP'|g
|
||||
s|@KEEPALIVED_PRIORITY@|'$KEEPALIVED_PRIORITY'|g
|
||||
' /etc/keepalived/keepalived.conf
|
||||
|
||||
exec /usr/sbin/keepalived -nld -p /run/keepalived.pid
|
||||
exec $CMD $ARGS
|
||||
|
Loading…
Reference in New Issue
Block a user