diff --git a/data/common.yaml b/data/common.yaml new file mode 100644 index 0000000..351310c --- /dev/null +++ b/data/common.yaml @@ -0,0 +1,16 @@ +--- + +twemproxy::yaml_config: + default: + listen: 127.0.0.1:22122 + hash: md5 + distribution: ketama + timeout: 400 + backlog: 1024 + redis: false + server_connections: 1 + auto_eject_hosts: false + server_retry_timeout: 30000 + server_failure_limit: 2 + servers: + - 127.0.0.1:11211 diff --git a/hiera.yaml b/hiera.yaml new file mode 100644 index 0000000..6e2a6a1 --- /dev/null +++ b/hiera.yaml @@ -0,0 +1,22 @@ +--- +version: 5 + +defaults: + datadir: 'data' + data_hash: 'yaml_data' + +hierarchy: + - name: 'Full Version' + path: '%{facts.os.name}-%{facts.os.release.full}.yaml' + + - name: 'Major Version' + path: '%{facts.os.name}-%{facts.os.release.major}.yaml' + + - name: 'Distribution Name' + path: '%{facts.os.name}.yaml' + + - name: 'Operating System Family' + path: '%{facts.os.family}-family.yaml' + + - name: 'common' + path: 'common.yaml' diff --git a/manifests/init.pp b/manifests/init.pp index a4aae29..2dd93f2 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -41,6 +41,7 @@ $client_port = $twemproxy::params::client_port, $client_weight = $twemproxy::params::client_weight, $clients_array = undef, + $yaml_config = undef, ) inherits twemproxy::params { anchor { 'twemproxy::start': } -> @@ -64,6 +65,7 @@ client_port => $client_port, client_weight => $client_weight, clients_array => $clients_array, + yaml_config => $yaml_config, } -> class { 'twemproxy::service': } -> diff --git a/manifests/pool.pp b/manifests/pool.pp index 8711987..1e9a58c 100644 --- a/manifests/pool.pp +++ b/manifests/pool.pp @@ -20,37 +20,49 @@ $clients_array = undef, $client_port = $twemproxy::params::client_port, $client_weight = $twemproxy::params::client_weight, + $yaml_config = undef, ) { - if !$client_address and !$clients_array { - fail('You must set at least one of client_address or clients_array parameter.') - } + if !$yaml_config { + if !$client_address and !$clients_array { + fail('You must set at least one of client_address or clients_array parameter.') + } - twemproxy::listen { $name: - order => $order, - listen_address => $listen_address, - listen_port => $listen_port, - connections => $connections, - hash => $hash, - hash_tag => $hash_tag, - distribution => $distribution, - timeout => $timeout, - backlog => $backlog, - preconnect => $preconnect, - redis => $redis, - redis_auth => $redis_auth, - redis_db => $redis_db, - server_connections => $server_connections, - auto_eject_hosts => $auto_eject_hosts, - server_retry_timeout => $server_retry_timeout, - server_failure_limit => $server_failure_limit, - } + twemproxy::listen { $name: + order => $order, + listen_address => $listen_address, + listen_port => $listen_port, + connections => $connections, + hash => $hash, + hash_tag => $hash_tag, + distribution => $distribution, + timeout => $timeout, + backlog => $backlog, + preconnect => $preconnect, + redis => $redis, + redis_auth => $redis_auth, + redis_db => $redis_db, + server_connections => $server_connections, + auto_eject_hosts => $auto_eject_hosts, + server_retry_timeout => $server_retry_timeout, + server_failure_limit => $server_failure_limit, + } - twemproxy::member { $name: - order => $order, - client_address => $client_address, - client_port => $client_port, - client_weight => $client_weight, - clients_array => $clients_array, + twemproxy::member { $name: + order => $order, + client_address => $client_address, + client_port => $client_port, + client_weight => $client_weight, + clients_array => $clients_array, + } + } + else { + file {'/etc/nutcracker.yml': + ensure => present, + content => template("${module_name}/pure_hash.yml.erb"), + owner => 'root', + group => 'root', + mode => '0644', + } } } diff --git a/templates/pure_hash.yml.erb b/templates/pure_hash.yml.erb new file mode 100644 index 0000000..0d74be4 --- /dev/null +++ b/templates/pure_hash.yml.erb @@ -0,0 +1,2 @@ +### Twemproxy/Nutcracker configuration managed by Puppet ### +#<%= @yaml_config.to_yaml() %>