Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify zabbix version #3

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ driver:
name: vagrant

provisioner:
name: chef_solo
name: chef_zero

platforms:
- name: ubuntu-12.04
- name: centos-6.4
- name: ubuntu-14.04
- name: centos-7.1

suites:
- name: default
run_list:
- zabbix_ng::default
attributes:

- name: server
run_list:
- zabbix_ng::server
attributes:
9 changes: 9 additions & 0 deletions Berksfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
source 'https://supermarket.chef.io'

metadata

group :integration do
cookbook 'apt'
cookbook 'sudo'
cookbook 'selinux'
end
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 0.1.3

- Configure Kitchen CI

# 0.1.2

- Add yum repository
- Fix converge on 'rhel' platform


# 0.1.1

- Restart zabbix agent after config file was deployed
Expand Down
22 changes: 22 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,25 @@
#

default['zabbix_ng']['zabbix_server'] = '127.0.0.1'
default['zabbix_ng']['version'] = value_for_platform(
['rhel','centos'] => {
"~> 7" => '3.0.0-1.el7',
},
'ubuntu' => {
'~> 14' => '1:3.0.0-1+trusty'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think it's a good idea to version-lock repository packages. This will break as soon as there is a minor update or security fix.
For Ubuntu, the major version is specified using the repository URL, which is fine I think. Does this work differently on RHEL, or what was the reason you included this?

},
'default' => {'default' => '3.0.0'}
)

default['zabbix_ng']['repository']['key'] = 'http://repo.zabbix.com/zabbix-official-repo.key'

uri_version = node['zabbix_ng']['version'].to_s.gsub(/^[0-9]*:/,'').split('.')[0..1].join('.')
default['zabbix_ng']['repository']['uri'] = value_for_platform(
['redhat', 'centos', 'fedora'] => {
"~> 6" => "http://repo.zabbix.com/zabbix/#{uri_version}/rhel/6/x86_64",
"~> 7" => "http://repo.zabbix.com/zabbix/#{uri_version}/rhel/7/x86_64" },
'debian' => { 'default' => "http://repo.zabbix.com/zabbix/#{uri_version}/debian"},
'ubuntu' => { 'default' => "http://repo.zabbix.com/zabbix/#{uri_version}/ubuntu"},
)


5 changes: 4 additions & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
license 'GNU Public License 3.0'
description 'Installs/Configures zabbix_ng'
long_description 'Installs/Configures zabbix_ng'
version '0.1.1'
version '0.1.2'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not change the cookbook version - I think it's usually a good idea to let the maintainer take care of this. Can you remove this from the PR?

depends 'apt'
depends 'sudo'

depends 'yum'
depends 'yum-epel'
16 changes: 11 additions & 5 deletions recipes/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

include_recipe 'zabbix_ng::repository'

package 'zabbix-agent'
package 'zabbix-agent' do
version node['zabbix_ng']['version']
end

template '/etc/zabbix/zabbix_agentd.conf' do
mode 00644
Expand All @@ -35,6 +37,11 @@
# aptitude is required to get available update count
package 'aptitude'

directory '/etc/zabbix/zabbix_agentd.d' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my machines, this directory is maintained by the apt packages. I suppose it doesn't hurt to re-define it here though. Wasn't it created in your tests?

mode 00644
recursive true
end

template '/etc/zabbix/zabbix_agentd.d/apt.conf' do
owner 'root'
group 'root'
Expand All @@ -43,8 +50,7 @@
source 'agent/apt.conf.erb'
end

when 'rhel', 'fedora'
# TODO: yum repository is currently not supported anyway
when 'rhel'
template '/etc/zabbix/zabbix_agentd.d/yum.conf' do
owner 'root'
group 'root'
Expand All @@ -57,9 +63,9 @@
service 'zabbix-agent' do
case node['platform_family']
when 'debian'
subscribes :restart, 'template[/etc/zabbix/zabbix_agentd.d/yum.conf]'
when 'rhel', 'fedora'
subscribes :restart, 'template[/etc/zabbix/zabbix_agentd.d/apt.conf]'
when 'rhel'
subscribes :restart, 'template[/etc/zabbix/zabbix_agentd.d/yum.conf]'
end

subscribes :restart, 'template[/etc/zabbix/zabbix_agentd.conf'
Expand Down
30 changes: 25 additions & 5 deletions recipes/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,29 @@
#

# Official Zabbix repository
apt_repository 'zabbix' do
uri 'http://repo.zabbix.com/zabbix/2.4/ubuntu'
distribution node['lsb']['codename']
components %w(main)
key 'http://repo.zabbix.com/zabbix-official-repo.key'
case node['platform']
when 'debian'
apt_repository 'zabbix' do
uri node['zabbix_ng']['repository']['uri']
distribution node['lsb']['codename']
components %w(main)
key node['zabbix_ng']['repository']['key']
end
when 'ubuntu'
apt_repository 'zabbix' do
uri node['zabbix_ng']['repository']['uri']
distribution node['lsb']['codename']
components %w(main)
key node['zabbix_ng']['repository']['key']
end
when 'redhat', 'centos', 'fedora'
yum_repository 'zabbix' do
description "Official zabbix repository"
baseurl node['zabbix_ng']['repository']['uri']
gpgkey node['zabbix_ng']['repository']['key']
end
include_recipe 'yum-epel'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a default case should be inserted, which prints some sort of error message if this cookbook is run on a platform that is not supported?
It's not that important though, as for other platforms the package names are probably different as well and the cookbook will fail anyway.

end



14 changes: 13 additions & 1 deletion recipes/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@

include_recipe 'zabbix_ng::repository'

package 'zabbix-server-pgsql' do
version node['zabbix_ng']['version']
end
package 'zabbix-server-pgsql'
package 'zabbix-frontend-php'
case node['platform_family']
when 'debian'
package 'zabbix-frontend-php' do
version node['zabbix_ng']['version']
end
when 'rhel'
package 'zabbix-web-pgsql' do
version node['zabbix_ng']['version']
end
end

service 'zabbix-server' do
action :enable
Expand Down