add ubuntu support
[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     if ( $::osfamily == 'RedHat' ){
104         # Download ODL systemd .service file and put in right location
105         archive { 'opendaylight-systemd':
106           ensure           => present,
107           url              => $opendaylight::unitfile_url,
108           # Will end up installing /usr/lib/systemd/system/opendaylight.service
109           target           => '/usr/lib/systemd/system/',
110           # Required by archive mod for correct exec `creates` param
111           root_dir         => 'opendaylight.service',
112           # ODL doesn't provide a checksum in the expected path, would fail
113           checksum         => false,
114           # This discards top-level dir of extracted tarball
115           # Required to get proper /opt/opendaylight-<version> path
116           strip_components => 1,
117           # May end up with an HTML redirect output in a text file without this
118           # Note that the curl'd down file would still have a .tar.gz name
119           follow_redirects => true,
120           # Should exist before we try to set its user/group/mode
121           before           => File['/usr/lib/systemd/system/opendaylight.service'],
122         }
123
124         # Set the user:group owners and mode of ODL's systemd .service file
125         file { '/usr/lib/systemd/system/opendaylight.service':
126           # It should be a normal file
127           ensure  => 'file',
128           # Set user:group owners of ODL systemd .service file
129           owner   => 'root',
130           group   => 'root',
131           # Set mode of ODL systemd .service file
132           mode    => '0644',
133           # Should happen after the ODL systemd .service file has been extracted
134           require => Archive['opendaylight-systemd'],
135         }
136     }
137     elsif ( $::osfamily == 'Debian' ){
138         file { '/etc/init/opendaylight.conf':
139           # It should be a normal file
140           ensure  => 'file',
141           # Set user:group owners of ODL upstart file
142           owner   => 'root',
143           group   => 'root',
144           # Set mode of ODL upstart file
145           mode    => '0644',
146           # Get content from template
147           content => template('opendaylight/upstart.odl.conf'),
148         }
149     }else{
150         fail("Unsupported OS family: ${::osfamily}")
151     }
152   }
153   else {
154     fail("Unknown install method: ${opendaylight::install_method}")
155   }
156 }