init.pp 5.88 KB
Newer Older
Matthieu FAURE's avatar
Matthieu FAURE committed
1 2 3 4
# @summary Install NextCloud
#
# Install NextCloud
#
5 6 7
# @param nc_admin_username Username of NextCloud administrator
# @param nc_admin_password Password of NextCloud administrator
# @param nc_install_parent_dir
8 9 10
#     Absolute directory where NextCloud archive will be extracted. By design, a 'nextcloud' directory is created
# @param nc_data_parent_dir
#     Absolute directory where NextCloud data will be stored. A `data/` subdir will be created
Matthieu FAURE's avatar
Matthieu FAURE committed
11 12 13
# @param manage_apache Whether to install Apache
# @param apache_hostname If manage_apache: Hostname for the virtual host to be create
# @param apache_port If manage_apache: port Apache will listen to
14
# @param apache_default_vhost Define the created vhost as the default one
Matthieu FAURE's avatar
Matthieu FAURE committed
15
# @param php_version If manage_apache: PHP version to install
Matthieu FAURE's avatar
Matthieu FAURE committed
16
# @param manage_redis Whether to install Redis
17
# @param manage_mariadb Whether to install MariaDB
18 19 20 21 22 23 24
# @param db_hostname FQDN or IP of MariaDB host
# @param db_port Port to connect to MariaDB host
# @param db_root_password Password to give to MariaDB root user
# @param db_username MariaDB user that will be created and grant access to the DB
# @param db_password Password for MariaDB user that will connect to the DB
# @param db_database_name Name of the database that will be created and used for NextCloud
# @param db_table_prefix String to prefix tables name
Matthieu FAURE's avatar
Matthieu FAURE committed
25 26 27 28
#
# @example
#   include nextcloud
class nextcloud (
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  String                $db_password,
  String                $nc_admin_username,
  String                $nc_admin_password,
  Stdlib::Absolutepath  $nc_install_parent_dir = '/var/www',
  Stdlib::Absolutepath  $nc_data_parent_dir    = '/var/lib/nextcloud',
  String                $nc_version            = 'latest',
  Boolean               $manage_apache         = false,
  Stdlib::Host          $apache_hostname       = 'nextcloud.example.org',
  Stdlib::Port          $apache_port           = 80,
  Boolean               $apache_default_vhost  = true,
  String                $apache_user           = 'www',
  String                $php_version           = '7.2',
  Boolean               $manage_redis          = false,
  Boolean               $manage_mariadb        = false,
  Stdlib::Host          $db_hostname           = 'localhost',
  Stdlib::Port          $db_port               = 3306,
  String                $db_root_password      = 'StrongPa$$w0rdz',
  String                $db_username           = 'mariadb',
  String                $db_database_name      = 'nextcloud',
  String                $db_table_prefix       = '',
Matthieu FAURE's avatar
Matthieu FAURE committed
49 50
) {

Matthieu FAURE's avatar
Matthieu FAURE committed
51
  # Local variable
52
  $nc_download_url_base = 'https://download.nextcloud.com/server/releases'
Matthieu FAURE's avatar
Matthieu FAURE committed
53
  # TODO manage possible formats of $nextcloud_version: 'latest.tar.bz2', 'nextcloud-16.0.5.tar.bz2'...
54
  $nc_archive = "${nc_version}.tar.bz2"
55
  $nc_archive_url = "${nc_download_url_base}/${nc_archive}"
56
  $nc_install_dir = "${nc_install_parent_dir}/nextcloud" # hardcoded because archive extracts in a 'nextcloud' dir
57
  $nc_data_dir = "${nc_data_parent_dir}/data"
Matthieu FAURE's avatar
Matthieu FAURE committed
58

59
  # Install Apache + PHP-FPM and configure vhost
Matthieu FAURE's avatar
Matthieu FAURE committed
60 61 62
  if $manage_apache {

    $_fastcgi_socket = 'fcgi://127.0.0.1:9000'
63
    # ProxyPassMatch: see https://httpd.apache.org/docs/2.4/mod/mod_proxy_fcgi.html#examples
64
    $_my_custom_fragment = "ProxyPassMatch ^/.*\\.php(/.*)?\$ ${_fastcgi_socket}${nc_install_dir}/ enablereuse=on"
65

Matthieu FAURE's avatar
Matthieu FAURE committed
66 67
    # PHP + modules
    class { 'php::globals':
68
      php_version => $php_version,
Matthieu FAURE's avatar
Matthieu FAURE committed
69 70 71
    }
    -> class { 'php':
      extensions => {
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
        apcu      => {},
        bz2       => {},
        ctype     => {},
        curl      => {},
        dom       => {},
        # exif      => {}, # already installed
        gd        => {},
        iconv     => {},
        imagick   => {},
        intl      => {},
        json      => {},
        # fileinfo  => {}, # already installed
        # libxml    => {}, # already installed
        mbstring  => {},
        # openssl   => {}, # already installed
        mysql     => {},
        posix     => {},
        # session   => {}, # already installed
        simplexml => {},
        xmlreader => {},
        xmlwriter => {},
        zip       => {},
        # zlib      => {}, # already installed
Matthieu FAURE's avatar
Matthieu FAURE committed
95 96
      },
    }
97 98 99 100 101

    # Apache
    class { 'apache::mod::proxy': }
    class { 'apache::mod::proxy_fcgi': }
    apache::vhost { $apache_hostname:
102
      docroot         => $nc_install_dir,
103 104 105 106 107 108
      port            => $apache_port,
      default_vhost   => $apache_default_vhost,
      override        => 'all',
      custom_fragment => $_my_custom_fragment,
      require         => Class[php],
    }
Matthieu FAURE's avatar
Matthieu FAURE committed
109
  }
110

Matthieu FAURE's avatar
Matthieu FAURE committed
111 112
  # Install Redis
  if $manage_redis {
Matthieu FAURE's avatar
Matthieu FAURE committed
113
    include nextcloud::redis
Matthieu FAURE's avatar
Matthieu FAURE committed
114
  }
115

Matthieu FAURE's avatar
Matthieu FAURE committed
116 117
  # Install MariaDB
  if $manage_mariadb {
118
    include nextcloud::mariadb
Matthieu FAURE's avatar
Matthieu FAURE committed
119
  }
Matthieu FAURE's avatar
Matthieu FAURE committed
120

121
  # Create NextCloud directory
122 123 124 125
  file { $nc_install_parent_dir:
    ensure => directory,
  }
  -> file { $nc_install_dir:
126 127 128 129 130 131
    ensure => directory,
    owner  => $apache_user,
    group  => $apache_user,
    mode   => '0755',
  }

Matthieu FAURE's avatar
Matthieu FAURE committed
132
  # Create NextCloud *data* directory
133 134 135 136
  file { $nc_data_parent_dir:
    ensure => directory,
  }
  -> file { $nc_data_dir:
Matthieu FAURE's avatar
Matthieu FAURE committed
137 138 139 140 141 142
    ensure => directory,
    owner  => $apache_user,
    group  => $apache_user,
    mode   => '0755',
  }

Matthieu FAURE's avatar
Matthieu FAURE committed
143 144
  # Get Nextcloud archive
  archive { 'download-nextcloud-archive':
145
    ensure       => 'present',
146
    path         => "/tmp/${nc_archive}",
147
    source       => $nc_archive_url,
148
    extract      => true,
149
    extract_path => "${nc_install_parent_dir}/",
150 151
    user         => $apache_user,
    group        => $apache_user,
152
    require      => File[$nc_install_dir]
153
    # TODO add checksum verification
Matthieu FAURE's avatar
Matthieu FAURE committed
154 155
  }

156 157 158 159 160 161 162 163 164
  # Nextcloud autoconfig (unattended configuration)
  file { "${nc_install_dir}/config/autoconfig.php":
    ensure  => present,
    owner   => $apache_user,
    group   => $apache_user,
    mode    => '0640',
    content => template('nextcloud/autoconfig.php.erb'),
  }

165 166
  # TODO configure APCu + Redis in NextCloud.
  # See https://docs.nextcloud.com/server/16/admin_manual/configuration_server/caching_configuration.html#id1
Matthieu FAURE's avatar
Matthieu FAURE committed
167
}