What is Ohai and How to use Ohai in Chef server?
• It is a system discovery tool.
• It gathers system information.
• ohai
• Now run
• ohai ipaddress • ohai hostname • ohai memory/total • ohai cpu/0/mhz
Attributes
• We have a web application to be deployed into 1000 nodes & we need to know some
details of each server.
• Because we need to mention that in the configuration file of each node. This information varies from system to system.
• These details we call “Attributes”
• chef-client tool gathers these Attributes from the ohai store and puts them in configuration files.
• Instead of hard coding these attributes, we mention them as variables.
file '/robofile' do content "This is to get Attributes HOSTNAME: #{node['hostname']} IPADDRESS: #{node['ipaddress']} CPU: #{node['cpu']['0']['mhz']} MEMORY: #{node['memory']['total']}" owner 'root' group 'root' action :create end
Execute
• To execute Linux commands
execute “run a script” do command <<-EOH mkdir /saidir touch /saifile EOH end
User & Group
• We can create users & Groups
Users user “raj” do action :create end Verify : cat /etc/passwd
Group group “devops” do action :create members ‘raj’ append true end Verify : cat /etc/group