<p>Very basic recipe exemple to install filebeat on ubuntu (I do use more or less the same approach for elasticsearch, kibana and logstash):</p>

<pre><code>apt_repository 'elk' do
  uri 'https://artifacts.elastic.co/packages/5.x/apt'
  distribution 'stable'
  components ['main']
  key 'https://artifacts.elastic.co/GPG-KEY-elasticsearch'
  cache_rebuild true
end

package 'filebeat' do
  action :upgrade # To keep up to date with releases from elastic.co
end

service 'filebeat' do
  action [:enable, :start]
end

template '/etc/filebeat/filebeat.yml' do
  source 'filebeat.yml.erb'
  mode '0600'
  notifies :restart, 'service[filebeat]'
end
</code></pre>

<p>Basically, adding a repository, installing package, enabling and starting the service, render a config and restart the service when it changes. On ubuntu the package set the service scripts so I don't have to manage it here.</p>

<p>The template is my default configuration using some node attributes depending on environment. See <a href="https://docs.chef.io/resource_template.html" rel="nofollow noreferrer">https://docs.chef.io/resource_template.html</a> for more details on how to use them.</p>

<p>According to your question I would strongly sugest you to follow the tutorial paths at <a href="https://learn.chef.io" rel="nofollow noreferrer">https://learn.chef.io</a> to grasp the basics about chef.</p>

CC BY-SA 3.0
2018-02-23T17:03:25.267Z
Sure.. I will do that.
Ilyas khan H
CC BY-SA 3.0
2018-02-21T21:23:40.120Z
2018-02-21T21:23:40.120Z
Tensibai
<p><a href="https://www.google.nl/search?q=how%2Bto%2Bcreate%2Ba%2Bchef%2Bpackage" rel="nofollow noreferrer">https://www.google.nl/search?q=how%2Bto%2Bcreate%2Ba%2Bchef%2Bpackage</a></p>

<p>returns:</p>

<p><a href="https://docs.chef.io/resource_package.html" rel="nofollow noreferrer">https://docs.chef.io/resource_package.html</a></p>

<p>and</p>

<p><a href="https://docs.chef.io/resource_examples.html" rel="nofollow noreferrer">https://docs.chef.io/resource_examples.html</a></p>

<p>The latter provides code snippets, like how to copy files:</p>

<blockquote>
  <p><strong>Create a file from a copy</strong></p>
  
  <p>The following example shows how to copy a file from one directory to
  another, locally on a node:</p>

<pre><code>file '/root/1.txt' do
  content IO.read('/tmp/1.txt')
  action :create
end
</code></pre>
</blockquote>

<p>More example could be found in <a href="https://supermarket.chef.io/cookbooks/mysql" rel="nofollow noreferrer">the supermarket</a>. In order to write chef books one could investigate how some recipes are structured like <a href="https://github.com/chef-cookbooks/mysql" rel="nofollow noreferrer">mysql</a>.</p>

CC BY-SA 3.0
2018-02-21T19:24:25.037Z
Hey.Thank you.I want to know how to proceed.What I understood from the answer is. The above snippets creates a package after that I have to prepare a recipe?
Ilyas khan H
CC BY-SA 3.0
2018-02-21T20:27:16.947Z
Could you explain why you would like to use chef?
030
CC BY-SA 3.0
2018-02-21T20:46:55.970Z
I am using it for deployment of the above binaries for all servers
Ilyas khan H
CC BY-SA 3.0
2018-02-21T20:47:57.243Z
Ok, but did you consider puppet, ansible or salt?
030
CC BY-SA 3.0
2018-02-21T20:50:44.313Z
Hey. I already have an environment of chef
Ilyas khan H
CC BY-SA 3.0
2018-03-05T20:25:44.617Z
Hi, I could able to write cookbook and install filebeat rpm. However I am getting the below error while creating a template.                     
 Error executing action `create` on resource 'template[/etc/filebeat/filebeat.yml]'
 ==================================================Chef::Exceptions::FileNotFound
    ------------------------------
    Cookbook 'ELK' (0.1.0) does not contain a file at any of these locations:
      templates/redhat-6.9/filebeat.yml.erb
      templates/redhat/filebeat.yml.erb
      templates/default/filebeat.yml.erb
      templates/filebeat.yml.erb
Ilyas khan H
CC BY-SA 3.0
2018-03-05T20:34:19.253Z
Could you add this to the question and format it?
030
CC BY-SA 3.0
2018-02-21T18:52:30.600Z
2018-02-21T21:08:42.940Z
2018-02-21T21:08:42.940Z
030
<ol>
<li><p>Installation steps. There are two ELK agents to install:</p>

<ul>
<li><p>Metricbeat</p>

<ol>
<li>Copy the attached file <code>metricbeat-6.0.0-x86_64.rpm</code> to the target server</li>
<li>Execute the command: <code>sudo rpm -vi metricbeat-6.0.0-x86_64.rpm</code></li>
<li>Copy the attached file <code>system.yml</code> to <code>/etc/metricbeat/modules.d/</code></li>
<li>Copy the attached file <code>metricbeat.yml</code> to <code>/etc/metricbeat/</code></li>
<li>Execute the command: <code>sudo systemctl enable metricbeat</code></li>
<li>Execute the command: <code>sudo service metricbeat start</code></li>
</ol></li>
<li><p>Filebeat</p>

<ol>
<li>Copy the attached file <code>filebeat-6.0.0-x86_64.rpm</code> to the target server</li>
<li>Execute the command: <code>sudo rpm -vi filebeat-6.0.0-x86_64.rpm</code></li>
<li>Execute the command: <code>sudo mv /etc/filebeat/module.d/system.yml.disabled /etc/filebeat/module.d/system.yml</code></li>
<li>Copy the attached file <code>filebeat.yml</code> to <code>/etc/filebeat/</code></li>
<li>Execute the command: <code>sudo systemctl enable filebeat</code></li>
<li>Execute the command: <code>sudo service filebeat start</code></li>
</ol></li>
</ul></li>
</ol>

<p>I want to Automate this using Chef. The Chef environment is ready and working.I want to deploy this binaries on 150 servers. Would be helpfull if someone explain with step by step.</p>

CC BY-SA 3.0
2018-02-21T19:02:15.770Z
Elastic.co provides repositories IIRC, just use yum_repository and package resources, add a template or file resource for the service and configuration and you should be fine. (that's what I do for Ubuntu boxes)
Tensibai
CC BY-SA 3.0
2018-02-21T20:16:26.567Z
Hey. Thank you. Could you please an example how you do or take my example as itself.
Ilyas khan H
<chef><automation>
How to create Chef Package for Redhat. I have 2 rpms agents and 2 yaml files
Ilyas khan H
# How to create Chef Package for Redhat. I have 2 rpms agents and 2 yaml files

(Asked by: username_0 on 2018-02-21)

1. Installation steps. There are two ELK agents to install:

   * Metricbeat

     1. Copy the attached file `metricbeat-6.0.0-x86_64.rpm` to the target server
     2. Execute the command: `sudo rpm -vi metricbeat-6.0.0-x86_64.rpm`
     3. Copy the attached file `system.yml` to `/etc/metricbeat/modules.d/`
     4. Copy the attached file `metricbeat.yml` to `/etc/metricbeat/`
     5. Execute the command: `sudo systemctl enable metricbeat`
     6. Execute the command: `sudo service metricbeat start`
   * Filebeat

     1. Copy the attached file `filebeat-6.0.0-x86_64.rpm` to the target server
     2. Execute the command: `sudo rpm -vi filebeat-6.0.0-x86_64.rpm`
     3. Execute the command: `sudo mv /etc/filebeat/module.d/system.yml.disabled /etc/filebeat/module.d/system.yml`
     4. Copy the attached file `filebeat.yml` to `/etc/filebeat/`
     5. Execute the command: `sudo systemctl enable filebeat`
     6. Execute the command: `sudo service filebeat start`

I want to Automate this using Chef. The Chef environment is ready and working.I want to deploy this binaries on 150 servers. Would be helpfull if someone explain with step by step.

**Tags:** chef, automation

> **Comments:**
> **username_1**: Elastic.co provides repositories IIRC, just use yum_repository and package resources, add a template or file resource for the service and configuration and you should be fine. (that's what I do for Ubuntu boxes)  
> **username_0**: Hey. Thank you. Could you please an example how you do or take my example as itself.  

---

## 2 answers

### Answer by username_1 on 2018-02-21. Score: 1

Very basic recipe exemple to install filebeat on ubuntu (I do use more or less the same approach for elasticsearch, kibana and logstash):
apt_repository 'elk' do
  uri 'https://artifacts.elastic.co/packages/5.x/apt'
  distribution 'stable'
  components ['main']
  key 'https://artifacts.elastic.co/GPG-KEY-elasticsearch'
  cache_rebuild true
end

package 'filebeat' do
  action :upgrade # To keep up to date with releases from elastic.co
end

service 'filebeat' do
  action [:enable, :start]
end

template '/etc/filebeat/filebeat.yml' do
  source 'filebeat.yml.erb'
  mode '0600'
  notifies :restart, 'service[filebeat]'
end

Basically, adding a repository, installing package, enabling and starting the service, render a config and restart the service when it changes. On ubuntu the package set the service scripts so I don't have to manage it here.
The template is my default configuration using some node attributes depending on environment. See https://docs.chef.io/resource_template.html for more details on how to use them.
According to your question I would strongly sugest you to follow the tutorial paths at https://learn.chef.io to grasp the basics about chef.

> **Comments:**
> **username_0**: Sure.. I will do that.  

---

### Answer by username_2 on 2018-02-21. Score: 0

https://www.google.nl/search?q=how%2Bto%2Bcreate%2Ba%2Bchef%2Bpackage
returns:
https://docs.chef.io/resource_package.html
and
https://docs.chef.io/resource_examples.html
The latter provides code snippets, like how to copy files:

Create a file from a copy
The following example shows how to copy a file from one directory to
  another, locally on a node:
file '/root/1.txt' do
  content IO.read('/tmp/1.txt')
  action :create
end


More example could be found in the supermarket. In order to write chef books one could investigate how some recipes are structured like mysql.

> **Comments:**
> **username_0**: Hey.Thank you.I want to know how to proceed.What I understood from the answer is. The above snippets creates a package after that I have to prepare a recipe?  
> **username_2**: Could you explain why you would like to use chef?  
> **username_0**: I am using it for deployment of the above binaries for all servers  
> **username_2**: Ok, but did you consider puppet, ansible or salt?  
> **username_0**: Hey. I already have an environment of chef  
> **username_0**: Hi, I could able to write cookbook and install filebeat rpm. However I am getting the below error while creating a template.                       Error executing action `create` on resource 'template[/etc/filebeat/filebeat.yml]'  ==================================================Chef::Exceptions::FileNotFound     ------------------------------     Cookbook 'ELK' (0.1.0) does not contain a file at any of these locations:       templates/redhat-6.9/filebeat.yml.erb       templates/redhat/filebeat.yml.erb       templates/default/filebeat.yml.erb       templates/filebeat.yml.erb  
> **username_2**: Could you add this to the question and format it?  

---

