Giuseppe Lavagetto has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/350810 )

Change subject: scap::dsh: transition to using confd
......................................................................

scap::dsh: transition to using confd

Instead of calling conftool from puppet, which is typically a bit goofy,
build the dsh list that depend on conftool using confd instead.

Change-Id: If320eecfd2a6164387e06a120012d9a603175a87
---
M modules/scap/manifests/dsh/group.pp
M modules/scap/manifests/master.pp
A modules/scap/templates/dsh/dsh-group-conftool.tpl.erb
M modules/scap/templates/dsh/dsh-group.erb
4 files changed, 40 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/10/350810/1

diff --git a/modules/scap/manifests/dsh/group.pp 
b/modules/scap/manifests/dsh/group.pp
index f585d4c..5a4c6f6 100644
--- a/modules/scap/manifests/dsh/group.pp
+++ b/modules/scap/manifests/dsh/group.pp
@@ -13,12 +13,27 @@
         default => $hosts,
     }
 
-    file { "/etc/dsh/group/${title}":
-        ensure  => present,
-        owner   => 'root',
-        group   => 'root',
-        mode    => '0444',
-        content => template('scap/dsh/dsh-group.erb'),
+    if $conftool {
+        # Usual dirty trick to avoid a parser function
+        $keys = split(
+            inline_template('<%= @conftool.each{|x| [x['cluster'], 
x['service']].join "/"}.join("|")'),
+            '|')
+
+        confd::file { "/etc/dsh/group/${title}":
+            ensure => present,
+            prefix => '/pools',
+            watch_keys => $keys,
+            content  => template('scap/dsh/dsh-group-conftool.tpl.erb')
+        }
+    }
+    else {
+        file { "/etc/dsh/group/${title}":
+            ensure  => present,
+            owner   => 'root',
+            group   => 'root',
+            mode    => '0444',
+            content => template('scap/dsh/dsh-group.erb'),
+        }
     }
 
 }
diff --git a/modules/scap/manifests/master.pp b/modules/scap/manifests/master.pp
index c47a808..5b8c28d 100644
--- a/modules/scap/manifests/master.pp
+++ b/modules/scap/manifests/master.pp
@@ -9,8 +9,13 @@
     $statsd_host        = 'statsd.eqiad.wmnet',
     $statsd_port        = 8125,
     $deployment_group   = 'wikidev',
+    $conftool_prefix    = hiera('conftool_prefix'),
 ) {
     include scap::scripts
+    class { 'confd':
+        interval => 300,
+        prefix   => $conftool_prefix,
+    }
     include scap::dsh
     include rsync::server
     include network::constants
diff --git a/modules/scap/templates/dsh/dsh-group-conftool.tpl.erb 
b/modules/scap/templates/dsh/dsh-group-conftool.tpl.erb
new file mode 100644
index 0000000..b4aa72f
--- /dev/null
+++ b/modules/scap/templates/dsh/dsh-group-conftool.tpl.erb
@@ -0,0 +1,14 @@
+# DSH group <%= @title %>
+# This file is managed by puppet.
+
+# List of hosts defined in puppet
+# Either directly in the declaration of the resource
+# or via hiera scap::dsh::group::<%= @title %>
+<%= @host_list.sort.join("\n") %>
+
+# List of hosts gathered from etcd
+<%- @keys.each do |key| -%>
+# etcd pool: <%= key %>
+{{range $node := ls "<%= key %>/"}}{{ $key := printf "<%= key %>/%s" $node 
}}{{ $data := json (getv $key) }}
+{{ if ne $data.pooled "inactive" }}{{ $node }}{{end}}{{end}}
+<% end -%>
diff --git a/modules/scap/templates/dsh/dsh-group.erb 
b/modules/scap/templates/dsh/dsh-group.erb
index b54bc43..d8f575f 100644
--- a/modules/scap/templates/dsh/dsh-group.erb
+++ b/modules/scap/templates/dsh/dsh-group.erb
@@ -6,11 +6,3 @@
 # or via hiera scap::dsh::group::<%= @title %>
 <%= @host_list.sort.join("\n") %>
 
-# List of hosts gathered from conftool
-<%-
-conftool_tags = Array(@conftool)
-conftool_tags.each do |tags|
-  hosts = scope.function_conftool([tags, 'node']) -%>
-# Tags: <%= tags %>
-<%= hosts.select{ |x| x['value']['pooled'] != 'inactive' }.map{|x| 
x['name']}.sort.join("\n") %>
-<% end -%>

-- 
To view, visit https://gerrit.wikimedia.org/r/350810
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If320eecfd2a6164387e06a120012d9a603175a87
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Giuseppe Lavagetto <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to