Puppet Plan: remediate_install

Defined in:
plans/init.pp

Summary

Install Puppet Remediate

Overview

Bolt plan to install Puppet Remediate.

Examples:

Upload license file

bolt file upload /tmp/license.json /tmp/vr-license.json -n <host> --user <user> \
          [--private_key <path to privare-key>] [--password] --no-host-key-check

Requirements check

bolt plan run remediate_install::check_requirements -n <host> --run-as root --user <user> \
          [--private_key <path to privare-key>] [--password] --no-host-key-check

Remediate installation

bolt plan run remediate_install install_docker=y init_swarm=y license_file=/tmp/license.json \
      install_compose=y install_remediate=y configure_firewall=y -n <host> --run-as root \
      --user <user> [--private_key <path to privare-key>] [--password] --no-host-key-check \
      [--sudo-password [PASSWORD]]

Parameters:

  • nodes (TargetSpec)

    The target nodes

  • install_docker (Enum['y', 'n']) (defaults to: 'y')

    Flag fpr Docker install. Valid input: ‘y’ or ‘no’

  • init_swarm (Enum['y', 'n']) (defaults to: 'y')

    Initialize Docker Swarm during installation. This will initialize a first manager swarm node. Valid input: ‘y’ or ‘n’

  • install_compose (Enum['y', 'n']) (defaults to: 'y')

    Install docker-compose binary which is needed for Remediate installation. Valid input: ‘y’ or ‘n’.

  • compose_version (String) (defaults to: '1.24.1')

    The version of docker-compose to install if installation of docker-compose is requested. Please keep in mind that Remedieate needs version 1.24.1 of docker-compose at least.

  • install_remediate (Enum['y', 'n']) (defaults to: 'y')

    Install Remediate. Valid input: ‘y’ or ‘n’

  • configure_firewall (Enum['y', 'n']) (defaults to: 'n')

    Serup a firewall with all rules needed for Remediate. If unsure please set this parameter to no and do the firewall configuration yourself. If you manage the firewall on the box with Puppet or some other tool please set this parameter to ‘n’. Valid input: ‘y’ or ‘n’

  • license_file (String) (defaults to: undef)

    Full qualified filename of the Remediate license file on your local system. Upload will be done by installer.

  • docker_users (Array) (defaults to: ['centos'])

    Users to add to the docker group

  • compose_install_path (String) (defaults to: '/usr/local/bin')

    Path where to install docker-compose binary

  • win_install_dir (String) (defaults to: 'C:/Users/Administrator/remediate')

    Directory where to install Remediate on Windows boxes

  • unix_install_dir (String) (defaults to: '/opt/remediate')

    Directory where to install Remediate on Unix systems

  • enforce_system_requirements (Boolean) (defaults to: true)

    Set to true the installer breaks if the system requirements for Remediate are not met.

  • noop_mode (Boolean) (defaults to: false)

    Run apply commands in noop mode. If set to true no changes will be made to the system

  • docker_ee (Boolean) (defaults to: false)

    Flag to install Docker Enterprise. Must be set to true on Windows boxes.



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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'plans/init.pp', line 72

plan remediate_install (
  TargetSpec $nodes,
  Enum['y', 'n'] $install_docker       = 'y',
  Enum['y', 'n'] $init_swarm           = 'y',
  Enum['y', 'n'] $install_compose      = 'y',
  Enum['y', 'n'] $install_remediate    = 'y',
  Enum['y', 'n'] $configure_firewall   = 'n',
  String $license_file                 = undef,
  Array $docker_users                  = ['centos'],
  String $compose_version              = '1.24.1',
  String $compose_install_path         = '/usr/local/bin',
  String $win_install_dir              = 'C:/Users/Administrator/remediate',
  String $unix_install_dir             = '/opt/remediate',
  Boolean $enforce_system_requirements = true,
  Boolean $noop_mode                   = false,
  Boolean $docker_ee                   = false,
) {
  get_targets($nodes).each |$target| {

    $target.apply_prep()
    $myfacts = facts($target)

    if(($myfacts['kernel'].downcase() == 'windows') and ($docker_ee == false)) {
      fail_plan('Docker installation on Windows systems require Docker EE version!')
    }

    # check hardware platform
    if($myfacts['os']['hardware'] != 'x86_64') {
      if($enforce_system_requirements) {
        fail_plan("Remediate is not supported on ${myfacts['hardwaremodel']} hardware")
      } else {
        crit("Remediate is not supported on ${myfacts['hardwaremodel']} hardware")
      }
    }

    # check os version
    case $myfacts['os']['name'] {
      'RedHat', 'CentOS':  {
        if($myfacts['os']['release']['major'] < '7') {
          if($enforce_system_requirements) {
            fail_plan("Remediate is not supported on Redhat/CentOS version ${myfacts['os']['releae']['major']}. It has to be at least 7.")
          } else {
            crit("Remediate is not supported on Redhat/CentOS version ${myfacts['os']['releae']['major']}. It has to be at least 7.")
          }
        }
      }
      'Debian':            {
        if($myfacts['os']['release']['major'] < '8') {
          if($enforce_system_requirements) {
            fail_plan("Remediate is not supported on Debian version ${myfacts['os']['releae']['major']}. It has to be at least 8.")
          } else {
            crit("Remediate is not supported on Debian version ${myfacts['os']['releae']['major']}. It has to be at least 8.")
          }
        }
      }
      'Ubuntu':            {
        if($myfacts['os']['release']['major'] < '14.04') {
          if($enforce_system_requirements) {
            fail_plan("Remediate is not supported on Ubuntu version ${myfacts['os']['releae']['major']}. It has to be at least 14.04.")
          } else {
            crit("Remediate is not supported on Ubuntu version ${myfacts['os']['releae']['major']}. It has to be at least 14.04.")
          }
        }
      }
      'Windows':           {
        if($myfacts['os']['release']['major'] != '10') {
          $msg = "Remediate is not supported on Windows version ${myfacts['os']['release']['major']}. It is only supported on Windows 10."
          if($enforce_system_requirements) {
            fail_plan($msg)
          } else {
            crit($msg)
          }
        }
      }
      default:             {
        if($enforce_system_requirements) {
          fail_plan("OS ${myfacts['os']['name']} is not supported.")
        } else {
          crit("OS ${myfacts['os']['name']} is not supported.")
        }
      }
    }

    # check system memory
    if($myfacts['memory']['system']['total_bytes'] < 8201568256) {
      if($enforce_system_requirements) {
        fail_plan('System memory has to be at least 8 GB.')
      } else {
        crit('System memory has to be at least 8 GB.')
      }
    }

    # check cpu count
    if($myfacts['processors']['count'] < 2) {
      if($enforce_system_requirements) {
        fail_plan('Remediate need 2 cpus at minimum.')
      } else {
        crit('Remediate need 2 cpus at minimum.')
      }
    }

    out::message(' ')
    out::message('====================================================================')
    out::message(' ')
    out::message("Install docker .............. : ${install_docker}")
    out::message("     -> docker ee ........... : ${docker_ee}")
    out::message("Initialize docker swarm ..... : ${init_swarm}")
    out::message("Install docker-compose ...... : ${install_compose}")
    if($install_compose == 'y') {
      out::message("Compose install directory ... : ${compose_install_path}")
      out::message("Docker compose version ...... : ${compose_version}")
    }
    out::message("Install Remediate ........... : ${install_remediate}")
    if($install_remediate == 'y') {
      if($myfacts['kernel'] == 'Linux') {
        out::message("Remediate install directory . : ${unix_install_dir}")
      } elsif($myfacts['k4rnel'] == 'windows') {
        out::message("Remediate install directory . : ${win_install_dir}")
      }
    }
    out::message("Configure firewall .......... : ${configure_firewall}")
    out::message("Noop mode ................... : ${noop_mode}")
    out::message("Enforce system requirements . : ${enforce_system_requirements}")
    out::message(' ')
    out::message('====================================================================')
    out::message(' ')

    # run Remediate installation steps
    if($install_docker == 'y') {
      # install docker and additional rpm packages
      out::message('installing docker')
      without_default_logging() || {
        apply($target, _catch_errors => true, _noop => $noop_mode, _run_as => root) {
          class { 'remediate_install::install::docker':
            docker_users => $docker_users,
            docker_ee    => $docker_ee,
          }
        }
      }
    }

    if($init_swarm == 'y') {
      out::message('initializing docker swarm')
      without_default_logging() || {
        apply($target, _catch_errors => true, _noop => $noop_mode, _run_as => root) {
          docker::swarm {'swarm':
            init => true,
          }
        }
      }
    }

    # check for docker compose and install if not present
    if($install_compose == 'y') {
      out::message('installing docker compose')
      without_default_logging() || {
        apply($target, _catch_errors => true, _noop => $noop_mode, _run_as => root) {
          if($facts['kernel'].downcase() == 'windows') {
            $compose_params = {
              'ensure'  => present,
              'version' => $compose_version,
            }
          } else {
            $compose_params = {
              ensure       => present,
              version      => $compose_version,
              install_path => $compose_install_path,
            }
          }

          class {'docker::compose':
            *  => $compose_params,
          }
        }
      }
      $compose_path = $compose_install_path
    } else {
      $compose_path = ''
    }

    # configure firewall
    if($configure_firewall == 'y') {
      without_default_logging() || {
        $res = run_task('remediate_install::check_firewall', $nodes)
        $fwd = $res.first
        if($fwd['firewall'] == 'disabled') {
          out::message('configuring firewall')
          apply($target, _catch_errors => true, _noop => $noop_mode, _run_as => root) {
            class { 'remediate_install::firewall':
            }
          }
        } else {
          warning('Firewall already running on host, no configuration will be done')
        }
      }
    }

    # install remedeate
    if($install_remediate == 'y') {
      case $myfacts['kernel'].downcase() {
        'linux': {
          $install_dir = $unix_install_dir
        }
        'windows': {
          $install_dir = $win_install_dir
        }
        default: {
          fail_plan("unknown system kernel ${myfacts['kernel']}")
        }
      }

      if(file::exists($license_file)) {
        if(file::readable($license_file)) {
          info('licenfile is readable')
        } else {
          fail_plan("License file ${license_file} is not readbale!")
        }
      } else {
        fail_plan("License file ${license_file} does not exists!")
      }

      if($myfacts['kernel'].downcase() == 'windows') {
        $remote_license_file = 'C:/Users/Administrator/Documents/license.json'
      } else {
        $remote_license_file = '/tmp/license.json'
      }

      upload_file($license_file, $remote_license_file, $target, "Uploading license file ${license_file} to ${remote_license_file}")

      out::message("installing Puppet Remediate in ${install_dir}")

      without_default_logging() || {
        apply($target, _catch_errors => true, _noop => $noop_mode, _run_as => root) {
          class { 'remediate_install::install':
            install_dir  => $install_dir,
            license_file => $remote_license_file,
            compose_dir  => $compose_path,
          }
        }
      }
    }
  }

  return('installation finished')
}