From dd6cd68f81fe5e7eaf49ae6cb2cb245c58028edf Mon Sep 17 00:00:00 2001 From: Tim Gerla Date: Thu, 25 Apr 2013 20:03:03 -0700 Subject: [PATCH] Simplify site.yml and allow parallelization of 'common' role tasks, and update to new pre_task/post_task syntax for rolling update. --- lamp_haproxy/db.yml | 12 ---------- lamp_haproxy/haproxy.yml | 12 ---------- lamp_haproxy/nagios.yml | 13 ----------- lamp_haproxy/rolling_update.yml | 27 +++++++++++++++-------- lamp_haproxy/site.yml | 39 ++++++++++++++++++++++++++++----- lamp_haproxy/web.yml | 14 ------------ 6 files changed, 52 insertions(+), 65 deletions(-) delete mode 100644 lamp_haproxy/db.yml delete mode 100644 lamp_haproxy/haproxy.yml delete mode 100644 lamp_haproxy/nagios.yml delete mode 100644 lamp_haproxy/web.yml diff --git a/lamp_haproxy/db.yml b/lamp_haproxy/db.yml deleted file mode 100644 index 9484ec9..0000000 --- a/lamp_haproxy/db.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -# This playbook deploys MySQL and configures the database on the db node(s) - -# fetch monitoring facts for iptables rules -- hosts: monitoring - tasks: - -- hosts: dbservers - user: root - roles: - - common - - db diff --git a/lamp_haproxy/haproxy.yml b/lamp_haproxy/haproxy.yml deleted file mode 100644 index 11f5d26..0000000 --- a/lamp_haproxy/haproxy.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -# Playbook for HAProxy operations - -# fetch monitoring facts for iptables rules -- hosts: monitoring - tasks: - -- hosts: lbservers - user: root - roles: - - common - - haproxy diff --git a/lamp_haproxy/nagios.yml b/lamp_haproxy/nagios.yml deleted file mode 100644 index 3016617..0000000 --- a/lamp_haproxy/nagios.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -# This playbook configures the monitoring node - -# trigger fact-gathering for all hosts -- hosts: all - tasks: - -- hosts: monitoring - user: root - roles: - - common - - base-apache - - nagios diff --git a/lamp_haproxy/rolling_update.yml b/lamp_haproxy/rolling_update.yml index d6f2b49..fdb7e25 100644 --- a/lamp_haproxy/rolling_update.yml +++ b/lamp_haproxy/rolling_update.yml @@ -1,14 +1,22 @@ --- -# This playbook does a rolling update of the code for all webservers serially (one at a time). +# This playbook does a rolling update for all webservers serially (one at a time). # Change the value of serial: to adjust the number of server to be updated. -# This playbook also takes the webapp_version variable to specify which git version -# of the test webapp to deploy. +# +# The three roles that apply to the webserver hosts will be applied: common, +# base-apache, and web. So any changes to configuration, package updates, etc, +# will be applied as part of the rolling update process. +# + +# gather facts from monitoring nodes for iptables rules +- hosts: monitoring + tasks: - hosts: webservers user: root serial: 1 - tasks: + # These are the tasks to run before applying updates: + pre_tasks: - name: disable nagios alerts for this host webserver service nagios: action=disable_alerts host=$ansible_hostname services=webserver delegate_to: $item @@ -19,12 +27,13 @@ delegate_to: $item with_items: ${groups.lbservers} - - name: Remove the code from server - command: rm -rf /var/www/html/* - - - name: Copy the code from repository - git: repo=${repository} version=${webapp_version} dest=/var/www/html/ + roles: + - common + - base-apache + - web + # These tasks run after the roles: + post_tasks: - name: Enable the server in haproxy shell: echo "enable server myapplb/${ansible_hostname}" | socat stdio /var/lib/haproxy/stats delegate_to: $item diff --git a/lamp_haproxy/site.yml b/lamp_haproxy/site.yml index 8418376..ee89339 100644 --- a/lamp_haproxy/site.yml +++ b/lamp_haproxy/site.yml @@ -1,7 +1,36 @@ --- -#This Playbook deploys the whole application stack in this site. +# This playbook deploys the whole application stack in this site. -- include: db.yml -- include: web.yml -- include: haproxy.yml -- include: nagios.yml +# Apply common configuration to all hosts +- hosts: all + roles: + - common + +# Configure and deploy database servers. +- hosts: dbservers + user: root + roles: + - db + +# Configure and deploy the web servers. Note that we include two roles here, +# the 'base-apache' role which simply sets up Apache, and 'web' which includes +# our example web application. +- hosts: webservers + user: root + + roles: + - base-apache + - web + +# Configure and deploy the load balancer(s). +- hosts: lbservers + user: root + roles: + - haproxy + +# Configure and deploy the Nagios monitoring node(s). +- hosts: monitoring + user: root + roles: + - base-apache + - nagios diff --git a/lamp_haproxy/web.yml b/lamp_haproxy/web.yml deleted file mode 100644 index d40eae4..0000000 --- a/lamp_haproxy/web.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -# This playbook deploys the webservers with httpd and the code. - -# fetch monitoring facts for iptables rules -- hosts: monitoring - tasks: - -- hosts: webservers - user: root - - roles: - - common - - base-apache - - web