c5dce1be02a524116600314aa661ad783604ea4b
[genesis.git] / fuel / build / f_ntp / puppet / modules / opnfv / manifests / ntp.pp
1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 # stefan.k.berg@ericsson.com
4 # jonas.bjurel@ericsson.com
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 # Class: Ntp
12 #
13 # Add Ntp content passed through astute.yaml into ntp.conf depending on the role
14 #
15 # Suitable yaml content:
16 # <begin>
17 # opnfv:
18 #   ntp:
19 #     controller: |
20 #      line 1
21 #      line 2
22 #    compute: |
23 #      line 1
24 #      line 2
25 # <end>
26 #
27 #
28 #
29
30 class opnfv::ntp(
31   $file='/etc/ntp.conf'
32 ) {
33
34   case $::operatingsystem {
35         centos, redhat: {
36           $service_name = 'ntpd'
37         }
38         debian, ubuntu: {
39           $service_name = 'ntp'
40         }
41   }
42
43   if $::fuel_settings['role'] {
44     if ($::fuel_settings['opnfv'] and
45     $::fuel_settings['opnfv']['ntp']) {
46       case $::fuel_settings['role'] {
47         /controller/: {
48           if $::fuel_settings['opnfv']['ntp']['controller'] {
49             $template = 'opnfv/ntp.conf.controller.erb'
50             $file_content = $::fuel_settings['opnfv']['ntp']['controller']
51           }
52         }
53         /compute/:    {
54           if $::fuel_settings['opnfv']['ntp']['compute'] {
55             $template = 'opnfv/ntp.conf.compute.erb'
56             $file_content = $::fuel_settings['opnfv']['ntp']['compute']
57           }
58         }
59       }
60     }
61   }
62
63   if $file_content {
64     package { 'ntp':
65       ensure => installed,
66     }
67
68     file { $file:
69       content => template($template),
70       notify  => Service['ntp'],
71     }
72
73     service { 'ntp':
74       ensure  => running,
75       name    => $service_name,
76       enable  => true,
77       require => [ Package['ntp'], File[$file]]
78     }
79   }
80 }