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