feat: add etcd module/role (#215)
- add etcd module - add etcd role, profile and hieradata Reviewed-on: https://git.query.consul/unkinben/puppet-prod/pulls/215
This commit was merged in pull request #215.
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
# manage etcd
|
||||
class etcd (
|
||||
Boolean $manage_user = true,
|
||||
Boolean $manage_group = true,
|
||||
Boolean $manage_package = true,
|
||||
Boolean $manage_service = true,
|
||||
String[1] $package_name = 'etcd',
|
||||
String[1] $user = 'etcd',
|
||||
String[1] $group = 'etcd',
|
||||
Stdlib::Absolutepath $config_path = '/etc/etcd',
|
||||
Stdlib::Absolutepath $config_file = "${config_path}/etcd.yaml",
|
||||
Hash $config = { 'data-dir' => '/var/lib/etcd' },
|
||||
Integer $max_open_files = 40000,
|
||||
) {
|
||||
if downcase($facts['kernel']) != 'linux' {
|
||||
fail("Module etcd only supports Linux, not ${facts['kernel']}")
|
||||
}
|
||||
if $facts['service_provider'] != 'systemd' {
|
||||
fail('Module etcd only supported on systems using systemd')
|
||||
}
|
||||
if ! $config['data-dir'] {
|
||||
fail('Module etcd requires data-dir be specified in config Hash')
|
||||
}
|
||||
|
||||
if $manage_package {
|
||||
package { $package_name:
|
||||
ensure => installed,
|
||||
}
|
||||
}
|
||||
|
||||
if $manage_user {
|
||||
user { 'etcd':
|
||||
ensure => 'present',
|
||||
name => $user,
|
||||
forcelocal => true,
|
||||
shell => '/bin/false',
|
||||
gid => $group,
|
||||
home => $config['data-dir'],
|
||||
managehome => false,
|
||||
system => true,
|
||||
before => Systemd::Unit_file['etcd.service'],
|
||||
}
|
||||
}
|
||||
if $manage_group {
|
||||
group { 'etcd':
|
||||
ensure => 'present',
|
||||
name => $group,
|
||||
forcelocal => true,
|
||||
system => true,
|
||||
before => Systemd::Unit_file['etcd.service'],
|
||||
}
|
||||
}
|
||||
|
||||
mkdir::p { $config_path: }
|
||||
mkdir::p { $config['data-dir']: }
|
||||
|
||||
file { $config_file:
|
||||
ensure => 'file',
|
||||
owner => $user,
|
||||
group => $group,
|
||||
mode => '0600',
|
||||
content => to_yaml($config),
|
||||
notify => Systemd::Unit_file['etcd.service'],
|
||||
require => Mkdir::P[$config_path],
|
||||
}
|
||||
|
||||
file { 'etcd-data-dir':
|
||||
ensure => 'directory',
|
||||
path => $config['data-dir'],
|
||||
owner => $user,
|
||||
group => $group,
|
||||
mode => '0700',
|
||||
notify => Systemd::Unit_file['etcd.service'],
|
||||
require => Mkdir::P[$config['data-dir']],
|
||||
}
|
||||
|
||||
file { 'etcd-data-dir-wal.tmp':
|
||||
ensure => 'directory',
|
||||
path => "${config['data-dir']}/wal.tmp",
|
||||
owner => $user,
|
||||
group => $group,
|
||||
mode => '0700',
|
||||
notify => Systemd::Unit_file['etcd.service'],
|
||||
require => File['etcd-data-dir'],
|
||||
}
|
||||
|
||||
if $config['wal-dir'] {
|
||||
mkdir::p { $config['wal-dir']: }
|
||||
file { 'etcd-wal-dir':
|
||||
ensure => 'directory',
|
||||
path => $config['wal-dir'],
|
||||
owner => $user,
|
||||
group => $group,
|
||||
mode => '0700',
|
||||
notify => Systemd::Unit_file['etcd.service'],
|
||||
require => Mkdir::P[$config['wal-dir']],
|
||||
}
|
||||
}
|
||||
|
||||
if $manage_service {
|
||||
include ::systemd
|
||||
|
||||
systemd::unit_file { 'etcd.service':
|
||||
content => template('etcd/etcd.service.erb'),
|
||||
enable => true,
|
||||
active => true,
|
||||
require => Package[$package_name],
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
# DO NOT EDIT: This file is being managed by Puppet.
|
||||
[Unit]
|
||||
Description=etcd key-value store
|
||||
Documentation=https://github.com/etcd-io/etcd
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=<%= @user %>
|
||||
Group=<%= @group %>
|
||||
Type=notify
|
||||
ExecStart=/usr/bin/etcd --config-file <%= @config_file %>
|
||||
Restart=always
|
||||
RestartSec=10s
|
||||
LimitNOFILE=<%= @max_open_files %>
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in New Issue
Block a user