Puppet Resources

 • Resources are the fundamental unit for modelling system configurations

• Each resource describes some aspect of a system, like a specific service or package

• A resource declaration is an expression that describes the desired state for a resource and tells Puppet to add it to the catalog

• When Puppet applies that catalog to a target system, it manages every resource it contains, ensuring that the actual state matches the desired state


Resource Type Reference

• From the shell the command line interface: puppet describe file

• For the full list of available descriptions try: puppet describe --list

• Give a glance to Puppet code for the list of native resource types: ls $(facter rubysitedir)/puppet/type


Simple Sample of Resources

• Installation of OpenSSH package 

package { 'openssh': ensure => present, }

• Creation of /etc/motd file 

file { 'motd': path => '/etc/motd', }

• Start of httpd service 

service { 'httpd': ensure => running, enable => true, }


Complex Samples of Resources

• Management of nginx service with parameters defined in module's variables 

service { 'nginx': ensure => $::nginx::manage_service_ensure, name => $::nginx::service_name, enable => $::nginx::manage_service_enable, }

• Creation of nginx.conf with content retrieved from different sources (first found is served) 

file { 'nginx.conf': ensure => present, path => '/etc/nginx/nginx.conf', source => [ "puppet:///modules/site/nginx.conf--${::fqdn}", "puppet:///modules/site/nginx.conf" ], }


Exercise  - Puppet Resources

• Run the following commands in master/agent terminal window.

• Let us take a look at a file resource. This will give information about this file in terms of Puppet resource. It will also show that this file is in fact a symbolic link to an actual file.

puppet resource file /etc/resolv.conf

• Run the following commands in master terminal window to look at the real file that the above file is linking to

puppet resource file /run/resolvconf/resolv.conf

 Now let’s take a look at a service resource. This command will show all service running on my master/agent

service –status-all

 Go to Agent window and run the following command to check the ssh service. Puppet will display a snippet of puppet code for service ssh.

puppet resource service ssh

 Go to Agent window and run the following command to check the package resource. Puppet will display a snippet of puppet code for package vim.

puppet resource package vim

 Go to master window and run the following commands to create a file and edit it

cd /etc/puppet/manifests

nano file.pp

file{“/etc/motd”:

ensure => present,

content => “This is the MOTD\n”,

owner => ‘root’,

mode => ‘0755’,

}

 We created a file with 4 properties ensure its present, the contents of the file, the owner of the file as root and the permissions to the file.

 Go to master window and run the following commands

puppet apply file.pp

 You will see in the output that 2 changes were made to this file. The content was changed and also the permissions on file were changed

 Go to master window and run the following commands

cat /etc/motd

 You will see what we defined in content is in the file.

 Go to master window and run the following commands to create a file and edit it

cd /etc/puppet/manifests

nano package.pp

package{“apache2”:

ensure => present,

}

 Go to master window and run the following commands

puppet apply package.pp

 Now to run Apache webserver service. Go to master window and run the following commands

cd /etc/puppet/manifests

nano service.pp

service{‘apache2’:

ensure => running,

}

 Go to master window and run the following commands

puppet apply service.pp

 This will run Apache webserver as a service on master. Now to run the following command to see Apache service running

ps aux | grep apache

 Go to master window and run the following commands to create a file and edit it

file {"/etc/inetd.conf" :

ensure => link,

target => "/etc/inet/inetd.conf",

}

file {"/root/mysql" :

ensure => 'directory',

}

group {'Administrators':

ensure => present,

gid => '500',

}

user {"mysql" :

ensure => present,

gid => '500',

home => '/home/mysql',

password => '!!',

uid => '99100',

}

file {"/root/mysql/mysql.ini" :

ensure => "file",

mode => '0660',

owner => 'mysql',

group => 'Administrators',

content => 'This is a test ini file',

}

Comments

Popular posts from this blog

Terraform

Scrum Master Interview help - Bootcamp

Kubernetes