Hello -
We have apps that use haproxy as a lb for http/https and we use 8 haproxy
sockets. Below I have included a playbook extract and a sample run where I
take a single server in and out of the lbs. In this example the server is
behind 2 lbs and has 2 backends. So when I run the haproxy module play to
enable or disable the server there are 32 subtasks (see below).
I am wondering if there is a faster way of doing this.
I have pipelining=True in the ansible.cfg.
This example is relatively simple - I have other configs with 4 backends
and 6 lbs so the deploys can get a bit bogged down.
thank you
Michael
playbook extract
---
- name: put loadbalanced servers in and out of maintenance
hosts: all
remote_user: ansible_user
become: yes
roles:
- baseinstall
# - "{{ app_role }}"
serial: "25%"
# accelerate: True # this is deprecated
vars:
disable_app: False
enable_app: False
tasks:
- name: set pre-timestamp
set_fact:
pretimestamp: "{{ lookup('pipe', 'date +%Y%m%d-%T') }}"
- name: show hostname and prestamp
debug:
msg: "{{pretimestamp}} - {{ansible_hostname}}"
- block:
- name: disable server in lb
haproxy: 'state=disabled host="{{ ansible_hostname }}" backend={{
item[1] }} socket={{item[2]}}'
delegate_to: "{{ item[0] }}"
with_nested:
- "{{loadbalancer_group}}"
- "{{lbbackends}}"
- "{{haproxysocks}}"
when: loadbalanced and disable_app
- block:
- name: enable server in lb
haproxy: 'state=enabled host="{{ ansible_hostname }}" backend={{
item[1] }} socket={{item[2]}}'
delegate_to: "{{ item[0] }}"
with_nested:
- "{{loadbalancer_group}}"
- "{{lbbackends}}"
- "{{haproxysocks}}"
when: loadbalanced and enable_app
- name: set post-timestamp
set_fact:
posttimestamp: "{{ lookup('pipe', 'date +%Y%m%d-%T') }}"
- name: show stats
debug:
msg: "{{pretimestamp}} - {{posttimestamp}}"
<https://gist.github.com/mbubb/dbc978de70df801c5666739fbd676614#output>output
extract (not showing enable play)
### ansible-playbook /etc/ansible/ansible-modules/lb_app_maint.yml -s -e
"loadbalanced=True" -e "disable_app=True" -e "enable_app=True" -l
web-sin-1.example.com
PLAY [put loadbalanced servers in and out of maintenance]
*********************************************************************************************************************************************************
...
TASK [disable server in lb]
***************************************************************************************************************************************************************************************
changed: [web-sin-1.example.com -> 10.64.141.111] =>
(item=[u'lb-sin-1.example.com', u'myapp', u'/var/run/haproxysock1'])
changed: [web-sin-1.example.com -> 10.64.141.111] =>
(item=[u'lb-sin-1.example.com', u'myapp', u'/var/run/haproxysock2'])
changed: [web-sin-1.example.com -> 10.64.141.111] =>
(item=[u'lb-sin-1.example.com', u'myapp', u'/var/run/haproxysock3'])
changed: [web-sin-1.example.com -> 10.64.141.111] =>
(item=[u'lb-sin-1.example.com', u'myapp', u'/var/run/haproxysock4'])
changed: [web-sin-1.example.com -> 10.64.141.111] =>
(item=[u'lb-sin-1.example.com', u'myapp', u'/var/run/haproxysock5'])
changed: [web-sin-1.example.com -> 10.64.141.111] =>
(item=[u'lb-sin-1.example.com', u'myapp', u'/var/run/haproxysock6'])
changed: [web-sin-1.example.com -> 10.64.141.111] =>
(item=[u'lb-sin-1.example.com', u'myapp', u'/var/run/haproxysock7'])
changed: [web-sin-1.example.com -> 10.64.141.111] =>
(item=[u'lb-sin-1.example.com', u'myapp', u'/var/run/haproxysock8'])
changed: [web-sin-1.example.com -> 10.64.141.111] =>
(item=[u'lb-sin-1.example.com', u'myapphttps', u'/var/run/haproxysock1'])
changed: [web-sin-1.example.com -> 10.64.141.111] =>
(item=[u'lb-sin-1.example.com', u'myapphttps', u'/var/run/haproxysock2'])
changed: [web-sin-1.example.com -> 10.64.141.111] =>
(item=[u'lb-sin-1.example.com', u'myapphttps', u'/var/run/haproxysock3'])
changed: [web-sin-1.example.com -> 10.64.141.111] =>
(item=[u'lb-sin-1.example.com', u'myapphttps', u'/var/run/haproxysock4'])
changed: [web-sin-1.example.com -> 10.64.141.111] =>
(item=[u'lb-sin-1.example.com', u'myapphttps', u'/var/run/haproxysock5'])
changed: [web-sin-1.example.com -> 10.64.141.111] =>
(item=[u'lb-sin-1.example.com', u'myapphttps', u'/var/run/haproxysock6'])
changed: [web-sin-1.example.com -> 10.64.141.111] =>
(item=[u'lb-sin-1.example.com', u'myapphttps', u'/var/run/haproxysock7'])
changed: [web-sin-1.example.com -> 10.64.141.111] =>
(item=[u'lb-sin-1.example.com', u'myapphttps', u'/var/run/haproxysock8'])
changed: [web-sin-1.example.com -> 10.64.141.107] =>
(item=[u'lb-sin-2.example.com', u'myapp', u'/var/run/haproxysock1'])
changed: [web-sin-1.example.com -> 10.64.141.107] =>
(item=[u'lb-sin-2.example.com', u'myapp', u'/var/run/haproxysock2'])
changed: [web-sin-1.example.com -> 10.64.141.107] =>
(item=[u'lb-sin-2.example.com', u'myapp', u'/var/run/haproxysock3'])
changed: [web-sin-1.example.com -> 10.64.141.107] =>
(item=[u'lb-sin-2.example.com', u'myapp', u'/var/run/haproxysock4'])
changed: [web-sin-1.example.com -> 10.64.141.107] =>
(item=[u'lb-sin-2.example.com', u'myapp', u'/var/run/haproxysock5'])
changed: [web-sin-1.example.com -> 10.64.141.107] =>
(item=[u'lb-sin-2.example.com', u'myapp', u'/var/run/haproxysock6'])
changed: [web-sin-1.example.com -> 10.64.141.107] =>
(item=[u'lb-sin-2.example.com', u'myapp', u'/var/run/haproxysock7'])
changed: [web-sin-1.example.com -> 10.64.141.107] =>
(item=[u'lb-sin-2.example.com', u'myapp', u'/var/run/haproxysock8'])
changed: [web-sin-1.example.com -> 10.64.141.107] =>
(item=[u'lb-sin-2.example.com', u'myapphttps', u'/var/run/haproxysock1'])
changed: [web-sin-1.example.com -> 10.64.141.107] =>
(item=[u'lb-sin-2.example.com', u'myapphttps', u'/var/run/haproxysock2'])
changed: [web-sin-1.example.com -> 10.64.141.107] =>
(item=[u'lb-sin-2.example.com', u'myapphttps', u'/var/run/haproxysock3'])
changed: [web-sin-1.example.com -> 10.64.141.107] =>
(item=[u'lb-sin-2.example.com', u'myapphttps', u'/var/run/haproxysock4'])
changed: [web-sin-1.example.com -> 10.64.141.107] =>
(item=[u'lb-sin-2.example.com', u'myapphttps', u'/var/run/haproxysock5'])
changed: [web-sin-1.example.com -> 10.64.141.107] =>
(item=[u'lb-sin-2.example.com', u'myapphttps', u'/var/run/haproxysock6'])
changed: [web-sin-1.example.com -> 10.64.141.107] =>
(item=[u'lb-sin-2.example.com', u'myapphttps', u'/var/run/haproxysock7'])
changed: [web-sin-1.example.com -> 10.64.141.107] =>
(item=[u'lb-sin-2.example.com', u'myapphttps', u'/var/run/haproxysock8'])
TASK [show stats]
*************************************************************************************************************************************************************************************************
ok: [web-sin-1.example.com ] => {
"changed": false,
"msg": "20170419-16:38:46 - 20170419-16:39:28"
}
PLAY RECAP
********************************************************************************************************************************************************************************************************
web-sin-1.example.com : ok=7 changed=2 unreachable=0 failed=0
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/15a66b33-c47c-4b76-a9d5-8d3f99fa69ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.