Skip to content

Commit dc3695c

Browse files
committed
Merge pull request realpython#487 from kevinaloys/puppet
Puppet
2 parents ad57363 + a829c84 commit dc3695c

File tree

1 file changed

+88
-2
lines changed

1 file changed

+88
-2
lines changed

docs/scenarios/admin.rst

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,95 @@ Chef
240240
Puppet
241241
------
242242

243-
.. todo:: Write about Puppet
243+
`Puppet <http://puppetlabs.com>`_ is an IT Automation and configuration management
244+
software from Puppet Labs that allows System Administrators to define the state of
245+
their IT Infrastructure, thereby providing an elegant way to manage their fleet of
246+
physical and virtual machines.
247+
248+
Puppet is available both as an Open Source and an Enterprise variant. Modules are
249+
small,shareable units of code written to automate or define the state of a system.
250+
`Puppet Forge <https://forge.puppetlabs.com/>`_ is a repository for modules written
251+
by the community for Open Source and Enterprise Puppet.
252+
253+
Puppet Agents are installed on nodes whose state needs to be monitored or changed.
254+
A desginated server known as the Puppet Master is responsible for orchastrating the
255+
agent nodes.
256+
257+
Agent nodes send basic facts about the system such as to the operating system, kernel,
258+
architecture, ip address, hostname etc. to the Puppet Master.
259+
The Puppet Master then compiles a catalog with information provided by the agents on
260+
how each node should be configured and sends it to the agent. The agent enforces the
261+
change as prescribed in the catalog and sends a report back to the Puppet Master.
262+
263+
Facter is an interesting tool that ships with Puppet that pulls basic facts about
264+
the System. These facts can be referenced as a variable while writing your
265+
Puppet modules.
244266

245-
`Puppet Labs Documentation <http://docs.puppetlabs.com>`_
267+
.. code-block:: console
268+
269+
$ facter kernel
270+
Linux
271+
.. code-block:: console
272+
273+
$ facter operatingsystem
274+
Ubuntu
275+
276+
Writing Modules in Puppet is pretty straight forward. Puppet Manifests together form
277+
Puppet Modules. Puppet manifest end with an extension of ``.pp``.
278+
Here is an example of 'Hello World' in Puppet.
279+
280+
.. code-block:: puppet
281+
282+
notify { 'This message is getting logged into the agent node':
283+
284+
#As nothing is specified in the body the resource title
285+
#the notification message by default.
286+
}
287+
288+
Here is another example with system based logic. Note how the operatingsystem fact
289+
is being used as a variable prepended with the ``$`` sign. Similarly, this holds true
290+
for other facts such as hostname which can be referenced by ``$hostname``
291+
292+
.. code-block:: puppet
293+
294+
notify{ 'Mac Warning':
295+
message => $operatingsystem ? {
296+
'Darwin' => 'This seems to be a Mac.',
297+
default => 'I am a PC.',
298+
},
299+
}
300+
301+
There are several resource types for Puppet but the package-file-service paradigm is all
302+
you need for undertaking majority of the configuration management. The following Puppet code makes sure
303+
that the OpenSSH-Server package is installed in a system and the sshd service is notified to restart
304+
everytime the sshd configuration file is changed.
305+
306+
.. code-block:: puppet
307+
308+
package { 'openssh-server':
309+
ensure => installed,
310+
}
311+
312+
file { '/etc/ssh/sshd_config':
313+
source => 'puppet:///modules/sshd/sshd_config',
314+
owner => 'root',
315+
group => 'root',
316+
mode => '640',
317+
notify => Service['sshd'], # sshd will restart
318+
# whenever you edit this
319+
# file
320+
require => Package['openssh-server'],
321+
322+
}
323+
324+
service { 'sshd':
325+
ensure => running,
326+
enable => true,
327+
hasstatus => true,
328+
hasrestart=> true,
329+
}
330+
331+
For more information checkout `Puppet Labs Documentation <http://docs.puppetlabs.com>`_
246332

247333
Blueprint
248334
---------

0 commit comments

Comments
 (0)