From: Peter Palfrader Date: Thu, 25 Apr 2013 13:18:34 +0000 (+0200) Subject: Send update component request to proper master host X-Git-Url: https://git.adam-barratt.org.uk/?a=commitdiff_plain;h=651fe05d48395dc41a629de4567383db7c97fbb4;p=mirror%2Fdsa-puppet.git Send update component request to proper master host --- diff --git a/modules/roles/files/static-mirroring/static-update-component b/modules/roles/files/static-mirroring/static-update-component new file mode 100755 index 000000000..7e8475455 --- /dev/null +++ b/modules/roles/files/static-mirroring/static-update-component @@ -0,0 +1,84 @@ +#!/bin/bash + +# Copyright (c) 2012 Peter Palfrader +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +usage() { + echo >&2 "Usage: $0 " + exit 1 +} + +componentlist=/etc/static-components.conf + +if [ "$#" = 1 ]; then + component="$1" +else + usage +fi + + +if [ "${component%/*}" != "$component" ] ; then + echo >&2 "$0: Invalid component: $component"; + exit 1 +fi + +thishost=$(hostname -f) +masterhost="$(awk -v component="$component" '$2 == component {print $1; exit}' "$componentlist")" +srchost="$(awk -v component="$component" '$2 == component {print $3; exit}' "$componentlist")" +srcdir="$(awk -v component="$component" '$2 == component {print $4; exit}' "$componentlist")" +inextralist="$( + awk -v component="$component" -v host="$thishost" ' + $2 == component { + split($5,extra,",") + for (i in extra) { + if (host == extra[i]) { + printf "%s:%s\n", $3, $4 + exit + } + } + exit + }' "$componentlist" + )" +if [ -z "$srchost" ] || [ -z "$srcdir" ]; then + echo >&2 "$0: Invalid component: $component (not found in $componentlist)"; + exit 1 +fi + +if ! [ "$srchost" = "$thishost" ] && [ -z "$inextralist" ]; then + echo >&2 "Component $component is sourced from $srchost, and this host is neither that nor in the extra allowed list." + exit 1 +fi + +if [ "$srchost" = "$thishost" ] && ! [ -d "$srcdir" ]; then + echo >&2 "Component source directory $srcdir does not exist or is not a directory, or is not accessible." + exit 1 +fi + +if [ "`id -nu`" != "staticsync" ] && [ "$masterhost" = "`hostname -f`" ]; then + static-update-component "$@" +else + ssh -o AddressFamily=inet -t -o ServerAliveInterval=300 -o PreferredAuthentications=publickey "$masterhost" static-master-update-component "$component" +fi + +# vim:set et: +# vim:set ts=2: +# vim:set shiftwidth=2: +# vim:set syn=sh: diff --git a/modules/roles/manifests/static_source.pp b/modules/roles/manifests/static_source.pp index dbdede186..81210e291 100644 --- a/modules/roles/manifests/static_source.pp +++ b/modules/roles/manifests/static_source.pp @@ -4,7 +4,7 @@ class roles::static_source { content => template('roles/static-mirroring/static-mirror-authorized_keys.erb'), } file { '/usr/local/bin/static-update-component': - content => template('roles/static-mirroring/static-update-component.erb'), + source => 'puppet:///modules/roles/static-mirroring/static-update-component', mode => '0555', } file { '/usr/local/bin/static-mirror-ssh-wrap': diff --git a/modules/roles/templates/static-mirroring/static-update-component.erb b/modules/roles/templates/static-mirroring/static-update-component.erb deleted file mode 100755 index 2f70cfbb7..000000000 --- a/modules/roles/templates/static-mirroring/static-update-component.erb +++ /dev/null @@ -1,97 +0,0 @@ -#!/bin/bash - -# Copyright (c) 2012 Peter Palfrader -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -usage() { - echo >&2 "Usage: $0 " - exit 1 -} - -componentlist=/etc/static-components.conf - -if [ "$#" = 1 ]; then - component="$1" -else - usage -fi - - -if [ "${component%/*}" != "$component" ] ; then - echo >&2 "$0: Invalid component: $component"; - exit 1 -fi - -thishost=$(hostname -f) -srchost="$(awk -v component="$component" '$1 == component {print $2; exit}' "$componentlist")" -srcdir="$(awk -v component="$component" '$1 == component {print $3; exit}' "$componentlist")" -inextralist="$( - awk -v component="$component" -v host="$thishost" ' - $1 == component { - split($4,extra,",") - for (i in extra) { - if (host == extra[i]) { - printf "%s:%s\n", $2, $3 - exit - } - } - exit - }' "$componentlist" - )" -if [ -z "$srchost" ] || [ -z "$srcdir" ]; then - echo >&2 "$0: Invalid component: $component (not found in $componentlist)"; - exit 1 -fi - -if ! [ "$srchost" = "$thishost" ] && [ -z "$inextralist" ]; then - echo >&2 "Component $component is sourced from $srchost, and this host is neither that nor in the extra allowed list." - exit 1 -fi - -if [ "$srchost" = "$thishost" ] && ! [ -d "$srcdir" ]; then - echo >&2 "Component source directory $srcdir does not exist or is not a directory, or is not accessible." - exit 1 -fi - -if [ "`id -nu`" != "staticsync" ]; then - sudo -u staticsync static-update-component "$@" -else - masters=() -<%= -lines = [] -masters = [] -scope.lookupvar('site::localinfo').keys.sort.each do |node| - if scope.lookupvar('site::localinfo')[node]['static_master'] - lines << " masters+=(\"#{node}\")" - end -end -lines.join("\n") -%> - - for master_idx in ${!masters[*]}; do - ssh -o AddressFamily=inet -t -o ServerAliveInterval=300 -o PreferredAuthentications=publickey "${masters[$master_idx]}" static-master-update-component "$component" - done -fi - -# vim:set et: -# vim:set ts=2: -# vim:set shiftwidth=2: -# vim:set syn=sh: