BryanDavis has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/212294

Change subject: [WIP] Add Vagrantfile
......................................................................

[WIP] Add Vagrantfile

Add configuration that allows this Puppet repository to be used to
provision virtual machines using Vagrant.

Change-Id: Ib3c8724f392d94e591fdb43866cce42a26c4c2e7
---
M manifests/realm.pp
M modules/apt/manifests/init.pp
M modules/wmflib/lib/hiera/backend/nuyaml_backend.rb
A utils/vagrant/.gitignore
A utils/vagrant/Vagrantfile
A utils/vagrant/fileserver.conf
A utils/vagrant/hiera.yaml
A utils/vagrant/hieradata/common/apt.yaml
8 files changed, 175 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/94/212294/1

diff --git a/manifests/realm.pp b/manifests/realm.pp
index 0c7ccae..f4ee3f8 100644
--- a/manifests/realm.pp
+++ b/manifests/realm.pp
@@ -23,17 +23,19 @@
     $main_ipaddress = $ipaddress
 }
 
-$site = $main_ipaddress ? {
-    /^208\.80\.152\./                         => 'codfw',
-    /^208\.80\.153\./                         => 'codfw',
-    /^208\.80\.15[45]\./                      => 'eqiad',
-    /^10\.6[48]\./                            => 'eqiad',
-    /^10\.192\./                              => 'codfw',
-    /^91\.198\.174\./                         => 'esams',
-    /^198\.35\.26\.([0-9]|[1-5][0-9]|6[0-2])/ => 'ulsfo',
-    /^10\.128\./                              => 'ulsfo',
-    /^10\.20\.0\./                            => 'esams',
-    default                                   => '(undefined)'
+if $::site == undef {
+    $site = $main_ipaddress ? {
+        /^208\.80\.152\./                         => 'codfw',
+        /^208\.80\.153\./                         => 'codfw',
+        /^208\.80\.15[45]\./                      => 'eqiad',
+        /^10\.6[48]\./                            => 'eqiad',
+        /^10\.192\./                              => 'codfw',
+        /^91\.198\.174\./                         => 'esams',
+        /^198\.35\.26\.([0-9]|[1-5][0-9]|6[0-2])/ => 'ulsfo',
+        /^10\.128\./                              => 'ulsfo',
+        /^10\.20\.0\./                            => 'esams',
+        default                                   => '(undefined)'
+    }
 }
 
 $mw_primary = $::realm ? {
diff --git a/modules/apt/manifests/init.pp b/modules/apt/manifests/init.pp
index 8802817..bc2ba3d 100644
--- a/modules/apt/manifests/init.pp
+++ b/modules/apt/manifests/init.pp
@@ -1,4 +1,11 @@
-class apt {
+# == Class: apt
+#
+# === Parameters
+# [*use_proxy*]
+#   Use a proxy server to access apt repositories. Default true.
+class apt (
+  $use_proxy = true,
+) {
     exec { 'apt-get update':
         path        => '/usr/bin',
         timeout     => 240,
@@ -46,8 +53,6 @@
         notify  => Exec['apt-get update'],
     }
 
-    $http_proxy = "http://webproxy.${::site}.wmnet:8080";
-
     # This will munge /etc/apt/apt.conf that get's created during installation
     # process (either labs vmbuilder or d-i). Given the ones below exist, it is
     # no longer needed after the installation is over
@@ -56,15 +61,19 @@
         notify => Exec['apt-get update'],
     }
 
-    apt::conf { 'wikimedia-proxy':
-        ensure   => absent,
-        priority => '80',
-        key      => 'Acquire::http::Proxy',
-        value    => $http_proxy,
+    notify { "Got to ::apt with use_proxy=${use_proxy}":
+        withpath => true,
     }
 
-    if $::operatingsystem == 'Debian' {
-        $components = 'main backports thirdparty'
+    if $use_proxy {
+        $http_proxy = "http://webproxy.${::site}.wmnet:8080";
+
+        apt::conf { 'wikimedia-proxy':
+            ensure   => absent,
+            priority => '80',
+            key      => 'Acquire::http::Proxy',
+            value    => $http_proxy,
+        }
 
         apt::conf { 'security-debian-proxy':
             ensure   => present,
@@ -72,8 +81,6 @@
             key      => 'Acquire::http::Proxy::security.debian.org',
             value    => $http_proxy,
         }
-    } elsif $::operatingsystem == 'Ubuntu' {
-        $components = 'main universe thirdparty'
 
         apt::conf { 'security-ubuntu-proxy':
             ensure   => present,
@@ -95,6 +102,12 @@
             key      => 'Acquire::http::Proxy::old-releases.ubuntu.com',
             value    => $http_proxy,
         }
+    }
+
+    if $::operatingsystem == 'Debian' {
+        $components = 'main backports thirdparty'
+    } elsif $::operatingsystem == 'Ubuntu' {
+        $components = 'main universe thirdparty'
     } else {
         fail("Unknown operating system '$::operatingsystem'.")
     }
diff --git a/modules/wmflib/lib/hiera/backend/nuyaml_backend.rb 
b/modules/wmflib/lib/hiera/backend/nuyaml_backend.rb
index 3a73514..8eb46e1 100644
--- a/modules/wmflib/lib/hiera/backend/nuyaml_backend.rb
+++ b/modules/wmflib/lib/hiera/backend/nuyaml_backend.rb
@@ -15,6 +15,12 @@
 # in a data.yaml file in the data dir we've specified as the datadir
 # for a 'private' backend, or in the default datadir as a fallback.
 #
+# == Vagrant path
+#
+# If you define a 'vagrant' data source in hiera, we will look up
+# in a data.yaml file in the data dir we've specified as the datadir
+# for a 'vagrant' backend, or in the default datadir as a fallback.
+#
 # == Path expansion
 #
 # Any hierarchy named in the backend-configuration section
@@ -92,6 +98,15 @@
           source = m[1]
         end
 
+        # Special case: 'vagrant' repository.
+        # We use a different datadir in this case.
+        # Example: vagrant/common will search in the common source
+        # within the vagrant datadir
+        if m = /vagrant\/(.*)/.match(source)
+          config_section = :vagrant
+          source = m[1]
+        end
+
         Hiera.debug("The source is: #{source}")
         # If the source is in the expand_path list, perform path
         # expansion. This is thought to allow large codebases to live
diff --git a/utils/vagrant/.gitignore b/utils/vagrant/.gitignore
new file mode 100644
index 0000000..60daf28
--- /dev/null
+++ b/utils/vagrant/.gitignore
@@ -0,0 +1,2 @@
+.vagrant/
+private/
diff --git a/utils/vagrant/Vagrantfile b/utils/vagrant/Vagrantfile
new file mode 100644
index 0000000..5a16608
--- /dev/null
+++ b/utils/vagrant/Vagrantfile
@@ -0,0 +1,77 @@
+# Wikimedia Puppet Vagrant
+# ========================
+#
+# Want to impress your friends and confound your enemies? Then setup a VM on
+# your laptop using the exact Puppet configuration used in the Wikimedia
+# Foundation's production cluster!
+#
+# Example
+# -------
+# OPS_HOSTNAME=logstash1001.eqiad.wmnet vagrant up precise
+#
+Vagrant.configure(2) do |config|
+
+  config.vm.hostname = ENV['OPS_HOSTNAME'] || 'opsvagrant.eqiad.wmnet'
+
+  config.vm.network 'private_network', type: 'dhcp'
+
+  config.vm.define :precise, autostart: false do |precise|
+    precise.vm.box = 'ubuntu/precise64'
+  end
+
+  config.vm.define :trusty, autostart: false do |trusty|
+    trusty.vm.box = 'ubuntu/trusty64'
+  end
+
+  config.vm.define :jessie, autostart: false do |jessie|
+    jessie.vm.box = 'deimosfr/debian-jessie'
+  end
+
+  config.vm.synced_folder '../..', '/vagrant'
+
+  config.vm.provision :puppet do |puppet|
+    puppet.module_path = []
+    puppet.manifests_path = [:guest, '/vagrant/manifests']
+    puppet.manifest_file = 'site.pp'
+    puppet.working_directory = '/vagrant'
+    puppet.options = [
+      '--modulepath', 
'/vagrant/modules:/vagrant/utils/vagrant/private/modules',
+      '--templatedir', '/vagrant/templates',
+      '--hiera_config', '/vagrant/utils/vagrant/hiera.yaml',
+      '--fileserverconfig', '/vagrant/utils/vagrant/fileserver.conf',
+      '--verbose',
+      '--logdest', 'console',
+    ]
+    puppet.facter = {
+      'fqdn'     => config.vm.hostname,
+      'hostname' => config.vm.hostname.split('.')[0],
+      'site'     => config.vm.hostname.split('.')[1],
+      'cluster'  => ENV['OPS_CLUSTER'] || 'misc'
+    }
+    puppet.options << '--debug' if ENV.include?('PUPPET_DEBUG')
+  end
+
+  config.vm.provider :virtualbox do |vb|
+    host = RbConfig::CONFIG['host_os']
+    if host =~ /mac|darwin/i
+      cpus = `sysctl -n hw.ncpu`.to_i
+      mem = `sysctl -n hw.memsize`.to_i / 1024 / 1024 / 4
+    elsif host =~ /linux/i
+      cpus = `nproc`.to_i
+      mem = `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ 
kB//'`.to_i / 1024 / 4
+    elsif host =~ /mswin|mingw|cygwin/i
+      require 'win32ole'
+      wmi = WIN32OLE.connect('winmgmts://')
+      q = wmi.ExecQuery('select NumberOfCores from Win32_Processor')
+      cpus = q.to_enum.reduce(0) { |cores, processor| cores + 
processor.NumberOfCores }
+      mem = `wmic OS get TotalVisibleMemorySize | more +1`.to_i / 1024
+    else
+      cpus = 2
+      mem = 1024
+    end
+    vb.customize [ 'modifyvm', :id, '--memory', mem, '--cpus', cpus ]
+  end
+
+end
+# -*- mode: ruby -*-
+# vi: set ft=ruby :
diff --git a/utils/vagrant/fileserver.conf b/utils/vagrant/fileserver.conf
new file mode 100644
index 0000000..8c5a090
--- /dev/null
+++ b/utils/vagrant/fileserver.conf
@@ -0,0 +1,7 @@
+[files]
+  path /vagrant/files
+  allow *
+
+[private]
+  path /vagrant/utils/vagrant/private/files
+  allow *
diff --git a/utils/vagrant/hiera.yaml b/utils/vagrant/hiera.yaml
new file mode 100644
index 0000000..32907d9
--- /dev/null
+++ b/utils/vagrant/hiera.yaml
@@ -0,0 +1,34 @@
+:backends:
+  - nuyaml
+  - role
+
+:role:
+  :datadir: /vagrant/hieradata
+
+:nuyaml:
+  :datadir: /vagrant/hieradata
+  :expand_path:
+    - common
+    - "%{::site}"
+
+:private:
+  :datadir: /vagrant/utils/vagrant/private/hieradata
+
+:vagrant:
+  :datadir: /vagrant/utils/vagrant/hieradata
+
+:hierarchy:
+  - vagrant/local
+  - vagrant/common
+  - "hosts/%{::hostname}"
+  - "regex/%{::fqdn}"
+  - "%{::site}"
+  - "private/%{::site}"
+  - common
+  - private/common
+
+:role_hierarchy:
+  - "%{::site}"
+  - common
+  - "private/%{::site}"
+  - private/common
diff --git a/utils/vagrant/hieradata/common/apt.yaml 
b/utils/vagrant/hieradata/common/apt.yaml
new file mode 100644
index 0000000..07da383
--- /dev/null
+++ b/utils/vagrant/hieradata/common/apt.yaml
@@ -0,0 +1,2 @@
+---
+use_proxy: false

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib3c8724f392d94e591fdb43866cce42a26c4c2e7
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: BryanDavis <bda...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to