From c84c4ad20b51245c7b089b456973aad91c16044a Mon Sep 17 00:00:00 2001 From: Brandon Burnett Date: Wed, 24 Feb 2016 10:54:25 -0800 Subject: [PATCH] Fixing merge conflict. --- .gitignore | 30 +++++++-- CONTRIBUTORS | 1 + Gemfile | 2 +- README.md | 92 ++++++++++++++++------------ manifests/init.pp | 24 -------- manifests/params.pp | 2 +- metadata.json | 2 +- spec/acceptance/nodesets/default.yml | 10 ++- spec/acceptance/standard_spec.rb | 18 +++--- spec/classes/init_spec.rb | 40 +----------- spec/spec_helper_acceptance.rb | 2 +- templates/nomad.debian.erb | 2 +- templates/nomad.launchd.erb | 2 +- templates/nomad.sles.erb | 10 +-- templates/nomad.systemd.erb | 2 +- templates/nomad.sysv.erb | 16 ++--- templates/nomad.upstart.erb | 8 +-- tests/init.pp | 14 ++++- 18 files changed, 135 insertions(+), 142 deletions(-) diff --git a/.gitignore b/.gitignore index 46e5569..5b15905 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,31 @@ +*.gem +*.rbc .*.sw? -pkg -spec/fixtures +.DS_Store +.bundle/ +.dat* +.repl_history .rspec_system +.rvmrc +/.bundle/ +/.config +/.yardoc/ +/InstalledFiles +/_yardoc/ +/coverage/ +/doc/ +/lib/bundler/man/ +/pkg/ +/rdoc/ +/spec/examples.txt +/spec/reports/ +/test/tmp/ +/test/version_tmp/ +/tmp/ +/vendor/bundle Gemfile.lock +build/ log/ +pkg +spec/fixtures vendor/ -.bundle/ -.DS_Store diff --git a/CONTRIBUTORS b/CONTRIBUTORS index b49b226..acd3f4a 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -3,3 +3,4 @@ Kenny Gatdula Simon Croome Dan Tehranian Vik Bhatti +Brandon Burnett diff --git a/Gemfile b/Gemfile index 71fdd99..e4e42c0 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ end group :test do gem "json" gem "rake" - gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.7.0' + gem "puppet", ENV['PUPPET_VERSION'] || '~> 4' gem "puppet-lint" # Pin for 1.8.7 compatibility for now diff --git a/README.md b/README.md index 6890464..d4bac49 100644 --- a/README.md +++ b/README.md @@ -1,64 +1,74 @@ -# puppet-consul - -## Compatibility - -| Consul Version | Recommended Puppet Module Version | -| ---------------- | ----------------------------------- | -| >= 0.6.0 | latest | -| 0.5.x | 1.0.3 | -| 0.4.x | 0.4.6 | -| 0.3.x | 0.3.0 | +# puppet-nomad ### What This Module Affects -* Installs the consul daemon (via url or package) +* Installs the nomad daemon (via url or package) * If installing from zip, you *must* ensure the unzip utility is available. * Optionally installs a user to run it under -* Installs a configuration file (/etc/consul/config.json) +* Installs a configuration file (/etc/nomad/config.json) * Manages the consul service via upstart, sysv, or systemd -* Optionally installs the Web UI ## Usage -To set up a single consul server, with several agents attached: +To set up a single nomad server, with several agents attached: On the server: ```puppet -class { '::consul': - config_hash => { - 'bootstrap_expect' => 1, - 'data_dir' => '/opt/consul', - 'datacenter' => 'east-aws', - 'log_level' => 'INFO', - 'node_name' => 'server', - 'server' => true, +class { '::nomad': + config_hash = { + 'region' => 'us-west', + 'datacenter' => 'ptk', + 'log_level' => 'INFO', + 'bind_addr' => '0.0.0.0', + 'data_dir' => '/opt/nomad', + 'server' => { + 'enabled' => true, + 'bootstrap_expect' => 3, + } } } ``` On the agent(s): ```puppet -class { '::consul': - config_hash => { - 'data_dir' => '/opt/consul', - 'datacenter' => 'east-aws', +class { 'nomad': + config_hash => { + 'region' => 'us-west', + 'datacenter' => 'ptk', 'log_level' => 'INFO', - 'node_name' => 'agent', - 'retry_join' => ['172.16.0.1'], - } + 'bind_addr' => '0.0.0.0', + 'data_dir' => '/opt/nomad', + 'client' => { + 'enabled' => true, + 'servers' => [ + "nomad01.your-org.pvt4647", + "nomad02.your-org.pvt:4647", + "nomad03.your-org.pvt:4647" + ] + } + }, } + ``` Disable install and service components: ```puppet -class { '::consul': +class { '::nomad': install_method => 'none', init_style => false, manage_service => false, - config_hash => { - 'data_dir' => '/opt/consul', - 'datacenter' => 'east-aws', + config_hash => { + 'region' => 'us-west', + 'datacenter' => 'ptk', 'log_level' => 'INFO', - 'node_name' => 'agent', - 'retry_join' => ['172.16.0.1'], - } + 'bind_addr' => '0.0.0.0', + 'data_dir' => '/opt/nomad', + 'client' => { + 'enabled' => true, + 'servers' => [ + "nomad01.your-org.pvt4647", + "nomad02.your-org.pvt:4647", + "nomad03.your-org.pvt:4647" + ] + } + }, } ``` @@ -67,6 +77,10 @@ class { '::consul': Depends on the JSON gem, or a modern ruby. (Ruby 1.8.7 is not officially supported) ## Development -Open an [issue](https://github.com/solarkennedy/puppet-consul/issues) or -[fork](https://github.com/solarkennedy/puppet-consul/fork) and open a -[Pull Request](https://github.com/solarkennedy/puppet-consul/pulls) +Open an [issue](https://github.com/dudemcbacon/puppet-nomad/issues) or +[fork](https://github.com/dudemcbacon/puppet-nomad/fork) and open a +[Pull Request](https://github.com/dudemcbacon/puppet-nomad/pulls) + +## Acknowledgement + +Must of this module was refactored from Kyle Anderson's great [consul](https://github.com/solarkennedy/puppet-consul) module available on the puppet forge. Go give him stars and likes and what not -- he deserves them! diff --git a/manifests/init.pp b/manifests/init.pp index 4edb5ab..8e7da87 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -74,10 +74,6 @@ $manage_service = true, $restart_on_change = true, $init_style = $nomad::params::init_style, - $services = {}, - $watches = {}, - $checks = {}, - $acls = {}, ) inherits nomad::params { $real_download_url = pick($download_url, "${download_url_base}${version}/${package_name}_${version}_${os}_${arch}.${download_extension}") @@ -91,10 +87,6 @@ validate_hash($config_defaults) validate_bool($pretty_config) validate_integer($pretty_config_indent) - validate_hash($services) - validate_hash($watches) - validate_hash($checks) - validate_hash($acls) $config_hash_real = deep_merge($config_defaults, $config_hash) validate_hash($config_hash_real) @@ -120,22 +112,6 @@ $rpc_addr = $::ipaddress_lo } - if $services { - create_resources(nomad::service, $services) - } - - if $watches { - create_resources(nomad::watch, $watches) - } - - if $checks { - create_resources(nomad::check, $checks) - } - - if $acls { - create_resources(nomad_acl, $acls) - } - $notify_service = $restart_on_change ? { true => Class['nomad::run_service'], default => undef, diff --git a/manifests/params.pp b/manifests/params.pp index 2876e74..10910c0 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -10,7 +10,7 @@ $package_ensure = 'latest' $download_url_base = 'https://releases.hashicorp.com/nomad/' $download_extension = 'zip' - $version = '0.5.2' + $version = '0.2.3' $config_mode = '0660' case $::architecture { diff --git a/metadata.json b/metadata.json index 678d7c5..f31aec4 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "dudemcbacon-consul", - "version": "1.0.0", + "version": "0.0.1", "author": "Kyle Anderson ", "summary": "Configures Nomad by Hashicorp", "license": "Apache-2.0", diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml index ad5440e..17ad168 100644 --- a/spec/acceptance/nodesets/default.yml +++ b/spec/acceptance/nodesets/default.yml @@ -1,9 +1,7 @@ HOSTS: - ubuntu-12-04: - platform: ubuntu-12.04-x64 - image: solarkennedy/ubuntu-12.04-puppet - hypervisor: docker - docker_cmd: '["/sbin/init"]' - docker_preserve_image: true + centos-7-puppet: + platform: centos-7.2-x64 + box: puppetlabs/centos-7.2-64-puppet + hypervisor: vagrant CONFIG: type: foss diff --git a/spec/acceptance/standard_spec.rb b/spec/acceptance/standard_spec.rb index f162437..13d8085 100644 --- a/spec/acceptance/standard_spec.rb +++ b/spec/acceptance/standard_spec.rb @@ -7,13 +7,17 @@ it 'should work with no errors based on the example' do pp = <<-EOS class { 'nomad': - version => '0.5.2', + version => '0.2.3', config_hash => { - 'datacenter' => 'east-aws', - 'data_dir' => '/opt/nomad', - 'log_level' => 'INFO', - 'node_name' => 'foobar', - 'server' => true + "region" => 'us-west', + "datacenter" => 'ptk', + "log_level" => 'INFO', + "bind_dir" => "0.0.0.0", + "data_dir" => "/var/lib/nomad", + "server" => { + "enabled" => true, + "bootstrap_expect" => 1 + } } } EOS @@ -32,7 +36,7 @@ class { 'nomad': end describe command('nomad version') do - its(:stdout) { should match /Consul v0\.5\.2/ } + its(:stdout) { should match /Nomad v0\.2\.3/ } end end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 46d4861..4aef322 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -84,7 +84,7 @@ end context "When installing via URL by default" do - it { should contain_staging__file('nomad-0.5.2.zip').with(:source => 'https://releases.hashicorp.com/nomad/0.5.2/nomad_0.5.2_linux_amd64.zip') } + it { should contain_staging__file('nomad-0.2.3.zip').with(:source => 'https://releases.hashicorp.com/nomad/0.2.3/nomad_0.2.3_linux_amd64.zip') } it { should contain_file('/usr/local/bin/nomad').that_notifies('Class[nomad::run_service]') } #it { should contain_notify(['Class[nomad::run_service]']) } end @@ -101,7 +101,7 @@ let(:params) {{ :download_url => 'http://myurl', }} - it { should contain_staging__file('nomad-0.5.2.zip').with(:source => 'http://myurl') } + it { should contain_staging__file('nomad-0.2.3.zip').with(:source => 'http://myurl') } it { should contain_file('/usr/local/bin/nomad').that_notifies('Class[nomad::run_service]') } end @@ -228,11 +228,6 @@ context "When a reload_service is triggered with service_ensure stopped" do let (:params) {{ :service_ensure => 'stopped', - :services => { - 'test_service1' => { - 'port' => '5' - } - } }} it { should_not contain_exec('reload nomad service') } end @@ -240,11 +235,6 @@ context "When a reload_service is triggered with manage_service false" do let (:params) {{ :manage_service => false, - :services => { - 'test_service1' => { - 'port' => '5' - } - } }} it { should_not contain_exec('reload nomad service') } end @@ -274,11 +264,6 @@ end context "When nomad is reloaded" do - let (:params) {{ - :services => { - 'test_service1' => {} - } - }} let (:facts) {{ :ipaddress_lo => '127.0.0.1' }} @@ -290,9 +275,6 @@ context "When nomad is reloaded on a custom port" do let (:params) {{ - :services => { - 'test_service1' => {} - }, :config_hash => { 'ports' => { 'rpc' => '9999' @@ -310,9 +292,6 @@ context "When nomad is reloaded with a default client_addr" do let (:params) {{ - :services => { - 'test_service1' => {} - }, :config_hash => { 'client_addr' => '192.168.34.56', } @@ -323,19 +302,6 @@ } end - context "When the user provides a hash of services" do - let (:params) {{ - :services => { - 'test_service1' => { - 'port' => '5' - } - } - }} - it { should contain_nomad__service('test_service1').with_port('5') } - it { should have_nomad__service_resource_count(1) } - it { should contain_exec('reload nomad service') } - end - context "When using sysv" do let (:params) {{ :init_style => 'sysv' @@ -571,7 +537,7 @@ let(:params) {{ :extra_options => '-some-extra-argument' }} - it { should contain_file('/etc/init/nomad.conf').with_content(/\$CONSUL -S -- agent .*-some-extra-argument$/) } + it { should contain_file('/etc/init/nomad.conf').with_content(/\$NOMAD -S -- agent .*-some-extra-argument$/) } end # Service Stuff diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 2c53dc7..1805144 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -2,7 +2,7 @@ require 'beaker-rspec/helpers/serverspec' require 'beaker/puppet_install_helper' -run_puppet_install_helper unless ENV['BEAKER_provision'] == 'no' +#run_puppet_install_helper unless ENV['BEAKER_provision'] == 'no' RSpec.configure do |c| # Project root diff --git a/templates/nomad.debian.erb b/templates/nomad.debian.erb index fcf9f9d..9a4bac4 100644 --- a/templates/nomad.debian.erb +++ b/templates/nomad.debian.erb @@ -18,7 +18,7 @@ DESC="Nomad job scheduling service" NAME=nomad DAEMON=<%= scope.lookupvar('nomad::bin_dir') %>/$NAME PIDFILE=/var/run/$NAME/$NAME.pid -DAEMON_ARGS="agent -config-dir <%= scope.lookupvar('nomad::config_dir') %> <%= scope.lookupvar('nomad::extra_options') %>" +DAEMON_ARGS="agent -config <%= scope.lookupvar('nomad::config_dir') %> <%= scope.lookupvar('nomad::extra_options') %>" USER=<%= scope.lookupvar('nomad::user') %> SCRIPTNAME=/etc/init.d/$NAME RPC_ADDR=-rpc-addr=<%= scope.lookupvar('nomad::rpc_addr') %>:<%= scope.lookupvar('nomad::rpc_port') %> diff --git a/templates/nomad.launchd.erb b/templates/nomad.launchd.erb index 68fb0ab..fb6aeb9 100644 --- a/templates/nomad.launchd.erb +++ b/templates/nomad.launchd.erb @@ -16,7 +16,7 @@ <%= scope.lookupvar('nomad::bin_dir') %>/nomad agent - -config-dir + -config <%= scope.lookupvar('nomad::config_dir') %> <% require 'shellwords' %> <% for extra_option in Shellwords.split(scope.lookupvar('nomad::extra_options')) %> diff --git a/templates/nomad.sles.erb b/templates/nomad.sles.erb index f63653e..1251268 100644 --- a/templates/nomad.sles.erb +++ b/templates/nomad.sles.erb @@ -20,7 +20,7 @@ rc_reset -CONSUL_BIN=<%= scope.lookupvar('nomad::bin_dir') %>/nomad +NOMAD_BIN=<%= scope.lookupvar('nomad::bin_dir') %>/nomad CONFIG_DIR=<%= scope.lookupvar('nomad::config_dir') %> LOG_FILE=/var/log/nomad @@ -36,7 +36,7 @@ case "$1" in echo -n "Starting nomad " ## Start daemon with startproc(8). If this fails ## the return value is set appropriately by startproc. - startproc $CONSUL_BIN agent -config-dir "$CONFIG_DIR" <%= scope.lookupvar('nomad::extra_options') %> >> "$LOG_FILE" + startproc $NOMAD_BIN agent -config "$CONFIG_DIR" <%= scope.lookupvar('nomad::extra_options') %> >> "$LOG_FILE" # Remember status and be verbose rc_status -v @@ -46,7 +46,7 @@ case "$1" in ## Stop daemon with killproc(8) and if this fails ## killproc sets the return value according to LSB. - killproc -TERM $CONSUL_BIN + killproc -TERM $NOMAD_BIN # Remember status and be verbose rc_status -v @@ -63,7 +63,7 @@ case "$1" in reload) # If it supports signaling: echo -n "Reload service nomad " - killproc -HUP $CONSUL_BIN + killproc -HUP $NOMAD_BIN #touch /var/run/nomad.pid rc_status -v @@ -85,7 +85,7 @@ case "$1" in # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.) # NOTE: checkproc returns LSB compliant status values. - checkproc $CONSUL_BIN + checkproc $NOMAD_BIN # NOTE: rc_status knows that we called this init script with # "status" option and adapts its messages accordingly. rc_status -v diff --git a/templates/nomad.systemd.erb b/templates/nomad.systemd.erb index 93728a8..e6a4ee3 100644 --- a/templates/nomad.systemd.erb +++ b/templates/nomad.systemd.erb @@ -7,7 +7,7 @@ After=basic.target network.target User=<%= scope.lookupvar('nomad::user') %> Group=<%= scope.lookupvar('nomad::group') %> ExecStart=<%= scope.lookupvar('nomad::bin_dir') %>/nomad agent \ - -config-dir <%= scope.lookupvar('nomad::config_dir') %> <%= scope.lookupvar('nomad::extra_options') %> + -config <%= scope.lookupvar('nomad::config_dir') %> <%= scope.lookupvar('nomad::extra_options') %> ExecReload=/bin/kill -HUP $MAINPID KillMode=process Restart=on-failure diff --git a/templates/nomad.sysv.erb b/templates/nomad.sysv.erb index 7457a98..065c1d8 100644 --- a/templates/nomad.sysv.erb +++ b/templates/nomad.sysv.erb @@ -13,7 +13,7 @@ # Source function library. . /etc/init.d/functions -CONSUL=<%= scope.lookupvar('nomad::bin_dir') %>/nomad +NOMAD=<%= scope.lookupvar('nomad::bin_dir') %>/nomad CONFIG=<%= scope.lookupvar('nomad::config_dir') %> PID_FILE=/var/run/nomad/nomad.pid LOG_FILE=/var/log/nomad @@ -40,7 +40,7 @@ KILLPROC_OPT="-p ${PID_FILE}" mkpidfile() { # Create PID file if it didn't exist mkrundir - [ ! -f $PID_FILE ] && pidofproc $CONSUL > $PID_FILE + [ ! -f $PID_FILE ] && pidofproc $NOMAD > $PID_FILE chown <%= scope.lookupvar('nomad::user') %> /var/run/nomad if [ $? -ne 0 ] ; then rm $PID_FILE @@ -54,7 +54,7 @@ start() { [ -f $PID_FILE ] && rm $PID_FILE daemon --user=<%= scope.lookupvar('nomad::user') %> \ --pidfile="$PID_FILE" \ - "$CONSUL" agent -pid-file "${PID_FILE}" -config-dir "$CONFIG" <%= scope.lookupvar('nomad::extra_options') %> >> "$LOG_FILE" & + "$NOMAD" agent -pid-file "${PID_FILE}" -config "$CONFIG" <%= scope.lookupvar('nomad::extra_options') %> >> "$LOG_FILE" & retcode=$? touch /var/lock/subsys/nomad return $retcode @@ -69,9 +69,9 @@ stop() { # If nomad is not acting as a server, exit gracefully # Use SIGINT to create a "leave" event, unless the user has explicitly # changed that behavior in the Consul config. - if ("${CONSUL}" info ${RPC_ADDR} 2>/dev/null | grep -q 'server = false' 2>/dev/null) ; then + if ("${NOMAD}" info ${RPC_ADDR} 2>/dev/null | grep -q 'server = false' 2>/dev/null) ; then nomad_pid=$(cat $PID_FILE) - killproc $KILLPROC_OPT $CONSUL -INT + killproc $KILLPROC_OPT $NOMAD -INT retcode=$? # We'll wait if necessary to make sure the leave works, and return @@ -93,7 +93,7 @@ stop() { # # A SIGTERM will mark the node as "failed" until it rejoins. # killproc with no arguments uses TERM, then escalates to KILL. - killproc $KILLPROC_OPT $CONSUL + killproc $KILLPROC_OPT $NOMAD retcode=$? rm -f /var/lock/subsys/nomad $PID_FILE @@ -108,7 +108,7 @@ case "$1" in stop ;; status) - "$CONSUL" info ${RPC_ADDR} + "$NOMAD" info ${RPC_ADDR} ;; restart) stop @@ -116,7 +116,7 @@ case "$1" in ;; reload) mkpidfile - killproc $KILLPROC_OPT $CONSUL -HUP + killproc $KILLPROC_OPT $NOMAD -HUP ;; condrestart) [ -f /var/lock/subsys/nomad ] && restart || : diff --git a/templates/nomad.upstart.erb b/templates/nomad.upstart.erb index c7cc437..92c8139 100644 --- a/templates/nomad.upstart.erb +++ b/templates/nomad.upstart.erb @@ -3,7 +3,7 @@ description "Nomad Agent" start on runlevel [2345] stop on runlevel [06] -env CONSUL=<%= scope.lookupvar('nomad::bin_dir') %>/nomad +env NOMAD=<%= scope.lookupvar('nomad::bin_dir') %>/nomad env CONFIG=<%= scope.lookupvar('nomad::config_dir') %> env USER=<%= scope.lookupvar('nomad::user') %> env GROUP=<%= scope.lookupvar('nomad::group') %> @@ -25,13 +25,13 @@ script [ -e $DEFAULTS ] && . $DEFAULTS export GOMAXPROCS=${GOMAXPROCS:-2} - exec start-stop-daemon -c $USER -g $GROUP -p $PID_FILE -x $CONSUL -S -- agent -config-dir $CONFIG -pid-file $PID_FILE <%= scope.lookupvar('nomad::extra_options') %> + exec start-stop-daemon -c $USER -g $GROUP -p $PID_FILE -x $NOMAD -S -- agent -config $CONFIG -pid-file $PID_FILE <%= scope.lookupvar('nomad::extra_options') %> end script pre-stop script # Only leave the cluster if running as an agent - if ("${CONSUL}" info ${RPC_ADDR} 2>/dev/null | grep -q 'server = false' 2>/dev/null) ; then - exec "$CONSUL" leave ${RPC_ADDR} + if ("${NOMAD}" info ${RPC_ADDR} 2>/dev/null | grep -q 'server = false' 2>/dev/null) ; then + exec "$NOMAD" leave ${RPC_ADDR} fi end script diff --git a/tests/init.pp b/tests/init.pp index 1817370..a95a060 100644 --- a/tests/init.pp +++ b/tests/init.pp @@ -9,4 +9,16 @@ # Learn more about module testing here: # http://docs.puppetlabs.com/guides/tests_smoke.html # -include nomad +class { 'nomad': + config_hash => { + "region" => 'us-west', + "datacenter" => 'ptk', + "log_level" => 'INFO', + "bind_dir" => "0.0.0.0", + "data_dir" => "/var/lib/nomad", + "server" => { + "enabled" => true, + "bootstrap_expect" => 1 + } + } +}