summaryrefslogtreecommitdiffstats
path: root/examples/code
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-08-23 16:09:14 +0000
committerLuke Kanies <luke@madstop.com>2005-08-23 16:09:14 +0000
commit6029ef7812765775306ff8394005c326e359d886 (patch)
tree32cbe5ea68e0e9fbdc0935d0b41e58fdfcba9e3d /examples/code
parente87eb58ce8dc40ba8c66233bf17cea61094e7647 (diff)
downloadpuppet-6029ef7812765775306ff8394005c326e359d886.tar.gz
puppet-6029ef7812765775306ff8394005c326e359d886.tar.xz
puppet-6029ef7812765775306ff8394005c326e359d886.zip
Moving all files into a consolidated trunk. All tests pass except the known-failing certificate test, but there appear to be some errors that are incorrectly not resulting in failurs. I will track those down ASAP.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@576 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'examples/code')
-rw-r--r--examples/code/allatonce13
-rw-r--r--examples/code/assignments11
-rw-r--r--examples/code/classing35
-rw-r--r--examples/code/components73
-rw-r--r--examples/code/execs16
-rw-r--r--examples/code/facts22
-rw-r--r--examples/code/failers/badclassnoparam10
-rw-r--r--examples/code/failers/badclassparam10
-rw-r--r--examples/code/failers/badcompnoparam9
-rw-r--r--examples/code/failers/badcompparam9
-rw-r--r--examples/code/failers/badtypeparam3
-rw-r--r--examples/code/file.bl11
-rw-r--r--examples/code/filedefaults10
-rw-r--r--examples/code/fileparsing116
-rw-r--r--examples/code/filerecursion15
-rw-r--r--examples/code/functions3
-rw-r--r--examples/code/groups7
-rw-r--r--examples/code/head30
-rw-r--r--examples/code/iftest21
-rw-r--r--examples/code/importing8
-rw-r--r--examples/code/nodes20
-rw-r--r--examples/code/one8
-rw-r--r--examples/code/relationships34
-rw-r--r--examples/code/selectors28
-rw-r--r--examples/code/simpletests11
-rw-r--r--examples/code/snippets/argumentdefaults14
-rw-r--r--examples/code/snippets/classpathtest13
-rw-r--r--examples/code/snippets/dirchmod19
-rw-r--r--examples/code/snippets/filecreate11
-rw-r--r--examples/code/snippets/simpledefaults5
-rw-r--r--examples/code/snippets/simpleselector38
-rw-r--r--examples/code/svncommit13
32 files changed, 646 insertions, 0 deletions
diff --git a/examples/code/allatonce b/examples/code/allatonce
new file mode 100644
index 000000000..2857b9b62
--- /dev/null
+++ b/examples/code/allatonce
@@ -0,0 +1,13 @@
+# $Id$
+
+define thingie {
+ file { "/tmp/classtest": create => true, mode => 755 }
+ #testing {}
+}
+
+class testing {
+ thingie { "componentname": }
+}
+
+#component {}
+testing { "testingname": }
diff --git a/examples/code/assignments b/examples/code/assignments
new file mode 100644
index 000000000..3edcef84e
--- /dev/null
+++ b/examples/code/assignments
@@ -0,0 +1,11 @@
+# $Id$
+
+$goodness = sunos
+
+$subvariable = $goodness
+
+$yayness = "this is a string of text"
+
+#$sleeper = service { sleeper:
+# running => "1"
+#}
diff --git a/examples/code/classing b/examples/code/classing
new file mode 100644
index 000000000..8f9477721
--- /dev/null
+++ b/examples/code/classing
@@ -0,0 +1,35 @@
+# $Id$
+
+# define the server as a class
+
+import "components"
+
+class base() {
+ # how do i handle components that don't take arguments? do they still
+ # require a name?
+ sudo { }
+}
+
+class server inherits base {
+ file { "/tmp/puppetfiletest":
+ create => true
+ }
+}
+
+class webserver(docroot) inherits server {
+ apache {
+ php => false,
+ docroot => $docroot,
+ user => http,
+ group => http
+ }
+}
+
+class sleepserver(path) inherits server {
+ sleeper {
+ path => $path,
+ mode => 644
+ }
+}
+
+# see 'nodes' for how to handle nodes
diff --git a/examples/code/components b/examples/code/components
new file mode 100644
index 000000000..efedf75e3
--- /dev/null
+++ b/examples/code/components
@@ -0,0 +1,73 @@
+# $Id$
+
+# i still have no 'require'-like functionality, and i should also
+# have 'recommend'-like functionality...
+define apache(php,docroot,user,group) {
+ package { apache:
+ version => "2.0.53"
+ }
+ service { apache:
+ running => true
+ }
+
+
+ # this definitely won't parse
+ if $php == "true" {
+ # this needs to do two things:
+ # - mark a dependency
+ # - cause this apache component to receive refresh events generated by php
+ #require("php")
+ $var = value
+ }
+
+ #file { "../examples/root/etc/configfile":
+ # owner => $user
+ #}
+}
+
+define sudo() {
+ package { sudo:
+ version => "1.6.8p7"
+ }
+ file { "/etc/sudoers":
+ owner => root,
+ group => root,
+ mode => "440"
+ }
+}
+
+define ssh {
+ package { ssh:
+ version => "3.4.4.4"
+ }
+ service { "sshd":
+ running => true
+ }
+}
+
+define sleeper(path,mode) {
+ Service {
+ path => "../examples/root/etc/init.d"
+ }
+
+ service { sleeper:
+ running => true,
+ path => "../examples/root/etc/init.d"
+ }
+ file { $path:
+ mode => $mode
+ }
+ $files = ["/tmp/testness","/tmp/funtest"]
+ file { $files:
+ create => true
+ }
+}
+
+#apache { "test":
+# php => false,
+# docroot => "/export/html",
+# user => "www-data",
+# group => "www-data"
+#}
+
+#ssh { "yucko":}
diff --git a/examples/code/execs b/examples/code/execs
new file mode 100644
index 000000000..44f133098
--- /dev/null
+++ b/examples/code/execs
@@ -0,0 +1,16 @@
+$path = "/usr/bin:/bin"
+
+exec { "mkdir -p /tmp/fakedir":
+ path => $path
+}
+
+exec { "rm -rf /tmp/fakedir":
+ path => $path
+}
+
+exec { "touch /this/directory/does/not/exist":
+ path => $path,
+ returns => 1
+}
+
+
diff --git a/examples/code/facts b/examples/code/facts
new file mode 100644
index 000000000..fcfec2c0d
--- /dev/null
+++ b/examples/code/facts
@@ -0,0 +1,22 @@
+# $Id$
+
+# DISABLED
+
+# facts are now added to the top scope (e.g., operatingsystem and macaddress)
+
+# these facts have to get defined by the server onto the client before
+# we can retrieve their values
+#fact { "videocard":
+# interpreter => "/bin/sh",
+# code => "lspci | grep VGA",
+# os => "Linux"
+#}
+$testing = "value"
+$operatingsystem = fact("operatingsystem")
+$fact = addfact(
+ name => "videocard",
+ interpreter => "/bin/sh",
+ code => "lspci | grep VGA",
+ os => "Linux"
+)
+$card = fact("videocard")
diff --git a/examples/code/failers/badclassnoparam b/examples/code/failers/badclassnoparam
new file mode 100644
index 000000000..a0397aacc
--- /dev/null
+++ b/examples/code/failers/badclassnoparam
@@ -0,0 +1,10 @@
+class comp() {
+ file { "/etc/passwd":
+ mode => 644
+ }
+}
+
+# this argument is invalid, thus we should get a falure
+comp {
+ fakearg => "yay"
+}
diff --git a/examples/code/failers/badclassparam b/examples/code/failers/badclassparam
new file mode 100644
index 000000000..4c9ff6199
--- /dev/null
+++ b/examples/code/failers/badclassparam
@@ -0,0 +1,10 @@
+class comp(arg1) {
+ file { "/etc/passwd":
+ mode => 644
+ }
+}
+
+# i've specified an arg but it's an invalid one
+comp {
+ fakearg => "yay"
+}
diff --git a/examples/code/failers/badcompnoparam b/examples/code/failers/badcompnoparam
new file mode 100644
index 000000000..fd25c9445
--- /dev/null
+++ b/examples/code/failers/badcompnoparam
@@ -0,0 +1,9 @@
+define comp() {
+ file { "/etc/passwd":
+ mode => 644
+ }
+}
+
+comp {
+ fakearg => "yay"
+}
diff --git a/examples/code/failers/badcompparam b/examples/code/failers/badcompparam
new file mode 100644
index 000000000..283d54014
--- /dev/null
+++ b/examples/code/failers/badcompparam
@@ -0,0 +1,9 @@
+define comp(arg1) {
+ file { "/etc/passwd":
+ mode => 644
+ }
+}
+
+comp {
+ fakearg => "yay"
+}
diff --git a/examples/code/failers/badtypeparam b/examples/code/failers/badtypeparam
new file mode 100644
index 000000000..4634f2052
--- /dev/null
+++ b/examples/code/failers/badtypeparam
@@ -0,0 +1,3 @@
+file { "/etc/passwd":
+ fakeparam => 644
+}
diff --git a/examples/code/file.bl b/examples/code/file.bl
new file mode 100644
index 000000000..41d80b53d
--- /dev/null
+++ b/examples/code/file.bl
@@ -0,0 +1,11 @@
+# $Id$
+
+file {
+ "/tmp/atest": create => true, mode => 755;
+ "/tmp/btest": create => true, mode => 755
+}
+
+file {
+ "/tmp/ctest": create => true;
+ "/tmp/dtest": create => true;
+}
diff --git a/examples/code/filedefaults b/examples/code/filedefaults
new file mode 100644
index 000000000..cb005c093
--- /dev/null
+++ b/examples/code/filedefaults
@@ -0,0 +1,10 @@
+# $Id$
+
+File {
+ mode => 755,
+ recurse => true
+}
+
+file { "/tmp/filedefaultstest":
+ create => true
+}
diff --git a/examples/code/fileparsing b/examples/code/fileparsing
new file mode 100644
index 000000000..f9766b9f6
--- /dev/null
+++ b/examples/code/fileparsing
@@ -0,0 +1,116 @@
+# $Id$
+
+# this will eventually parse different config files
+
+# this creates the 'passwd' type, but it does not create any instances
+filetype { "passwd":
+ linesplit => "\n",
+ escapednewlines => false
+}
+
+
+# this creates the 'PasswdUser' type, but again, no instances
+filerecord { "user":
+ filetype => passwd,
+ fields => [name, password, uid, gid, gcos, home, shell],
+ namevar => name,
+ splitchar => ":"
+
+}
+
+filetype { ini:
+ linesplit => "\n\n"
+}
+
+# ini files are different because we don't really care about validating fields
+# or at least, we can't do it for most files...
+filerecord { "initrecord":
+ filetype => ini,
+ fields => [name, password, uid, gid, gcos, home, shell],
+ namevar => name,
+ splitchar => ":"
+
+}
+
+# this won't work for multiple record types, will it?
+# or at least, it requires that we specify multiple times
+# ah, and it doesn't specify which of the available record types
+# it works for...
+passwd { user:
+ complete => true, # manage the whole file
+ path => "/etc/passwd"
+}
+
+user { yaytest:
+ password => x,
+ uid => 10000,
+ gid => 10000,
+ home => "/home/yaytest",
+ gcos => "The Yaytest",
+ shell => "/bin/sh"
+}
+ # there seems to be an intrinsic problem here -- i've got subtypes that only
+ # make sense when an instance of the super type already exists, and i need
+ # to associate the instances of the subtype with the instances of the supertype
+ # even if i created the parsers manually, I'd have the same problem
+
+# this is the crux of it -- i want to be able to say 'user' here without having
+# to specify the file, which leaves two options:
+# 1) associate the record type with a filetype instance (BAD)
+# 2) once the filetype and record type are created, have another command
+# that specifically creates a filetype instance and gives names for instances
+# of its record types
+
+define syslog {
+
+ # create a new type, with all defaults
+ filetype { "syslog":
+ escapednewlines => true
+ }
+
+ filerecord { "log":
+ filetype => syslog,
+ regex => "^([^#\s]+)\s+(\S+)$",
+ joinchar => "\t",
+ fields => [logs, dest]
+ }
+
+ # these two should just be supported within the filetypes
+ filerecord { "comment":
+ filetype => syslog,
+ regex => "^(#.*)$",
+ joinchar => "s",
+ fields => [comment]
+ }
+
+ filerecord { "blank":
+ filetype => syslog,
+ regex => "^(\s*)$",
+ joinchar => "s",
+ fields => blank
+ }
+}
+
+define cron {
+ filetype { "usercrontab":
+ }
+
+ # this won't actually work, of course
+ filerecord { "cronjob":
+ filetype => crontab,
+ regex => "^([^#\s]+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.+)$",
+ joinchar => " ",
+ fields => [minute, hour, day, month, weekday, command],
+ defaults => ["*", "*", "*", "*", "*", nil],
+ optional => [minute, hour, day, month, weekday]
+ }
+
+ crontab { "luke":
+ }
+}
+
+# XXX this doesn't work in the slightest
+define crontab(name,path) {
+ usercrontab { "${path}/${name}":
+ }
+}
diff --git a/examples/code/filerecursion b/examples/code/filerecursion
new file mode 100644
index 000000000..b7d8278c2
--- /dev/null
+++ b/examples/code/filerecursion
@@ -0,0 +1,15 @@
+# $Id$
+
+file { "/tmp/dirtest/b/a":
+ mode => 755,
+}
+
+file { "/tmp/dirtest":
+ mode => 755,
+ recurse => true,
+}
+
+file { "/tmp/dirtest/b/b":
+ mode => 644,
+}
+
diff --git a/examples/code/functions b/examples/code/functions
new file mode 100644
index 000000000..8e95c3a72
--- /dev/null
+++ b/examples/code/functions
@@ -0,0 +1,3 @@
+# $Id$
+
+$yaytest = fact("operatingsystem")
diff --git a/examples/code/groups b/examples/code/groups
new file mode 100644
index 000000000..35505a2eb
--- /dev/null
+++ b/examples/code/groups
@@ -0,0 +1,7 @@
+# $Id$
+
+# there need to be two forms of adding to groups:
+# add the current host to a group, and add a list of hosts to a
+# group by name
+
+$group = "crap"
diff --git a/examples/code/head b/examples/code/head
new file mode 100644
index 000000000..0b7a6c288
--- /dev/null
+++ b/examples/code/head
@@ -0,0 +1,30 @@
+# $Id$
+
+# this file is responsible for importing all of the files we want to actually test
+
+# these are all of the simple tests
+import "simpletests"
+import "assignments"
+import "selectors"
+import "iftest"
+import "importing"
+import "execs"
+import "filedefaults"
+
+# facts are now imported into the top of the namespace
+#import "facts"
+
+# obsoleted
+#import "functions"
+
+# files we no longer need to import directly, or at all in some cases
+#import "one"
+#import "classing"
+#import "components"
+#import "file.bl"
+#import "fileparsing.disabled"
+#import "groups"
+
+# this imports the more complex files
+import "allatonce" # imports classing and components
+import "nodes" # imports classing and components
diff --git a/examples/code/iftest b/examples/code/iftest
new file mode 100644
index 000000000..bc9d9cff1
--- /dev/null
+++ b/examples/code/iftest
@@ -0,0 +1,21 @@
+# $Id$
+$variable = "value"
+
+$cooltest = $variable ? {
+ other => yayness,
+ value => goodtest
+}
+
+if $variable == "other" {
+ $cooltest = "yayness"
+ $platform = $operatingsystem
+} elsif $variable == "value" {
+ $cooltest = "goodtest"
+ $platform = $operatingsystem
+} else {
+ $goodness = $operatingsystemrelease
+}
+
+if "value" == "value" {
+ $booyah = "value"
+}
diff --git a/examples/code/importing b/examples/code/importing
new file mode 100644
index 000000000..f02604109
--- /dev/null
+++ b/examples/code/importing
@@ -0,0 +1,8 @@
+# $Id$
+
+#import "groups"
+# testing import loops
+import "importing"
+
+$name = "value"
+$system = $operatingsystem
diff --git a/examples/code/nodes b/examples/code/nodes
new file mode 100644
index 000000000..42488e689
--- /dev/null
+++ b/examples/code/nodes
@@ -0,0 +1,20 @@
+# $Id$
+
+# define nodes
+
+#service.setpath("../examples/root/etc/init.d")
+
+Service {
+ path => "../examples/root/etc/init.d"
+}
+
+import "classing"
+
+sleepserver {
+ path => $operatingsystem ? {
+ sunos => "../examples/root/etc/configfile",
+ hpux => "../examples/other/etc/configfile",
+ default => "../examples/root/etc/configfile"
+ },
+ schedule => true
+}
diff --git a/examples/code/one b/examples/code/one
new file mode 100644
index 000000000..452d32f3e
--- /dev/null
+++ b/examples/code/one
@@ -0,0 +1,8 @@
+# $Id$
+
+# this service doesn't actually exist, so we noop it
+# and this way, we can test noop :)
+service { "funtest":
+ running => "0",
+ noop => true
+}
diff --git a/examples/code/relationships b/examples/code/relationships
new file mode 100644
index 000000000..f2319d5e4
--- /dev/null
+++ b/examples/code/relationships
@@ -0,0 +1,34 @@
+# $Id$
+
+#service.setpath("../examples/root/etc/init.d")
+#puppet.statefile("/tmp/puppetstate")
+$path = "../examples/root/etc/configfile"
+ path => "../examples/root/etc/init.d"
+
+
+define files {
+ file { "/tmp/yaytest":
+ create => true,
+ mode => 755
+ }
+ file { "/tmp/exists":
+ checksum => md5
+ }
+}
+
+define sleeper {
+ file { $path:
+ mode => 755
+ }
+ service { sleeper:
+ path => "../examples/root/etc/init.d",
+ running => 1
+ }
+}
+
+files { }
+
+sleeper {
+ require => files["yay"],
+ schedule => true
+}
diff --git a/examples/code/selectors b/examples/code/selectors
new file mode 100644
index 000000000..b1f1c63ec
--- /dev/null
+++ b/examples/code/selectors
@@ -0,0 +1,28 @@
+# $Id$
+#
+
+$platform = sunos
+
+$funtest = $platform ? {
+ sunos => yayness,
+ aix => goodness,
+ default => badness
+}
+
+# this is a comment
+
+$filename = "/tmp/yayness"
+
+$sleeper = file { $filename:
+ mode => $platform ? {
+ sunos => 644,
+ default => 755
+ },
+ create => $platform ? sunos => true
+}
+
+# i guess it has to be solved this way...
+
+$platform ? sunos => file { $filename:
+ mode => 644
+}
diff --git a/examples/code/simpletests b/examples/code/simpletests
new file mode 100644
index 000000000..6a2d5c5ff
--- /dev/null
+++ b/examples/code/simpletests
@@ -0,0 +1,11 @@
+# $Id$
+
+file {
+ "/tmp/atest": create => true;
+ "/tmp/btest": create => true
+}
+
+file {
+ "/tmp/ctest": create => true;
+ "/tmp/dtest": create => true;
+}
diff --git a/examples/code/snippets/argumentdefaults b/examples/code/snippets/argumentdefaults
new file mode 100644
index 000000000..b4081e9b0
--- /dev/null
+++ b/examples/code/snippets/argumentdefaults
@@ -0,0 +1,14 @@
+# $Id$
+
+define testargs(file, mode = 755) {
+ file { $file: create => true, mode => $mode }
+}
+
+testargs { "testingname":
+ file => "/tmp/argumenttest1"
+}
+
+testargs { "testingother":
+ file => "/tmp/argumenttest2",
+ mode => 644
+}
diff --git a/examples/code/snippets/classpathtest b/examples/code/snippets/classpathtest
new file mode 100644
index 000000000..609b3bef5
--- /dev/null
+++ b/examples/code/snippets/classpathtest
@@ -0,0 +1,13 @@
+# $Id$
+
+define component {
+ file { "/tmp/classtest": create => true, mode => 755 }
+ #testing {}
+}
+
+class testing {
+ component { "componentname": }
+}
+
+#component {}
+testing { "testingname": }
diff --git a/examples/code/snippets/dirchmod b/examples/code/snippets/dirchmod
new file mode 100644
index 000000000..0a8268fa8
--- /dev/null
+++ b/examples/code/snippets/dirchmod
@@ -0,0 +1,19 @@
+# $Id$
+
+file {
+ "/tmp/dirchmodtesta": create => directory;
+ "/tmp/dirchmodtesta/testing": create => true
+}
+
+file { "/tmp/dirchmodtesta":
+ mode => 644, recurse => true
+}
+
+file {
+ "/tmp/dirchmodtestb": create => directory;
+ "/tmp/dirchmodtestb/testing": create => true
+}
+
+file { "/tmp/dirchmodtestb":
+ mode => 600, recurse => true
+}
diff --git a/examples/code/snippets/filecreate b/examples/code/snippets/filecreate
new file mode 100644
index 000000000..7a4cdbb1e
--- /dev/null
+++ b/examples/code/snippets/filecreate
@@ -0,0 +1,11 @@
+# $Id$
+
+file {
+ "/tmp/createatest": create => true, mode => 755;
+ "/tmp/createbtest": create => true, mode => 755
+}
+
+file {
+ "/tmp/createctest": create => true;
+ "/tmp/createdtest": create => true;
+}
diff --git a/examples/code/snippets/simpledefaults b/examples/code/snippets/simpledefaults
new file mode 100644
index 000000000..a8f6190b1
--- /dev/null
+++ b/examples/code/snippets/simpledefaults
@@ -0,0 +1,5 @@
+# $Id$
+
+File { mode => 755 }
+
+file { "/tmp/defaulttest": create => true }
diff --git a/examples/code/snippets/simpleselector b/examples/code/snippets/simpleselector
new file mode 100644
index 000000000..52a06c773
--- /dev/null
+++ b/examples/code/snippets/simpleselector
@@ -0,0 +1,38 @@
+# $Id$
+
+$var = "value"
+
+file { "/tmp/snippetselectatest":
+ create => true,
+ mode => $var ? {
+ nottrue => 641,
+ value => 755
+ }
+}
+
+file { "/tmp/snippetselectbtest":
+ create => true,
+ mode => $var ? {
+ nottrue => 644,
+ default => 755
+ }
+}
+
+$othervar = "complex value"
+
+file { "/tmp/snippetselectctest":
+ create => true,
+ mode => $othervar ? {
+ "complex value" => 755,
+ default => 644
+ }
+}
+$anothervar = Yayness
+
+file { "/tmp/snippetselectdtest":
+ create => true,
+ mode => $anothervar ? {
+ Yayness => 755,
+ default => 644
+ }
+}
diff --git a/examples/code/svncommit b/examples/code/svncommit
new file mode 100644
index 000000000..350cd8580
--- /dev/null
+++ b/examples/code/svncommit
@@ -0,0 +1,13 @@
+$path = "/usr/bin:/bin"
+
+file { "/tmp/svntests":
+ recurse => true,
+ checksum => md5
+}
+
+exec { "echo 'files have been updated'":
+ cwd => "/tmp/svntests",
+ refreshonly => true,
+ require => file["/tmp/svntests"],
+ path => $path
+}