File: init.pp

package info (click to toggle)
puppet-module-joshuabaird-ipaclient 2.5.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 168 kB
  • sloc: ruby: 259; sh: 10; makefile: 10
file content (267 lines) | stat: -rw-r--r-- 7,418 bytes parent folder | download | duplicates (3)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# == Class: ipaclient
#
# You can use this class to configure your servers to use FreeIPA
#
# === Parameters
#
# Minimum Parameters (if relying on DNS discovery):
#   password
#
# All Parameters:
#
# $automount::             Enable automount
#                          Default: false
#
# $automount_location::    Automounter location
#
# $automount_server::      Automounter server
#
# $domain::                Domain, e.g. pixiedust.com
#
# $fixed_primary::         Used a fixed primary
#                          Default: false
#
# $force::                 Enable "forced" installation mode
#                          Default: false
#
# $installer::             IPA install command
#
# $mkhomedir::             Automatically make /home/<user> or not
#                          Default: true
#
# $needs_sudo_config       Manually configure sudo? (Boolean)
#
# $ntp::                   Manage and configure ntpd?
#                          Default: true
#
# $options::               Additional command-line options to pass directly to
#                          installer
#
# $package::               Package to install
#
# $password::              One-time password, or registration user's password
#
# $principal::             Kerberos principal when not using one-time passwords
#
# $realm::                 Realm, e.g. PIXIEDUST.COM
#
# $server::                Can be array or string of IPA servers
#
# $ssh::                   Enable SSH Integation
#                          Default: true
#
# $sshd::                  Enable SSHD Integration
#                          Default: true
#
# $sudo::                  Enable sudoers management
#                          Default: true
#
# $hostname::              Client FQDN
#
# $force_join::            Forces domain joining if host already joined once
#
# === Examples
#
# Discovery register example:
#
#  class { 'ipaclient':
#       password         => "rainbows"
#  }
#
# More complex:
#
#  class { 'ipaclient':
#       mkhomedir          => false,
#       automount          => true,
#       automount_location => "home",
#       password           => "unicorns",
#       domain             => "pixiedust.com",
#       realm              => "PIXEDUST.COM",
#       server             => ["ipa01.pixiedust.com", "ipa02.pixiedust.com"]
#  }
#
# === Authors
#
# Stephen Benjamin <stephen@bitbin.de>
#
# === Copyright
#
# Copyright 2014 Stephen Benjamin.
# Released under the MIT License. See LICENSE for more information
#
class ipaclient (
  $automount          = $ipaclient::params::automount,
  $automount_location = $ipaclient::params::automount_location,
  $automount_server   = $ipaclient::params::automount_server,
  $domain             = $ipaclient::params::domain,
  $fixed_primary      = $ipaclient::params::fixed_primary,
  $force              = $ipaclient::params::force,
  $installer          = $ipaclient::params::installer,
  $mkhomedir          = $ipaclient::params::mkhomedir,
  $needs_sudo_config  = $ipaclient::params::needs_sudo_config,
  $ntp                = $ipaclient::params::ntp,
  $options            = $ipaclient::params::options,
  $package            = $ipaclient::params::package,
  $password           = $ipaclient::params::password,
  $principal          = $ipaclient::params::principal,
  $realm              = $ipaclient::params::realm,
  $server             = $ipaclient::params::server,
  $ssh                = $ipaclient::params::ssh,
  $sshd               = $ipaclient::params::sshd,
  $sudo               = $ipaclient::params::sudo,
  $hostname           = $ipaclient::params::hostname,
  $force_join         = $ipaclient::params::force_join
) inherits ipaclient::params {

  package { $package:
    ensure => installed,
  }

  if !str2bool($::ipa_enrolled) {
    if empty($password) {
      fail('Require at least a join password')
    } else {
      # Build the installer command:

      $opt_password = ['--password', $password]

      if is_array($server) {
        # Transform ['a','b'] -> ['--server','a','--server','b']
        $opt_server = split(join(prefix($server, '--server|'), '|'), '\|')
      } elsif !empty($server) {
        $opt_server = ['--server' ,$server]
      } else {
        $opt_server = ''
      }

      if $domain {
        $opt_domain = ['--domain', $domain]
      } else {
        $opt_domain = ''
      }

      if $hostname {
        $opt_hostname = ['--hostname', $hostname]
      } else {
        $opt_hostname = ''
      }

      if $realm {
        $opt_realm = ['--realm', $realm]
      } else {
        $opt_realm = ''
      }

      if $principal {
        $opt_principal = ['--principal', "${principal}@${realm}"]
      } else {
        $opt_principal = ''
      }

      if !str2bool($ssh) {
        $opt_ssh = '--no-ssh'
      } else {
        $opt_ssh = ''
      }

      if !str2bool($sshd) {
        $opt_sshd = '--no-sshd'
      } else {
        $opt_sshd = ''
      }

      if str2bool($fixed_primary) {
        $opt_fixed_primary = '--fixed-primary'
      } else {
        $opt_fixed_primary = ''
      }

      if str2bool($mkhomedir) {
        $opt_mkhomedir = '--mkhomedir'
      } else {
        $opt_mkhomedir = ''
      }

      if !str2bool($ntp) {
        $opt_ntp = '--no-ntp'
      } else {
        $opt_ntp = ''
      }

      if str2bool($force) {
        $opt_force = '--force'
      } else {
        $opt_force = ''
      }

      if !str2bool($sudo) {
        $opt_sudo = '--no-sudo'
      } else {
        $opt_sudo = ''
      }
      
      if str2bool($force_join) {
        $opt_force_join = '--force-join'
      } else {
        $opt_force_join = ''
      }

      # Flatten the arrays, delete empty options, and shellquote everything
      $command = shellquote(delete(flatten([$installer,$opt_realm,$opt_password,
                            $opt_principal,$opt_mkhomedir,$opt_domain,$opt_hostname,
                            $opt_server,$opt_fixed_primary,$opt_ssh,$opt_sshd,$opt_ntp,$opt_sudo,
                            $opt_force,$opt_force_join,$options,'--unattended']), ''))

      exec { 'ipa_installer':
        command => $command,
        unless  => "/usr/sbin/ipa-client-install -U 2>&1 \
          | /bin/grep -q 'already configured'",
        require => Package[$package],
      }

      $installer_resource = Exec['ipa_installer']

      # Include debian fixes since the installer doesn't properly
      # configure ssh and mkhomedir
      if ($::osfamily == 'Debian') {
        class { 'ipaclient::debian_fixes':
          require => $installer_resource,
        }
      }
    }
  }

  if (str2bool($sudo) and str2bool($needs_sudo_config)) {
    # If user didn't specify a server, use the fact.  Otherwise pass in
    # the first value of server parameter
    if empty($server) {
      $sudo_server = $::ipa_server
    } elsif is_array($server) {
      $sudo_server = $server[0]
    } else {
      $sudo_server = $server
    }

    # If user didn't specify a domain, use the fact.
    if empty($domain) {
      $sudo_domain = $::ipa_domain
    } else {
      $sudo_domain = $domain
    }

    class { 'ipaclient::sudoers':
      server  => $sudo_server,
      domain  => $sudo_domain,
      require => $installer_resource,
    }
  }

  if str2bool($automount) {
    class { 'ipaclient::automount':
        location => $automount_location,
        server   => $automount_server,
        require  => $installer_resource,
    }
  }
}