b71497126c83b31053a70bf45b5d0906030d3e82
[integration/packaging/puppet-opendaylight.git] / manifests / install.pp
1 # == Class opendaylight::install
2 #
3 # Manages the installation of OpenDaylight.
4 #
5 # There are two install methods: RPM-based and tarball-based. The resulting
6 # system state should be functionally equivalent, but we have to do more
7 # work here for the tarball method (would normally be handled by the RPM).
8 #
9 class opendaylight::install {
10   if $opendaylight::install_method == 'rpm' {
11     # Choose Yum URL based on OS (CentOS vs Fedora)
12     $base_url = $::operatingsystem ? {
13       'CentOS' => 'https://copr-be.cloud.fedoraproject.org/results/dfarrell07/OpenDaylight/epel-7-$basearch/',
14       'Fedora' => 'https://copr-be.cloud.fedoraproject.org/results/dfarrell07/OpenDaylight/fedora-$releasever-$basearch/',
15     }
16
17     # Add OpenDaylight's Yum repository
18     yumrepo { 'opendaylight':
19       # 'ensure' isn't supported with Puppet <3.5
20       # Seems to default to present, but docs don't say
21       # https://docs.puppetlabs.com/references/3.4.0/type.html#yumrepo
22       # https://docs.puppetlabs.com/references/3.5.0/type.html#yumrepo
23       baseurl  => $base_url,
24       descr    => 'OpenDaylight SDN controller',
25       gpgcheck => 0,
26       enabled  => 1,
27       before   => Package['opendaylight'],
28     }
29
30     # Install the OpenDaylight RPM
31     package { 'opendaylight':
32       ensure  => present,
33       require => Yumrepo['opendaylight'],
34     }
35   }
36   elsif $opendaylight::install_method == 'tarball' {
37     # Install Java 7
38     $package = $::osfamily ? {
39       'RedHat' => 'java-1.7.0-openjdk',
40       'Debian' => 'java7-jdk',
41     }
42     class { 'java':
43       # NB: ODL is currently in the process of moving to Java 8
44       package => $package,
45     }
46
47     # Create and configure the odl user
48     user { 'odl':
49       ensure     => present,
50       # Must be a valid dir for the auto-creation of some files
51       home       => '/opt/opendaylight/',
52       # The odl user should, at the minimum, be a member of the odl group
53       membership => 'minimum',
54       groups     => 'odl',
55       # The odl user's home dir should exist before the user is created
56       # The odl group, to which the odl user will belong, should exist
57       require    => [Archive['opendaylight'], Group['odl']],
58       # The odl user will own this dir, user should exist before we set owner
59       before     => File['/opt/opendaylight/'],
60     }
61
62     # Create and configure the odl group
63     group { 'odl':
64       ensure => present,
65       # The odl user will be a member of this group, create it first
66       # The odl user will own ODL's dir, so should exist before owner set 
67       before => [File['/opt/opendaylight/'], User['odl']],
68     }
69
70     # Download and extract the ODL tarball
71     archive { 'opendaylight':
72       ensure           => present,
73       # URL from which ODL's tarball can be downloaded
74       url              => $opendaylight::tarball_url,
75       # Will end up installing /opt/opendaylight/
76       target           => '/opt/opendaylight/',
77       # ODL doesn't provide a checksum in the expected path, would fail
78       checksum         => false,
79       # This discards top-level dir of extracted tarball
80       # Required to get proper /opt/opendaylight/ path
81       strip_components => 1,
82       # Default timeout is 120s, which may not be enough. See Issue #53:
83       # https://github.com/dfarrell07/puppet-opendaylight/issues/53
84       timeout          => 600,
85       # ODL's archive should be dl'd/extracted before we config mode/user/group
86       # The odl user will set this to their home dir, should exist before user
87       before           => [File['/opt/opendaylight/'], User['odl']],
88     }
89
90     # Set the user:group owners and mode of ODL dir
91     file { '/opt/opendaylight/':
92       # ensure=>dir and recurse=>true are required for managing recursively
93       ensure  => 'directory',
94       recurse => true,
95       # Set user:group owners of ODL dir
96       owner   => 'odl',
97       group   => 'odl',
98       # The ODL archive we're modifying should exist
99       # Since ODL's dir is owned by odl:odl, that user:group should exist
100       require => [Archive['opendaylight'], Group['odl'], User['odl']],
101     }
102
103     # Systemd vs upstart config depends on OS family
104     if ( $::osfamily == 'RedHat' ) {
105       # Download ODL systemd .service file and put in right location
106       archive { 'opendaylight-systemd':
107         ensure           => present,
108         url              => $opendaylight::unitfile_url,
109         # Will end up installing /usr/lib/systemd/system/opendaylight.service
110         target           => '/usr/lib/systemd/system/',
111         # Required by archive mod for correct exec `creates` param
112         root_dir         => 'opendaylight.service',
113         # ODL doesn't provide a checksum in the expected path, would fail
114         checksum         => false,
115         # This discards top-level dir of extracted tarball
116         # Required to get proper /opt/opendaylight-<version> path
117         strip_components => 1,
118         # May end up with an HTML redirect output in a text file without this
119         # Note that the curl'd down file would still have a .tar.gz name
120         follow_redirects => true,
121         # Should exist before we try to set its user/group/mode
122         before           => File['/usr/lib/systemd/system/opendaylight.service'],
123       }
124
125       # Set the user:group owners and mode of ODL's systemd .service file
126       file { '/usr/lib/systemd/system/opendaylight.service':
127         # It should be a normal file
128         ensure  => 'file',
129         # Set user:group owners of ODL systemd .service file
130         owner   => 'root',
131         group   => 'root',
132         # Set mode of ODL systemd .service file
133         mode    => '0644',
134         # Should happen after the ODL systemd .service file has been extracted
135         require => Archive['opendaylight-systemd'],
136       }
137     }
138     elsif ( $::osfamily == 'Debian' ) {
139       file { '/etc/init/opendaylight.conf':
140         # It should be a normal file
141         ensure  => 'file',
142         # Set user:group owners of ODL upstart file
143         # NB: Unverfied, not sure if this is correct for upstart
144         owner   => 'root',
145         group   => 'root',
146         # Set mode of ODL upstart file
147         # NB: Unverfied, not sure if this is correct for upstart
148         mode    => '0644',
149         # Use Puppet URL for Travis. File stored in opendaylight/files/
150         content => 'puppet:///modules/opendaylight/upstart.odl.conf'
151       }
152     }
153     else {
154       fail("Unsupported OS family: ${::osfamily}")
155     }
156   }
157   else {
158     fail("Unknown install method: ${opendaylight::install_method}")
159   }
160 }