Skip to content

Commit

Permalink
Merge pull request #144 from vkhatri/travis-lwrp-post-fix
Browse files Browse the repository at this point in the history
LWRP Fix and Release v2.1.0
  • Loading branch information
vkhatri authored Jun 29, 2018
2 parents 75ee639 + 6186f79 commit 571e1b0
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .kitchen.dokken.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ suites:

- name: chef13-preview
driver:
chef_version: 13.3.42
chef_version: 13.9.4
run_list:
- recipe[filebeat_test::defaultv6preview]
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
filebeat CHANGELOG
==================

2.1.0
-----

- Virender Khatri - Added filebeat_install attr :elastic_repo_options for :elastic_repo resource configuration

- Virender Khatri - Added filebeat Log Directory Resource

- Virender Khatri - Updated filebeat_service service resource

- Virender Khatri - Updated filebeat_resource lookup to use attr filebeat_install_resource_name

- Virender Khatri - Fixed filebeat_install for windows

- Virender Khatri - Updated elastic_repo cookbook version


2.0.0
-----

- Virender Khatri - Converted Recipes to LWRP Resources, check README for available resources and test cookbook for usage reference

- Virender Khatri - LWRP Resources uses elastic_repo cookbook to setup elastic yum/apt repository

- Michael Burns - Clean up redundant filebeat_prospector resource attribute in test cookbook

1.5.0
-----
- Virender Khatri - Updated filebeat version to v6.2.4
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ This is a [Chef] cookbook to manage [Filebeat].
## Most Recent Release

```ruby
cookbook 'filebeat', '~> 2.0.0'
cookbook 'filebeat', '~> 2.1.0'
```


## From Git

```ruby
cookbook 'filebeat', github: 'vkhatri/chef-filebeat', tag: 'v2.0.0'
cookbook 'filebeat', github: 'vkhatri/chef-filebeat', tag: 'v2.1.0'
```


Expand Down Expand Up @@ -124,6 +124,7 @@ end
- *windows_package_url* (optional, String) - default `auto`, windows filebeat package url
- *windows_base_dir* (optional, String) - default `C:/opt/filebeat`, filebeat windows base directory
- *apt_options* (optional, Array) - default `%w[stable main]`, filebeat package resource attribute for `debian` platform family
- *elastic_repo_options* (optional, Hash) - default `{}`, resource elastic_repo options, `filebeat_install` attribute `version` overrides `elasti_repo_options` key `version` value. Check out [elastic_repo cookbook](https://github.com/vkhatri/chef-elastic-repo) for more details.


## LWRP filebeat_service
Expand Down
2 changes: 1 addition & 1 deletion libraries/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def machine_arch
node['kernel']['machine'] =~ /x86_64/ ? 'x86_64' : 'x86'
end

def windows_package_url(version, package_url)
def win_package_url(version, package_url)
package_url = if version < '5.0'
package_url == 'auto' ? "https://download.elastic.co/beats/filebeat/filebeat-#{version}-windows.zip" : package_url
else
Expand Down
4 changes: 2 additions & 2 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
license 'Apache-2.0'
description 'Installs/Configures Elastic Filebeat'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '2.0.0'
version '2.1.0'
source_url 'https://github.com/vkhatri/chef-filebeat' if respond_to?(:source_url)
issues_url 'https://github.com/vkhatri/chef-filebeat/issues' if respond_to?(:issues_url)
chef_version '>= 12.14' if respond_to?(:chef_version)

depends 'homebrew', '~> 4.2'
depends 'elastic_repo', '>= 1.0.0'
depends 'elastic_repo', '>= 1.1.1'
depends 'yum-plugin-versionlock', '>= 0.1.2'
depends 'runit'
depends 'windows'
Expand Down
2 changes: 1 addition & 1 deletion resources/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
end

action :delete do
filebeat_install_resource = find_beat_resource(Chef.run_context, :filebeat_install)
filebeat_install_resource = find_beat_resource(Chef.run_context, :filebeat_install, new_resource.filebeat_install_resource_name)
new_resource.conf_file = new_resource.conf_file || default_conf_file(filebeat_install_resource.conf_dir)

file new_resource.conf_file do
Expand Down
21 changes: 16 additions & 5 deletions resources/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
property :windows_package_url, String, default: 'auto'
property :windows_base_dir, String, default: 'C:/opt/filebeat'
property :apt_options, String, default: "-o Dpkg::Options::='--force-confnew' --force-yes"
property :elastic_repo_options, Hash, default: {}

default_action :create

Expand All @@ -28,10 +29,9 @@
new_resource.log_dir = new_resource.log_dir || default_log_dir(new_resource.conf_dir)
version_string = %w[fedora rhel amazon].include?(node['platform_family']) ? "#{new_resource.version}-#{new_resource.release}" : new_resource.version

service_action = new_resource.disable_service ? %i[disable nothing] : %i[enable nothing]
with_run_context(:root) do
edit_resource(:service, new_resource.service_name) do
action service_action
action :nothing
end
end

Expand Down Expand Up @@ -61,7 +61,7 @@

## install filebeat windows
if node['platform'] == 'windows'
package_url = windows_package_url(new_resource.version, new_resource.windows_package_url)
package_url = win_package_url(new_resource.version, new_resource.windows_package_url)
package_file = ::File.join(Chef::Config[:file_cache_path], ::File.basename(package_url))

remote_file 'filebeat_package_file' do
Expand Down Expand Up @@ -89,8 +89,12 @@
## install filebeat yum/apt
if %w[fedora rhel amazon debian].include?(node['platform_family'])
# setup yum/apt repository
elastic_repo_opts = new_resource.elastic_repo_options.dup
elastic_repo_opts['version'] = new_resource.version
elastic_repo 'default' do
version new_resource.version
elastic_repo_opts.each do |key, value|
send(key, value) unless value.nil?
end
only_if { new_resource.setup_repo }
end

Expand Down Expand Up @@ -126,7 +130,9 @@
end
end

directory new_resource.log_dir
directory new_resource.log_dir do
mode 0o755
end

prospectors_dir_action = new_resource.delete_prospectors_dir ? %i[delete create] : %i[create]

Expand All @@ -151,4 +157,9 @@
action :delete
recursive true
end

directory '/var/log/filebeat' do
action :delete
recursive true
end
end
2 changes: 1 addition & 1 deletion resources/prospector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
end

action :delete do
filebeat_install_resource = find_beat_resource(Chef.run_context, :filebeat_install)
filebeat_install_resource = find_beat_resource(Chef.run_context, :filebeat_install, new_resource.filebeat_install_resource_name)
file "prospector_#{new_resource.name}" do
path ::File.join(filebeat_install_resource.prospectors_dir, "lwrp-prospector-#{new_resource.name}.yml")
action :delete
Expand Down
17 changes: 7 additions & 10 deletions resources/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

property :retries, Integer, default: 2
property :retry_delay, Integer, default: 0
property :notify_restart, [TrueClass, FalseClass], default: false

default_action :create

Expand Down Expand Up @@ -48,15 +47,13 @@

service_action = new_resource.disable_service ? %i[disable stop] : %i[enable nothing]

with_run_context(:root) do
edit_resource(:service, new_resource.service_name) do
provider Chef::Provider::Service::Solaris if node['platform_family'] == 'solaris2'
retries new_resource.retries
retry_delay new_resource.retry_delay
supports :status => true, :restart => true
action service_action
ignore_failure new_resource.ignore_failure
end
service new_resource.service_name do
provider Chef::Provider::Service::Solaris if node['platform_family'] == 'solaris2'
retries new_resource.retries
retry_delay new_resource.retry_delay
supports :status => true, :restart => true
action service_action
ignore_failure new_resource.ignore_failure
end
end

Expand Down

0 comments on commit 571e1b0

Please sign in to comment.