aboutsummaryrefslogtreecommitdiff
path: root/manifests/instance.pp
blob: c48634d72240ab903cdd1d673d303b8a9c4f0966 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
define ikiwiki::instance(
  $ensure                    = 'present',
  $base_url                  = $domain,
  $description               = $title,
  $adminuser                 = 'yourname',
  $adminemail                = 'me@example.org',
  $account_creation_password = false,
  $add_plugins               = false,
  $disable_plugins           = false,
  $protocol                  = 'https',
  $owner                     = $name,
  $group                     = $name,
  $cgi                       = '1',
  $discussion                = '1',
  $manage_ssh_key            = false,
  $home                      = "/home/${owner}",
) {
  case $ensure {
    'present': {
      file { "/etc/ikiwiki/$name.setup":
        ensure  => present,
        content => template('ikiwiki/ikiwiki.setup.erb'),
        owner   => root,
        group   => $group,
        mode    => 640,
        notify  => Exec["ikiwiki_refresh_${name}"],
      }

      exec { "ikiwiki_refresh_${name}":
        command     => "/usr/local/sbin/ikiwiki-refresh $name $owner $group",
        user        => root,
        refreshonly => true,
      }

      if !defined(File["${ikiwiki::sites_folder}/${name}"]) {
        file { "${ikiwiki::sites_folder}/${name}":
          ensure  => directory,
          owner   => root,
          group   => root,
          mode    => 0755,
        }
      }

      if !defined(File["${ikiwiki::sites_folder}/${name}/ikiwiki"]) {
        file { "${ikiwiki::sites_folder}/${name}/ikiwiki":
          ensure  => directory,
          owner   => $owner,
          group   => $group,
          recurse => true,
          require => File["${ikiwiki::sites_folder}/${name}"],
        }
      }

      file { "${ikiwiki::sites_folder}/${name}/ikiwiki_src":
        ensure  => directory,
        owner   => $owner,
        group   => $group,
        recurse => true,
        notify  => Exec["ikiwiki_refresh_${name}"],
        require => File["${ikiwiki::sites_folder}/${name}"],
      }

      file { "${ikiwiki::git_folder}/${name}.git/hooks/post-update":
        ensure  => present,
        owner   => $owner,
        group   => $ikiwiki::git_implementation,
        mode    => 6550,
        require => File["/etc/ikiwiki/$name.setup",
                        "${ikiwiki::sites_folder}/${name}/ikiwiki",
                        "${ikiwiki::sites_folder}/${name}/ikiwiki_src"],
      }

      file { "${ikiwiki::sites_folder}/${name}/ikiwiki/ikiwiki.cgi":
        ensure  => present,
        owner   => $owner,
        group   => $ikiwiki::www_user,
        mode    => 6550,
        require => File["/etc/ikiwiki/$name.setup",
                        "${ikiwiki::sites_folder}/${name}/ikiwiki",
                        "${ikiwiki::sites_folder}/${name}/ikiwiki_src"],
      }
    }
    'absent': {
      file { "/etc/ikiwiki/$name.setup":
        ensure  => absent,
      }
    }
  }

  # SSH key management required a defined resource "ssh_local_key"
  if $manage_ssh_key == true {
    ssh_local_key { "ikiwiki-${name}":
      ensure => $ensure,
      owner  => $owner,
      group  => $group,
      home   => $home,
      source => $ensure ? {
       'present' => "puppet:///ssh/ikiwiki/${name}_id_rsa",
        default  => undef,
      }
    }
  }
}