Skip to content

Commit

Permalink
install and use the certbot nginx plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfouche authored and nod0n committed Dec 15, 2021
1 parent 42f4ba8 commit 7761142
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ letsencrypt::certonly { 'foo':
}
```

#### Nginx authenticator

To request a certificate for `foo.example.com` and `bar.example.com` with the
`certonly` installer and the `nginx` authenticator:

```puppet
letsencrypt::certonly { 'foo':
domains => ['foo.example.com', 'bar.example.com'],
plugin => 'nginx',
}
```

#### Webroot plugin

To request a certificate using the `webroot` plugin, the paths to the webroots
Expand Down
28 changes: 28 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* [`letsencrypt::install`](#letsencryptinstall): Installs the Let's Encrypt client.
* [`letsencrypt::plugin::dns_rfc2136`](#letsencryptplugindns_rfc2136): Installs and configures the dns-rfc2136 plugin
* [`letsencrypt::plugin::dns_route53`](#letsencryptplugindns_route53): Installs and configures the dns-route53 plugin
* [`letsencrypt::plugin::nginx`](#letsencryptpluginnginx): install and configure the Let's Encrypt nginx plugin
* [`letsencrypt::renew`](#letsencryptrenew): Configures renewal of Let's Encrypt certificates using Certbot

#### Private Classes
Expand Down Expand Up @@ -436,6 +437,33 @@ Data type: `String[1]`

The name of the package to install when $manage_package is true.

### <a name="letsencryptpluginnginx"></a>`letsencrypt::plugin::nginx`

install and configure the Let's Encrypt nginx plugin

#### Parameters

The following parameters are available in the `letsencrypt::plugin::nginx` class:

* [`manage_package`](#manage_package)
* [`package_name`](#package_name)

##### <a name="manage_package"></a>`manage_package`

Data type: `Boolean`

Manage the plugin package.

Default value: ``true``

##### <a name="package_name"></a>`package_name`

Data type: `String`

The name of the package to install when $manage_package is true.

Default value: `'python3-certbot-nginx'`

### <a name="letsencryptrenew"></a>`letsencrypt::renew`

Configures renewal of Let's Encrypt certificates using the certbot renew command.
Expand Down
1 change: 1 addition & 0 deletions data/os/CentOS/7.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
letsencrypt::plugin::dns_rfc2136::package_name: 'python2-certbot-dns-rfc2136'
letsencrypt::plugin::dns_route53::package_name: 'python2-certbot-dns-route53'
letsencrypt::plugin::nginx::package_name: 'python2-certbot-nginx'
1 change: 1 addition & 0 deletions data/os/RedHat/7.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
letsencrypt::plugin::dns_rfc2136::package_name: 'python2-certbot-dns-rfc2136'
letsencrypt::plugin::dns_route53::package_name: 'python2-certbot-dns-route53'
letsencrypt::plugin::nginx::package_name: 'python2-certbot-nginx'
11 changes: 11 additions & 0 deletions manifests/certonly.pp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@
]
}

'nginx': {
require letsencrypt::plugin::nginx

if $ensure == 'present' {
$_domains = join($domains, '\' -d \'')
$plugin_args = "--cert-name '${cert_name}' -d '${_domains}'"
} else {
$plugin_args = "--cert-name '${cert_name}'"
}
}

default: {
if $ensure == 'present' {
$_domains = join($domains, '\' -d \'')
Expand Down
14 changes: 14 additions & 0 deletions manifests/plugin/nginx.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# @summary install and configure the Let's Encrypt nginx plugin
#
# @param manage_package Manage the plugin package.
# @param package_name The name of the package to install when $manage_package is true.
class letsencrypt::plugin::nginx (
Boolean $manage_package = true,
String $package_name = 'python3-certbot-nginx',
) {
if $manage_package {
package { $package_name:
ensure => installed,
}
}
}
23 changes: 23 additions & 0 deletions spec/acceptance/letsencrypt_plugin_nginx_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'spec_helper_acceptance'

describe 'letsencrypt::plugin::nginx' do
context 'with default values' do
pp = <<-PUPPET
class { 'letsencrypt' :
email => '[email protected]',
config => {
'server' => 'https://acme-staging.api.letsencrypt.org/directory',
},
}
class { 'letsencrypt::plugin::nginx':
}
PUPPET

it 'installs letsencrypt and nginx plugin without error' do
apply_manifest(pp, catch_failures: true)
end
it 'installs letsencrypt and nginx idempotently' do
apply_manifest(pp, catch_changes: true)
end
end
end
38 changes: 38 additions & 0 deletions spec/classes/plugin/nginx_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'spec_helper'

describe 'letsencrypt::plugin::nginx' do
on_supported_os.each do |os, facts|
context "on #{os} based operating systems" do
let(:facts) { facts }
let(:params) { {} }
let(:pre_condition) do
<<-PUPPET
class { 'letsencrypt':
email => '[email protected]',
}
PUPPET
end

context 'with default parameters' do
it { is_expected.to compile.with_all_deps }

package_name =
if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '7'
'python2-certbot-nginx'
else
'python3-certbot-nginx'
end
it 'installs the certbot nginx plugin' do
is_expected.to contain_class('letsencrypt::plugin::nginx')
is_expected.to contain_package(package_name).with_ensure('installed')
end

describe 'with manage_package => false' do
let(:params) { super().merge(manage_package: false, package_name: 'nginx-package') }

it { is_expected.not_to contain_package('nginx-package') }
end
end
end
end
end
20 changes: 20 additions & 0 deletions spec/defines/letsencrypt_certonly_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,26 @@ class { 'letsencrypt::plugin::dns_route53':
it { is_expected.to contain_exec('letsencrypt certonly foo.example.com').with_command "letsencrypt --text --agree-tos --non-interactive certonly --rsa-key-size 4096 -a dns-route53 --cert-name 'foo.example.com' -d 'foo.example.com' --dns-route53-propagation-seconds 10" }
end

context 'with nginx plugin' do
let(:title) { 'foo.example.com' }
let(:params) { { plugin: 'nginx', letsencrypt_command: 'letsencrypt' } }
let(:pre_condition) do
<<-PUPPET
class { 'letsencrypt':
email => '[email protected]',
config_dir => '/etc/letsencrypt',
}
class { 'letsencrypt::plugin::nginx':
package_name => 'irrelevant',
}
PUPPET
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('letsencrypt::plugin::nginx') }
it { is_expected.to contain_exec('letsencrypt certonly foo.example.com').with_command "letsencrypt --text --agree-tos --non-interactive certonly --rsa-key-size 4096 -a nginx --cert-name 'foo.example.com' -d 'foo.example.com'" }
end

context 'with custom plugin' do
let(:title) { 'foo.example.com' }
let(:params) { { plugin: 'apache' } }
Expand Down

0 comments on commit 7761142

Please sign in to comment.