Skip to content

Commit

Permalink
Refactor to simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoneycutt committed Apr 30, 2020
1 parent 32f14ae commit 098a2df
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 206 deletions.
11 changes: 5 additions & 6 deletions examples/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@

include caddy


file {'/var/www':
file { '/var/www':
ensure => directory,
}

caddy::vhost {'example1':
source => 'puppet:///modules/caddy/etc/caddy/config/example1.conf',
caddy::vhost { 'example1':
content => file('caddy/examples/example1.conf'),
}

caddy::vhost {'example2':
source => 'puppet:///modules/caddy/etc/caddy/config/example2.conf',
caddy::vhost { 'example2':
content => file('caddy/examples/example2.conf'),
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
46 changes: 0 additions & 46 deletions manifests/config.pp

This file was deleted.

155 changes: 149 additions & 6 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
Optional[String[1]] $systemd_ambient_capabilities = undef,
Optional[Boolean] $systemd_no_new_privileges = undef,
) {

include file_capability

case $caddy_architecture {
'x86_64', 'amd64': { $arch = 'amd64'}
'x86' : { $arch = '386' }
Expand All @@ -118,6 +121,19 @@
}
}

case $install_method {
'github': {
$caddy_url = 'https://github.com/caddyserver/caddy/releases/download'
$caddy_dl_url = "${caddy_url}/v${version}/caddy_v${version}_linux_${arch}.tar.gz"
$caddy_dl_dir = "${caddy_tmp_dir}/caddy_v${version}_linux_${$arch}.tar.gz"
}
default: {
$caddy_url = 'https://caddyserver.com/download/linux'
$caddy_dl_url = "${caddy_url}/${arch}?plugins=${caddy_features}&license=${caddy_license}&telemetry=${caddy_telemetry}"
$caddy_dl_dir = "${caddy_tmp_dir}/caddy_linux_${$arch}_custom.tar.gz"
}
}

group { $caddy_group:
ensure => present,
system => true,
Expand All @@ -131,11 +147,138 @@
home => $caddy_home,
}

contain caddy::install
contain caddy::config
contain caddy::service
file { $install_path:
ensure => directory,
owner => $caddy_user,
group => $caddy_group,
mode => '0755',
}

archive { $caddy_dl_dir:
ensure => present,
extract => true,
extract_path => $install_path,
source => $caddy_dl_url,
username => $caddy_account_id,
password => $caddy_api_key,
user => 'root',
group => 'root',
creates => "${install_path}/caddy",
cleanup => true,
notify => File_capability["${install_path}/caddy"],
require => File[$install_path],
}

file_capability { "${install_path}/caddy":
ensure => present,
capability => 'cap_net_bind_service=ep',
require => Archive[$caddy_dl_dir],
}

file { $caddy_home:
ensure => directory,
owner => $caddy_user,
group => $caddy_group,
mode => '0755',
require => Archive[$caddy_dl_dir],
notify => Service['caddy'],
}

file { $caddy_ssl_dir:
ensure => directory,
owner => $caddy_user,
group => $caddy_group,
mode => '0755',
require => Archive[$caddy_dl_dir],
notify => Service['caddy'],
}

file { $caddy_log_dir:
ensure => directory,
owner => $caddy_user,
group => $caddy_group,
mode => '0755',
require => Archive[$caddy_dl_dir],
notify => Service['caddy'],
}

file { '/etc/caddy':
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
require => Archive[$caddy_dl_dir],
notify => Service['caddy'],
}

file { '/etc/caddy/Caddyfile':
ensure => file,
owner => $caddy_user,
group => $caddy_group,
mode => '0444',
content => file('caddy/Caddyfile'),
require => Archive[$caddy_dl_dir],
notify => Service['caddy'],
}

file { '/etc/caddy/config':
ensure => directory,
purge => true,
recurse => true,
owner => $caddy_user,
group => $caddy_group,
mode => '0755',
require => Archive[$caddy_dl_dir],
notify => Service['caddy'],
}

Class['caddy::install']
-> Class['caddy::config']
~> Class['caddy::service']
case $facts['service_provider'] {
default: {
fail("service provider ${$facts['service_provider']} is not supported.")
}
'systemd': {
systemd::unit_file { 'caddy.service':
content => epp('caddy/caddy.service.epp',
{
install_path => $install_path,
caddy_user => $caddy_user,
caddy_group => $caddy_group,
caddy_log_dir => $caddy_log_dir,
caddy_ssl_dir => $caddy_ssl_dir,
caddy_home => $caddy_home,
caddy_http_port => $caddy_http_port,
caddy_https_port => $caddy_https_port,
systemd_limit_processes => $systemd_limit_processes,
systemd_private_devices => $systemd_private_devices,
systemd_capability_bounding_set => $systemd_capability_bounding_set,
systemd_ambient_capabilities => $systemd_ambient_capabilities,
systemd_no_new_privileges => $systemd_no_new_privileges,
}
),
notify => Service['caddy'],
}
}
'redhat': {
file { '/etc/init.d/caddy':
ensure => file,
content => epp('caddy/caddy.epp',
{
caddy_user => $caddy_user,
caddy_log_dir => $caddy_log_dir,
caddy_ssl_dir => $caddy_ssl_dir,
caddy_home => $caddy_home,
}
),
owner => 'root',
group => 'root',
mode => '0755',
notify => Service['caddy'],
}
}
}

service { 'caddy':
ensure => running,
enable => true,
}
}
64 changes: 0 additions & 64 deletions manifests/install.pp

This file was deleted.

72 changes: 0 additions & 72 deletions manifests/service.pp

This file was deleted.

7 changes: 5 additions & 2 deletions manifests/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
) {

include caddy

file { "/etc/caddy/config/${title}.conf":
ensure => file,
content => $content,
source => $source,
owner => $caddy::caddy_user,
group => $caddy::caddy_group,
mode => '0444',
require => Class['caddy::config'],
notify => Class['caddy::service'],
require => File['/etc/caddy/Caddyfile'],
notify => Service['caddy'],
}
}
Loading

0 comments on commit 098a2df

Please sign in to comment.