Add haproxy playbooks
This commit is contained in:
parent
bee1a9627c
commit
8678ea4f6a
6 changed files with 138 additions and 1 deletions
40
haproxy/files/haproxy_config.j2
Normal file
40
haproxy/files/haproxy_config.j2
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
global
|
||||||
|
log 127.0.0.1 local2
|
||||||
|
|
||||||
|
maxconn 4000
|
||||||
|
user haproxy
|
||||||
|
group haproxy
|
||||||
|
daemon
|
||||||
|
|
||||||
|
stats socket /var/lib/haproxy/stats
|
||||||
|
|
||||||
|
defaults
|
||||||
|
mode http
|
||||||
|
log global
|
||||||
|
timeout queue 1m
|
||||||
|
timeout connect 10s
|
||||||
|
timeout client 5m
|
||||||
|
timeout server 5m
|
||||||
|
maxconn 3000
|
||||||
|
|
||||||
|
frontend ssh
|
||||||
|
mode tcp
|
||||||
|
|
||||||
|
bind {{ IPV4 }}:22
|
||||||
|
|
||||||
|
default_backend host-ssh
|
||||||
|
|
||||||
|
frontend http
|
||||||
|
mode tcp
|
||||||
|
bind {{ IPV4 }}:80
|
||||||
|
|
||||||
|
default_backend host-http
|
||||||
|
|
||||||
|
backend host-ssh
|
||||||
|
mode tcp
|
||||||
|
|
||||||
|
server localhost 127.0.0.1
|
||||||
|
|
||||||
|
backend host-http
|
||||||
|
mode tcp
|
||||||
|
server localhost 127.0.0.1
|
54
haproxy/files/haproxy_rcscript.initd.j2
Normal file
54
haproxy/files/haproxy_rcscript.initd.j2
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
#!/sbin/openrc-run
|
||||||
|
# Copyright 1999-2011 Gentoo Foundation
|
||||||
|
# Distributed under the terms of the GNU General Public License v2
|
||||||
|
# $Header: /var/cvsroot/gentoo-x86/net-proxy/haproxy/files/haproxy.initd-r1,v 1.2 2011/12/04 10:32:32 swegener Exp $
|
||||||
|
|
||||||
|
extra_commands="checkconfig"
|
||||||
|
extra_started_commands="reload"
|
||||||
|
command=/usr/sbin/haproxy
|
||||||
|
|
||||||
|
CONF=${HAPROXY_CONF:-/etc/haproxy/${SVCNAME}.cfg}
|
||||||
|
CONF_DIR=${HAPROXY_CONF_DIR:-{{ CONF_DIR }}}
|
||||||
|
PIDFILE=/var/run/${SVCNAME}.pid
|
||||||
|
|
||||||
|
depend() {
|
||||||
|
need net
|
||||||
|
after firewall
|
||||||
|
use dns logger
|
||||||
|
}
|
||||||
|
|
||||||
|
checkconfig() {
|
||||||
|
if [ ! -f "${CONF}" ] && [ ! -d "${CONF}" ]; then
|
||||||
|
eerror "${CONF} does not exist!"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
ebegin "Checking ${CONF}"
|
||||||
|
$command -q -c -f "${CONF}"
|
||||||
|
eend $?
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
ebegin "Starting ${SVCNAME}"
|
||||||
|
start-stop-daemon --pidfile "${PIDFILE}" --exec $command \
|
||||||
|
--start -- -D -p "${PIDFILE}" -f "${CONF}" -f "${CONF_DIR}"
|
||||||
|
eend $?
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
ebegin "Stopping ${SVCNAME}"
|
||||||
|
|
||||||
|
if [ "${RC_CMD}" = "restart" ]; then
|
||||||
|
checkconfig || return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
start-stop-daemon --stop --pidfile "${PIDFILE}"
|
||||||
|
eend $?
|
||||||
|
}
|
||||||
|
|
||||||
|
reload() {
|
||||||
|
ebegin "Reloading ${SVCNAME}"
|
||||||
|
checkconfig || { eerror "Reloading failed, please fix your ${CONF} first"; return 1; }
|
||||||
|
$command -D -p "${PIDFILE}" -f "${CONF}" -f "${CONF_DIR}" -sf $(cat "${PIDFILE}")
|
||||||
|
eend $?
|
||||||
|
}
|
|
@ -1 +1,2 @@
|
||||||
- import_playbook:
|
- import_playbook: pkg.ansible.yml
|
||||||
|
- import_playbook: service.ansible.yml
|
||||||
|
|
1
haproxy/map.yml
Normal file
1
haproxy/map.yml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
conf_dir: /etc/haproxy/conf.d
|
34
haproxy/pkg.ansible.yml
Normal file
34
haproxy/pkg.ansible.yml
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
- hosts: localhost
|
||||||
|
vars_files:
|
||||||
|
- map.yml
|
||||||
|
tasks:
|
||||||
|
- name: Install haproxy pkg
|
||||||
|
package:
|
||||||
|
state: present
|
||||||
|
name:
|
||||||
|
- haproxy
|
||||||
|
- name: Setup haproxy conf.d directory
|
||||||
|
file:
|
||||||
|
state: directory
|
||||||
|
path: /etc/haproxy/conf.d
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0755'
|
||||||
|
- name: Populate haproxy config
|
||||||
|
template:
|
||||||
|
src: files/haproxy_config.j2
|
||||||
|
dest: /etc/haproxy/haproxy.cfg
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0644'
|
||||||
|
vars:
|
||||||
|
IPV4: "{{ ansible_default_ipv4.address }}"
|
||||||
|
- name: Populate haproxy rc-script
|
||||||
|
template:
|
||||||
|
src: files/haproxy_rcscript.initd.j2
|
||||||
|
dest: /etc/init.d/haproxy
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0755'
|
||||||
|
vars:
|
||||||
|
CONF_DIR: "{{ conf_dir }}"
|
7
haproxy/service.ansible.yml
Normal file
7
haproxy/service.ansible.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
- hosts: localhost
|
||||||
|
tasks:
|
||||||
|
- name: Enable haproxy service
|
||||||
|
service:
|
||||||
|
name: haproxy
|
||||||
|
state: started
|
||||||
|
enabled: true
|
Loading…
Reference in a new issue