Skip to content

Commit

Permalink
Update haproxy.yml
Browse files Browse the repository at this point in the history
* Install lua and haproxy only if the source files has been downloaded.
Do not attempt to install haproxy packages when you re-run this book.
* Restart the haproxy service only during the initial installation or modification of the configuration file.
Do not restart the service when re-executing this playbook.
* Updated tags.
  • Loading branch information
vitabaks committed Sep 26, 2019
1 parent 9e64127 commit 58011db
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion deploy_pgcluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

- import_tasks: tasks/haproxy.yml
when: with_haproxy_load_balancing == "true" and cluster_vip | length > 0
tags: [ haproxy, load_balancing ]
tags: load_balancing

- import_tasks: tasks/vip-manager.yml
when: with_haproxy_load_balancing != "true" and cluster_vip | length > 0
Expand Down
29 changes: 23 additions & 6 deletions tasks/haproxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
src: http://www.haproxy.org/download/{{ haproxy_major }}/src/haproxy-{{ haproxy_version }}.tar.gz
dest: /tmp/
remote_src: yes
register: haproxy_src_result

- name: "haproxy | download lua-5.3.5 source files"
become: yes
Expand All @@ -17,6 +18,7 @@
dest: /tmp/
remote_src: yes
validate_certs: no
register: lua_src_result
tags: lua

# "Debian"
Expand Down Expand Up @@ -56,18 +58,21 @@
- systemd-devel
when: ansible_os_family == "RedHat"
environment: '{{ proxy_env | default({}) }}'

tags: haproxy

- name: haproxy | add haproxy group
group:
name: haproxy
state: present
tags: haproxy

- name: haproxy | add haproxy user
user:
name: haproxy
comment: "HAProxy user"
group: haproxy
shell: /usr/sbin/nologin
tags: haproxy

- name: haproxy | create directories
file:
Expand All @@ -79,6 +84,7 @@
- /etc/haproxy
- /var/run/haproxy
- /var/lib/haproxy/dev
tags: haproxy

# The version of Lua in the CentOS 7 repositories is too old for HAProxy
- name: haproxy | build and install lua-5.3.5 (required for HAProxy)
Expand All @@ -87,8 +93,9 @@
shell: "make INSTALL_TOP=/opt/lua-5.3.5 linux install"
args:
chdir: /tmp/lua-5.3.5
tags: lua

when: lua_src_result.changed
tags: [ haproxy, lua ]

# https://github.com/haproxy/haproxy/blob/master/INSTALL
- name: haproxy | build HAProxy
become: yes
Expand All @@ -109,34 +116,43 @@
USE_LUA: 1
LUA_INC: /opt/lua-5.3.5/include
LUA_LIB: /opt/lua-5.3.5/lib
when: haproxy_src_result.changed
tags: haproxy

- name: haproxy | install HAProxy
become: yes
become_user: root
make:
chdir: "/tmp/haproxy-{{ haproxy_version }}"
target: install

when: haproxy_src_result.changed
tags: haproxy

- name: haproxy | create systemd service file
template:
src: templates/haproxy.service.j2
dest: /etc/systemd/system/haproxy.service
owner: haproxy
group: haproxy
register: haproxy_service_result
tags: [ haproxy, haproxy_service ]

- name: haproxy | generate conf file "/etc/haproxy/haproxy.cfg"
template:
src: templates/haproxy.cfg.j2
dest: /etc/haproxy/haproxy.cfg
tags: [ haproxy_conf, haproxy ]
register: haproxy_conf_result
tags: [ haproxy, haproxy_conf ]

- name: haproxy | restart systemd service
systemd:
daemon_reload: yes
name: haproxy
enabled: yes
state: restarted
register: haproxy_restart_result
when: haproxy_conf_result.changed
tags: [ haproxy, haproxy_conf ]

- name: haproxy | check HAProxy is started and accepting connections
wait_for:
Expand All @@ -146,7 +162,8 @@
timeout: 120
delay: 10
ignore_errors: no

when: haproxy_restart_result.changed
tags: [ haproxy, haproxy_conf ]

# for automate the haproxy configuration (optional)
- import_tasks: ../tasks/confd.yml
Expand Down

0 comments on commit 58011db

Please sign in to comment.