Puppet – Automate Zabbix Agent Installation

Here is a Puppet script which automatically install the Zabbix agent on the Puppet agents.

class system::zabbix {
  # Install the required packages
  package { "zabbix": ensure => installed }
  package { "zabbix-agent": ensure => installed }

  # Replace the default config
  exec { "Remove the original zabbix agent config":
    command => "rm /etc/zabbix/zabbix_agentd.conf",
    onlyif  => "grep -c 'Hostname=Zabbix server' /etc/zabbix/zabbix_agentd.conf",
  }->
  file { "/etc/zabbix/zabbix_agentd.conf":
    source  => "puppet:///modules/system/etc/zabbix/zabbix_agentd.conf",
    owner   => "root",
    group   => "root",
    mode    => "644",
    ensure  => "present",
    replace => false, # Only create this file if it doesn't exist
  }->
  file_line { "Update ois zabbix agent config":
    line    => "Hostname=$hostname",
    path    => "/etc/zabbix/zabbix_agentd.conf",
    match   => "^Hostname=.*$",
    ensure  => present, # Restart the Zabbix agent if updated
    notify  => Service["zabbix-agent"],
  }

  # Enable the port for zabbix agent
  firewall { '202 allow communication with zabbix server':
    port    => [10050],
    proto   => tcp,
    action  => accept,
  }

  # Start the zabbix agent
  service { 'zabbix-agent':
    ensure  => 'running',
    enable  => true,
    require => Package["zabbix-agent"],
  }
}

 

Done =)

Reference:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s