Selaa lähdekoodia

Create basic class to install nginx

DarkMorford 6 vuotta sitten
vanhempi
commit
b17c1b82d5
5 muutettua tiedostoa jossa 37 lisäystä ja 3 poistoa
  1. 2 0
      data/os/Debian.yaml
  2. 4 1
      hiera.yaml
  3. 13 0
      manifests/init.pp
  4. 2 2
      metadata.json
  5. 16 0
      spec/classes/nginx_spec.rb

+ 2 - 0
data/os/Debian.yaml

@@ -0,0 +1,2 @@
+---
+nginx::server_package: 'nginx'

+ 4 - 1
hiera.yaml

@@ -5,6 +5,9 @@ defaults:  # Used for any hierarchy level that omits these keys.
   datadir: data         # This path is relative to hiera.yaml's directory.
   data_hash: yaml_data  # Use the built-in YAML backend.
 
-hierarchy:
+default_hierarchy:
+  - name: "OS Family"
+    path: "os/%{facts.os.family}.yaml"
+
   - name: 'common'
     path: 'common.yaml'

+ 13 - 0
manifests/init.pp

@@ -0,0 +1,13 @@
+# A description of what this class does
+#
+# @summary A short summary of the purpose of this class
+#
+# @example
+#   include nginx
+class nginx (
+  String $server_package,
+) {
+  package { $server_package:
+    ensure => installed,
+  }
+}

+ 2 - 2
metadata.json

@@ -12,14 +12,14 @@
       "operatingsystem": "Debian",
       "operatingsystemrelease": [
         "8",
-		"9"
+        "9"
       ]
     },
     {
       "operatingsystem": "Ubuntu",
       "operatingsystemrelease": [
         "16.04",
-		"18.04"
+        "18.04"
       ]
     }
   ],

+ 16 - 0
spec/classes/nginx_spec.rb

@@ -0,0 +1,16 @@
+require 'spec_helper'
+
+describe 'nginx' do
+  on_supported_os.each do |os, os_facts|
+    context "on #{os}" do
+      let(:facts) { os_facts }
+
+      it { is_expected.to compile.with_all_deps }
+
+      case facts[:osfamily]
+      when 'Debian'
+        it { is_expected.to contain_package('nginx') }
+      end
+    end
+  end
+end