Contents Definitions

Contents Definitions ... Puppet Study guide Puppet Installation Flags ... • Orchestration logs:/var/log/puppetlabs Puppet Ports...

0 downloads 202 Views 842KB Size
Contents Definitions.............................................................................................................................................................. 1 Introduction ........................................................................................................................................................... 1 Introduction to Puppet ................................................................................................................................... 1 Puppet Head First ........................................................................................................................................ 1 Nodes .................................................................................................................................................................. 1 InstallingPuppet ...................................................................................................................................................... 1 Puppet Installation Flags ................................................................................................................................ 2 pe.conf................................................................................................................................................................. 2 Installation Directories ................................................................................................................................... 2 Code and Data Directories.............................................................................................................................. 2 Puppet Enterprise Logs .................................................................................................................................. 3 Puppet Ports ...................................................................................................................................................... 3 Puppet Enterprise Services............................................................................................................................ 3 Puppet Enterprise Logs .................................................................................................................................. 5 puppet.conf ........................................................................................................................................................ 5 Resource AbstractionLayer .................................................................................................................................. 9 Resource Type: ............................................................................................................................................. 9 Example .......................................................................................................................................................... 9 Facter .................................................................................................................................................................... 11 CertificateSigningRequest(CSR) ...................................................................................................................... 11 Command: .................................................................................................................................................... 11 DNS altnames: ............................................................................................................................................. 11 On the Puppet Master................................................................................................................................ 13 Deleting SSL Certs on Agent ..................................................................................................................... 13 Autosigning...................................................................................................................................................... 13 $confdir/autosign.conf ............................................................................................................................. 13 Building Modules andClasses ............................................................................................................................. 13 Class Structure ane Names ........................................................................................................................... 13 Class Syntax: ................................................................................................................................................ 13 Example: ....................................................................................................................................................... 14 Module Structure and Names ...................................................................................................................... 14 Module Directories ........................................................................................................................................ 14 Autoloading .......................................................................................................................................................... 16 Example ............................................................................................................................................................ 16 CustomandExternalFacts ................................................................................................................................... 16

Custom Facts ................................................................................................................................................... 16 Example: ....................................................................................................................................................... 16 External Facts.................................................................................................................................................. 18 In a Module: ................................................................................................................................................. 18 On Unix/Linux/OS X: ................................................................................................................................. 18 On Windows: ............................................................................................................................................... 18 On Windows 2003: .................................................................................................................................... 18 STDOUT in the Format: ............................................................................................................................. 18 Structured Data Facts: ............................................................................................................................... 18 DSLOverview........................................................................................................................................................ 20 Resource Types............................................................................................................................................... 20 StyleGuide .............................................................................................................................................................. 20 Spacing, Indentation, and Whitespace ...................................................................................................... 21 Example: ....................................................................................................................................................... 21 Arrays and Hashes ......................................................................................................................................... 21 Example ........................................................................................................................................................ 21 Quoting ............................................................................................................................................................. 23 Example ........................................................................................................................................................ 23 Escape Characters and Comments ............................................................................................................. 23 Example ........................................................................................................................................................ 23 Module Metadata............................................................................................................................................ 23 Example ........................................................................................................................................................ 24 Resources ......................................................................................................................................................... 24 Example ........................................................................................................................................................ 25 Classes and Defined Types ........................................................................................................................... 26 Example ........................................................................................................................................................ 26 Example ........................................................................................................................................................ 26 Chaining Arrow Syntax ................................................................................................................................. 26 Example ........................................................................................................................................................ 26 Nested Classes or Defined Types ................................................................................................................ 27 Example of Bad Behavior: ........................................................................................................................ 28 Parameter ........................................................................................................................................................ 28 Example: ....................................................................................................................................................... 28 Class Inheritance ............................................................................................................................................ 28 Example: ....................................................................................................................................................... 28 Defined Resource Types ............................................................................................................................... 30 Variables........................................................................................................................................................... 30

Good Examples: .......................................................................................................................................... 30 Bad Examples: ............................................................................................................................................. 31 Conditionals..................................................................................................................................................... 31 Example: ....................................................................................................................................................... 31 DataTypes .............................................................................................................................................................. 32 Core Data Types.............................................................................................................................................. 32 Resource and Class References ................................................................................................................... 33 Abstract Data Types....................................................................................................................................... 33 The Type Data Type ....................................................................................................................................... 34 Syntax: .......................................................................................................................................................... 34 Example: ....................................................................................................................................................... 34 RelationshipsandDependencies ......................................................................................................................... 34 Relationship Metaparameters ..................................................................................................................... 34 Chaining Arrows ............................................................................................................................................. 34 Chaining Arrows: Operands ......................................................................................................................... 35 Ordering ........................................................................................................................................................... 35 Refreshing and Notification ......................................................................................................................... 35 Refreshing and Notification ......................................................................................................................... 35 Missing Dependencies ................................................................................................................................... 36 Failed Dependencies...................................................................................................................................... 36 Dependency Cycles ........................................................................................................................................ 36 Conditional Statements .......................................................................................................................................... 36 "If" Statements ................................................................................................................................................ 36 Syntax: .......................................................................................................................................................... 37 Example: ....................................................................................................................................................... 37 Example: ....................................................................................................................................................... 38 "Unless" statements ....................................................................................................................................... 39 Syntax: .......................................................................................................................................................... 39 Example: ....................................................................................................................................................... 39 Case Statements.............................................................................................................................................. 39 Syntax: .......................................................................................................................................................... 39 Example: ....................................................................................................................................................... 41 Example: ....................................................................................................................................................... 43 Selectors ........................................................................................................................................................... 43 Syntax: .......................................................................................................................................................... 43 Example: ....................................................................................................................................................... 43 Example: ....................................................................................................................................................... 45

VariablesandScope................................................................................................................................................ 45 Variable Assignment Example: ............................................................................................................... 46 Array Assignment Example: .................................................................................................................... 46 Hash Assignment Example:...................................................................................................................... 46 Example: ....................................................................................................................................................... 48 Array Example: ........................................................................................................................................... 48 Hash Example: ............................................................................................................................................ 48 Scope ................................................................................................................................................................. 48 Metaparameters .................................................................................................................................................. 50 Example: ....................................................................................................................................................... 50 IterationandLoops ............................................................................................................................................... 50 Example: ....................................................................................................................................................... 52 ClassParametersandDefaults ............................................................................................................................. 52 Syntax: .......................................................................................................................................................... 52 Example: ....................................................................................................................................................... 52 Function Data Provider ................................................................................................................................. 54 Example: ....................................................................................................................................................... 54 PuppetFunctions .................................................................................................................................................. 56 Functions.......................................................................................................................................................... 56 Templates .............................................................................................................................................................. 58 Example: ....................................................................................................................................................... 58 Expression-printing: .................................................................................................................................. 59 If statement: ................................................................................................................................................ 59 Comments: ................................................................................................................................................... 59 Looping: ........................................................................................................................................................ 59 DefinedResourceTypes........................................................................................................................................ 59 Syntax: .......................................................................................................................................................... 61 Declaring an Instance: ............................................................................................................................... 61 Example: ....................................................................................................................................................... 61 ResourceCollectors .............................................................................................................................................. 62 Operators ......................................................................................................................................................... 63 Syntax: .......................................................................................................................................................... 63 Example: ....................................................................................................................................................... 63 ExportedResources.............................................................................................................................................. 63 Purpose............................................................................................................................................................. 63 Syntax: .......................................................................................................................................................... 64 Example: ....................................................................................................................................................... 64

Declaring an Exported Resource ................................................................................................................ 64 Syntax: .......................................................................................................................................................... 64 NTPModule .......................................................................................................................................................... 64 ntp.conf.erb.................................................................................................................................................. 64 ExportedResources.............................................................................................................................................. 66 Roles andProfiles ................................................................................................................................................ 67 Overview .......................................................................................................................................................... 67 Profiles .............................................................................................................................................................. 68 Example: ....................................................................................................................................................... 68 Roles .................................................................................................................................................................. 69 Roles Names Example: .............................................................................................................................. 70 Example: ....................................................................................................................................................... 70 HieraOverview ..................................................................................................................................................... 70 Why use Hiera? ............................................................................................................................................... 70 Setting Up Hiera.............................................................................................................................................. 72 hiera.yaml .................................................................................................................................................... 72 Automatic Parameter Lookup ..................................................................................................................... 72 Hiera Lookup Functions ............................................................................................................................... 73 hiera: ............................................................................................................................................................. 73 hiera_array:.................................................................................................................................................. 73 hiera_hash: ................................................................................................................................................... 73 ManagingandDeployingPuppetCode .................................................................................................................. 73 Overview .......................................................................................................................................................... 73 Set Up and Configuring CodeManager ............................................................................................................... 74 Git URL Example: ........................................................................................................................................ 78 RSA Key Example: ...................................................................................................................................... 78 NginxModule ........................................................................................................................................................ 78 nginx.conf.erb.............................................................................................................................................. 78 vhost.conf.erb .............................................................................................................................................. 79 NodeClassification ............................................................................................................................................... 79 Node Definition Lookup................................................................................................................................ 79 External Node Classifiers.............................................................................................................................. 80 Example: ....................................................................................................................................................... 80 Using Hiera as an ENCs ................................................................................................................................. 80 Example: ........................................................................................................................................................... 80 External Node Classifiers (ENCs) & Site.pp Merging.............................................................................. 80 Puppet OrchestratorOverview ........................................................................................................................... 81

Overview .......................................................................................................................................................... 81 Orchestrator Workflow................................................................................................................................. 82 MCollectiveOverview ........................................................................................................................................... 82 Overview .......................................................................................................................................................... 82 MCollective Plugins:................................................................................................................................... 82 MCollective Components: ......................................................................................................................... 83 UsingMCollective ................................................................................................................................................. 83 Using sudo........................................................................................................................................................ 83 Adding SSH keys ............................................................................................................................................. 83 The mco command ......................................................................................................................................... 83 Using mco help ............................................................................................................................................ 84 Synstax:......................................................................................................................................................... 84 Examples: ..................................................................................................................................................... 84 Host Filters ...................................................................................................................................................... 84 Troubleshooting................................................................................................................................................... 84 Common Installer Problems ........................................................................................................................ 84 Troubleshooting Connections ..................................................................................................................... 86 Example: ....................................................................................................................................................... 86 General Troubleshooting .............................................................................................................................. 88 Database Troubleshooting ........................................................................................................................... 88 Determine What Node Groups the NC Has and What Data They Contain: .................................... 88 Determine What Data the NC Will Generate for a Given Node Name: ........................................... 88 Check /var/log/pe-postgresql/pgstartup.log ..................................................................................... 88 To Set the New Kernel Settings by Run: ................................................................................................ 90 Optimizing the Databases............................................................................................................................. 90 Vacuuming PostgreSQL ............................................................................................................................. 90 Backing Up PostgreSQL............................................................................................................................. 90 Reporting ............................................................................................................................................................. 90 Puppet Enterprise Roles Based Access Control .......................................................................................... 92 RemovingNodes .................................................................................................................................................... 92 On the Agent Node: .................................................................................................................................... 92 On the Puppet Master: .............................................................................................................................. 92 On the Agent Node: .................................................................................................................................... 93 Checking Values ofSettings................................................................................................................................... 93 Puppet ResourceCommand .................................................................................................................................. 93

Puppet Study guide

Definitions • Component modules: Normal modules that manage one particular technology. (Forexample, puppetlabs/apache.) •

FQDN: Fully qualified domainname.



Idempotence: The property of certain operations in mathematics and computer science,that

canbeappliedmultipletimeswithchangingtheresultbeyondtheinitialapplication.Catalogcanbeapplied multiple times without causing issue. • Profiles: Wrapperclassesthat alayeredtechnology stack. •

to configure

Roles:

configuration.

Introduction Introduction to Puppet Puppet Head First •

Install the Puppet Master: ./puppet-enterprise-installer

• InstallthePuppetAgent:curl-khttps://:8140/packages/ current/install.bash | sudo bash •

Puppet module install: puppetlabs-ntp --version6.0.0



Modules installed in /etc/puppetlabs/code/environments/production/modules



site.pp

in/etc/puppetlabs/code/environments/production/m

anifests •

puppet agent -texecutes a Puppet run in the foreground.

Nodes •

Supported Operating Systems

InstallingPuppet •

Install the Puppet Master: ./puppet-enterprise-installer

• InstallthePuppetAgent:curl-khttps://:8140/packages/ current/install.bash | sudo bash -1-

Puppet Study guide

Puppet Installation Flags •

-c-Useape.conffiletoconfigurethePuppetserver.



-D-Displaysdebugginginformation.



-h-Displayhelp



-q-Runinquietmode;theinstallationprocessisnotdisplayed.Requiresanswerfile.



-V-displayveryverbosedebugginginformation



-y-Assumesyes/defaultandbypassany

user input.

pe.conf Thepe.conffile configure

neededtoinstalland

Found in /etc/puppetlabs/enterprise/conf.d Sample pe.conffile: { "console_admin_password": "password", "puppet_enterprise::puppet_master_host": "", "pe_install::puppet_master_dnsaltnames": [ "puppet" ] } Installation Directories Puppet configurationfilesareinstalledin/etc/puppetlabs/puppetfor*nixnodesand \PuppetLabs forWindows nodes. •



PuppetEnterprisesoftwarebinariesareinstalledin/opt/puppetlabs



Executablebinariesarein/opt/puppetlabs/bin



Theinstallerautomaticallycreatessymlinksin/usr/local/bin

/opt/puppetlabs/sbin

Code and Data Directories •

R10k: /etc/puppetlabs/r10k



Environments: /etc/puppetlabs/code/environments



modules: Main directory for puppet modules (applies to master only) -2-

Puppet Study guide



manifests: Contains the main starting point for catalog compilation (applies to master only)



ssl:Containseachnodescertificateinfrastructure(allnodes)/etc/puppetlabs/pupp et/ssl

Puppet Enterprise Logs All Puppet Enterprise logs can be found in /var/log/puppetlabs. •

Puppet master logs:/var/log/puppetlabs/puppetserver



Puppet agent logs: /var/log/messages or/var/log/system.log



ActiveMQ logs:/var/log/puppetlabs/activemq



MCollectiveservice



Console

/var/log/puppetlabs



Installer

/var/log/puppetlabs/installer

/var/log/puppetlabs/

• Database logs: /var/log/puppetlabs/puppetdb and /var/log/puppetlabs/ postgresql •

Orchestration logs:/var/log/puppetlabs

Puppet Ports •

3000: Used

the web-based installer of the PuppetMaster.



8140:The

that the Puppet Master and



61613: Used by MCollective for orchestration requests by Puppet agents.



443:The



5432: PostgreSQL runs on this port. It is used by PuppetDB in a split stackconfiguration.



8081:The



8142: Used by Orchestration services to accept inbound traffic/responses from the Puppetagents.

communicate on.

port used to access the Puppet Enterprise Console.

traffic/requestport.

Puppet Enterprise Services On CentOS 7 the Puppet Enterprise services are installed in /usr/lib/systemd/system. • pe-activemq: The ActiveMQ message server, which passes messages to the MCollective servers on agent nodes. Runs on servers with the Puppet master component. •

pe-console-services: Manages and serves the PEconsole. -3-

Puppet Study guide



pe-puppetserver:ThePuppetmasterserver,whichmanagesthePuppetmastercomponent.

-4-

Puppet Study guide



pe-nginx:Nginx,servesasareverse-proxytothePEconsole.

• mcollective:The MCollective daemon, which listens for messages and invokes actions. Runs on everyagentnode. • puppet(onELandDebianbasedplatforms):ThePuppetagentdaemon.Runsoneveryagent node. • pe-puppetdbandpepostgresql:Daemonsthatmanageandservethedatabasecomponents. NotethatpepostgresqlisonlycreatedifweinstallandmanagePostgreSQLforyou. •

pe-orchestration-services: Runs the Puppet orchestration process.



pxp-agent:RunsthePuppetagent

Puppet Enterprise Logs AllPuppet

/var/log/puppetlabs



Puppetmaster

logs

/var/log/puppetlabs/puppetserver



Puppetagentlogs:/var/log/messages



ActiveMQ



MCollectiveservicelogs:/var/log/puppetlabs/



Console

/var/log/puppetlabs



Installer

/var/log/puppetlabs/installer

/var/log/system.log

/var/log/puppetlabs/activemq

• Database /var/log/puppetlabs/puppetdb and /var/log/puppetlabs/postgresql •

Orchestration logs:/var/log/puppetlabs

puppet.conf Thepuppet.conffileislocated /etc/puppetlabs/puppet. •

Configsections • main is the global section used by all commands and services. It can be overridden by the other sections. •

master is used by the Puppet master service and the Puppet cert command.



agent is used by the Puppet agent service.



user is used by the Puppet apply command -5-

Puppet Study guide

Note: Settings are loaded at service start time, to apply changes made to puppet.conf a restart to the pe- puppet service is required. •

Interpolating variables • The values of settings are available as variables within puppet.conf, and you can insert them into the values of other settings. To reference a setting as a variable, prefix its name with adollar sign. •

Example: •

$codedir



$confdir



$vardi

r Sample puppet.conf [main] certname = master.vagrant.vm server = master.vagrant.vm user = pe-puppet group = pe-puppet environment_timeout=0 app_management = true module_groups = base+pe_only environmentpath = /etc/puppetlabs/code/environments codedir = /etc/puppetlabs/code [agent] graph = true [master] node_terminus = classifier storeconfigs = true storeconfigs_backend = puppetdb reports =puppetdb certname = master.vagrant.vmalways_ca che_features =true Sample puppet.confforan

node. -6-

Puppet Study guide

[main] server = master.vagrant.vm certname =agent1.vagrant.vm •

Basic settings • always_retry_plugins:AffectshowwecacheattemptstoloadPuppetresourcetype sand features. •

basemodulepath: The search path for global modules. Should be specified as a listof

-7-

Puppet Study guide

directories separated by the system path separator character. •

Default:

$codedir/modules:/opt/puppetlabs/puppet/modules



ca_server:Theservertouseforcertificateauthorityrequests.



certname:The name to use when handling certificates.

• dns_alt_names:AlistofhostnamestheserverisallowedtousewhenactingasthePupp et master.Thehostnamethatanagentusesmustbeincludedthislistortheagentwillfailconnecti ng tomaster.Thehostnamecanalsoliveinthecertnamesetting. • environment: Defaults to production, environment to request but can be overridden by masters ENC (External NodeClassifier). •

• environmentpathlist of directories separated bythesystem manifestdirectory of manifests if one exists orifthepathends • reports: list of report names should be comma-separated, with

/

.

multiple report handlers, their (For example, reports = http, log, store.)

• http: reports via HTTP or HTTPS. This report processor submits reportsas POSTrequests to address in the reporturl setting. The body of eachPOSTrequest theYAMLdump of a Puppet::Transaction::Report object, andtheContent-T is set as application/x-yaml. •

log:

all received logs to the local log destinations. Usually the log destination issyslog.

• store Store the YAML reportondisk. this just stores





Default:



rundir



server



ssldir:Thelocation



vardir: The locationwherePuppet

host sends its report as aY file on disk, inthereportdir

dump and .

locationwherePuppetPIDfilesarestored. masterservertowhichthePuppetagent SSLcertsarestored. growing information.

Run behavior settings • ignoreschedules: Schedules allow you to only execute a resource if it's during a specific time period; this setting can disable that feature that might be used when you are doing an initial setup on a node and everything needs to be executed or enforced the first timearound •

noop: Agent will not do any work only simulate changes and report to the master.



postrun_co mand: command to run after Puppet commandexecute -8-

Puppet Study guide



prerun_co mand: command to run before Puppet commandexecutes

• priority:The scheduling priority of the process.Valid values are 'high', 'normal', 'low', or 'idle', which are mapped to platform-specificvalues. •

report:Whethertosendreportsaftereverytransaction.



runinterval:howoftenthepuppetagentdaemonruns

• tags:LimitthePuppetruntoincludeonlyresourceswithcertaintags(cool),specificdat a centers, etc • usecacheonfailure:Whether to remote configuration will notcompile. • waitforcert: time for the

not initially available (gives

Resource AbstractionLayer •

Describing/declaring the state



Providers enforce the desired state

Resource Type: •

Every resource is managed by resource type •

a title



a set

configuration when the

attributes.

{'': <ATTRIBUTE rel="nofollow"> ><VALUE>, } Example user { 'username': ensure >present , uid >'102', gid >'wheel', shell >'/bin/bash', home >'/home/usernam e',managehome >'', -9-<br /> <br /> Puppet Study guide<br /> <br /> }<br /> <br /> - 10 -<br /> <br /> Puppet Study guide<br /> <br /> Commands •<br /> <br /> puppetdescribewillprovideinformationaboutresourcetypeswithinPuppet<br /> <br /> •<br /> <br /> puppetdescribe-llistsallresourcetypesavailable<br /> <br /> •<br /> <br /> puppetdescribe-s<type>givesshortinformationaboutresourcetype<br /> <br /> •<br /> <br /> puppet describe <type>gives a long listing information aboutresource<br /> <br /> •<br /> <br /> puppetresourcewilldescribeinformationaboutresourcesalreadyinstalledonarunningnode<br /> <br /> •<br /> <br /> puppet resource<type><br /> <br /> •<br /> <br /> puppet resource <type><name><br /> <br /> • puppet agent node, this is<br /> <br /> information about the<br /> <br /> •<br /> <br /> puppet agent<br /> <br /> •<br /> <br /> A puppetagent<br /> <br /> Facter •<br /> <br /> facter:Returnsalistallfacts.<br /> <br /> •<br /> <br /> facter<fact>:Returnsaparticularfact.<br /> <br /> •<br /> <br /> facter-pAllowsFactertoloadPuppet-specificfacts.<br /> <br /> CertificateSigningRequest(CSR) Puppet Server includes from nodes, serves commands to sign<br /> <br /> certificate authority (CA) service that accepts certificate ates and a certificate revocation list (CRL) to certificates.<br /> <br /> requests (CSRs) optionally accepts<br /> <br /> Command: puppet cert puppetcertlis t puppet cert sign <NAME>puppet cert revoke <NAME> DNS altnames: puppet cert sign (<HOSTNAME>or --all) --allow-dns-alt-names - 11 -<br /> <br /> Puppet Study guide<br /> <br /> <NAME><br /> <br /> - 12 -<br /> <br /> Puppet Study guide<br /> <br /> Regenerating Certificates On the Puppet Master puppet cert clean<NAME> Deleting SSL Certs on Agent cp -r /etc/puppetlabs/puppet/ssl/ /etc/puppetlabs/puppet/ssl_bak/ Autosigning • Should only be used Puppet master. •<br /> <br /> able to connect to the<br /> <br /> The<br /> <br /> $confdir/autosign.conf •<br /> <br /> .domain.com<br /> <br /> Building Modules andClasses Class Structure ane Names •<br /> <br /> Class names can have: •<br /> <br /> Lowercase letters<br /> <br /> •<br /> <br /> Digits<br /> <br /> •<br /> <br /> Underscores<br /> <br /> \A[a-z][a-z0-9_]*\Z •<br /> <br /> Namespaceseparatorusedouble<br /> <br /> ::<br /> <br /> \A([a-z][a-z0-9_]*)?(::[a-z][a-z0-9_]*)*\Z • [Reserved Variable Names] [Reserved Variable Names]: (https://docs.puppet.com/puppet/4.5/lang_ reserved.html#reserved-variable-names) Class Syntax: class <CLASS_NAME>( - 13 -<br /> <br /> Puppet Study guide<br /> <br /> <DATA_TYPE><PARAM_NAME> ) { …puppetcode . } Example: class ssh { file { "/etc/ssh/ssh_config": ensure >file, source >"puppet:///modules/ssh/ssh_config" } } Module Structure and Names •<br /> <br /> Module •<br /> <br /> Lowercase<br /> <br /> •<br /> <br /> Numbers<br /> <br /> •<br /> <br /> Underscores<br /> <br /> •<br /> <br /> Should begin with a lowercaseletter.<br /> <br /> •<br /> <br /> Module<br /> <br /> •<br /> <br /> Modules cannot be nested<br /> <br /> cannot contain<br /> <br /> namespace separator ( ::<br /> <br /> <MODULE NAME> manifes ts files templat es lib facts.d example s spec functio ns types Module Directories •<br /> <br /> manifests/— Contains all of the manifests in the module. - 14 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> files/—Containsstaticfiles,whichmanagednodescandownload.<br /> <br /> •<br /> <br /> lib/—Containsplugins,likecustomfactsandcustomresourcetypes.<br /> <br /> •<br /> <br /> facts.d/—Containsexternalfacts,whichareanalternativetoRuby-basedcustomfacts.<br /> <br /> - 15 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> templates/—Containstemplates,whichthemodule'smanifestscanuse.<br /> <br /> •<br /> <br /> examples/—Containsexamplesshowinghowtodeclarethemodule'sclassesanddefinedtypes.<br /> <br /> •<br /> <br /> spec/—Containsspectestsforanypluginsinthelibdirectory.<br /> <br /> •<br /> <br /> functions/—ContainscustomfunctionswritteninthePuppetlanguage.<br /> <br /> •<br /> <br /> types/—Containstypealiases.<br /> <br /> Autoloading •<br /> <br /> Names map to thefile •<br /> <br /> First segment<br /> <br /> • •<br /> <br /> The last<br /> <br /> •<br /> <br /> Any segments<br /> <br /> manifestsdirectory.<br /> <br /> Example apache<MODULEDIRECTORY>/apache/manifests/init.pp apache::mod<MODULEDIRECTORY>/apache/manifests/mod.pp apache::mod::passenger-<MODULEDIRECTORY>/apache/manifests/mod/ passenger.pp CustomandExternalFacts Custom Facts •<br /> <br /> Custom<br /> <br /> of Ruby code on the Puppetmaster.<br /> <br /> •<br /> <br /> Usually shell commands are issued as part of the fact to return information.<br /> <br /> •<br /> <br /> Executed on the Puppet nodes with the<br /> <br /> •<br /> <br /> Custom facts are located in<MODULE>lib/facter.<br /> <br /> Plugin Module.<br /> <br /> Example: # hardware_platform.rb Facter.add('hardware_platform') do setcodedo Facter::Core::Execution.exc('/bin/uname --hardware- 16 -<br /> <br /> Puppet Study guide<br /> <br /> platform') end<br /> <br /> - 17 -<br /> <br /> Puppet Study guide<br /> <br /> end •<br /> <br /> Facts distributed using pluginsync •<br /> <br /> Enabled in the [main] section of puppet.conf by settingpluginsync=true<br /> <br /> External Facts External facts provide a way to use arbitrary executables or scripts as facts, or set facts statically with structured data. In a Module: <MODULEPATH>/<MODULE>/facts.d/ On Unix/Linux/OS X: /opt/puppetlabs/facter/facts.d/ /etc/puppetlabs/facter/facts.d/ /etc/facter/facts.d/ On Windows: C:\ProgramData\PuppetLabs\facter\facts.d\ On Windows 2003: C:\DocumentsandSettings\AllUsers\ApplicationData\PuppetLabs\fa cter\ facts.d\ STDOUT in the Format: key1=valu e1 key2=valu e2 key3=valu e3 Structured Data Facts: yam - 18 -<br /> <br /> Puppet Study guide<br /> <br /> l jso n txt<br /> <br /> - 19 -<br /> <br /> Puppet Study guide<br /> <br /> DSLOverview Resource Types •<br /> <br /> Resource types are the basic building blocks of the Puppet DSL.<br /> <br /> •<br /> <br /> Every resource type has: •<br /> <br /> a title<br /> <br /> •<br /> <br /> a set of attributes<br /> <br /> <TYPE>{'<TITLE>': <ATTRIBUTE rel="nofollow"> ><VALUE>, } •<br /> <br /> Example •<br /> <br /> •<br /> <br /> file<br /> <br /> ensure: •<br /> <br /> file: make sure it's a<br /> <br /> •<br /> <br /> directory: makes sure it is a directory (enables recursive)<br /> <br /> •<br /> <br /> linkensures file is a symlink (requires target attribute)<br /> <br /> •<br /> <br /> absent: deletes file if itexists<br /> <br /> Attributes: • • •<br /> <br /> •<br /> <br /> tar<br /> <br /> Review all<br /> <br /> types by visiting the Resource TypeReference<br /> <br /> StyleGuide • The style guide is to promote consistent formatting in the Puppet Language, especially across modules, giving users and developers of Puppet modules a common pattern, design, and style tofollow. •<br /> <br /> Readability matters.<br /> <br /> •<br /> <br /> Scoping and simplicity are key.<br /> <br /> •<br /> <br /> Your module is a piece ofsoftware. - 20 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> Version yourmodules.<br /> <br /> Spacing, Indentation, and Whitespace •<br /> <br /> Module manifests: •<br /> <br /> Must use two-space soft tabs,<br /> <br /> •<br /> <br /> Must not use literal tab characters,<br /> <br /> •<br /> <br /> Must not contain trailing whitespace,<br /> <br /> •<br /> <br /> Must include trailing commas after<br /> <br /> •<br /> <br /> Must end the last line<br /> <br /> attributes and parameterdefinitions,<br /> <br /> • Must use opening •<br /> <br /> between the<br /> <br /> Module •<br /> <br /> Should not<br /> <br /> limit would<br /> <br /> •<br /> <br /> Should leave one empty line<br /> <br /> impractical<br /> <br /> when using dependency chains<br /> <br /> • May align hash rockets (=>) within blocks attributes, one space after longest resource key, arranging hashes for maximum readabilityfirst. Example: file{'/tmp/foo':<br /> <br /> …}<br /> <br /> Arrays and Hashes •<br /> <br /> Each element<br /> <br /> on line<br /> <br /> •<br /> <br /> Each new<br /> <br /> •<br /> <br /> First and last lines used<br /> <br /> indented one level for the syntax of that data type<br /> <br /> Example #arraywithmultipleelementsonmultiplelines service { 'some_service': require >[File['some_conf ig_file'], File['some_sysconfig_fil e'], ], - 21 -<br /> <br /> Puppet Study guide<br /> <br /> }<br /> <br /> - 22 -<br /> <br /> Puppet Study guide<br /> <br /> Quoting •<br /> <br /> All strings must be enclosed in single quotes, unless the string: •<br /> <br /> Contains variables<br /> <br /> •<br /> <br /> Contains single quotes<br /> <br /> •<br /> <br /> Contains escaped characters not supported by single-quoted strings<br /> <br /> • Is an enumerable set of options, such as present/absent, in which case the single quotes are optional •<br /> <br /> All variables must be enclosed in<br /> <br /> in a string.<br /> <br /> • Double quotes should would require an<br /> <br /> single quotes, unless that<br /> <br /> Example file{"/tmp${file_name}": …} "${facts['operatingsystem']} is not supported by ${module_name}" warning("Class[class_name'] doesn't work they way you expected it too.") Escape Characters and Comments •<br /> <br /> Puppet uses backslash as an escapecharacter. •<br /> <br /> •<br /> <br /> Escaping as \\ would be "\\\\"<br /> <br /> Comments must be hash comments (#This comment), not /\* \*/<br /> <br /> Documentation comments for Puppet Strings should be included for each of classes,definedtypes, functions, resource types and providers. •<br /> <br /> Example # Configures sshd file{'/etc/ssh/ssh_config':<br /> <br /> .}<br /> <br /> Module Metadata •<br /> <br /> Every module must have metadata defined in themetadata.jsonfile.<br /> <br /> •<br /> <br /> Hard dependencies must be declared in your module'smetadata.jsonfile.<br /> <br /> •<br /> <br /> Soft dependencies should in theREADME.md. - 23 -<br /> <br /> Puppet Study guide<br /> <br /> Example { "name": "tthomsenmy_module_name", "version": "0.1.0", "author": "TravisN. Thomsen","license": "Apache-2.0", "su mary": "It's a modules that does things", "source":"https://github.com/mygithubaccount/tthomsenmy_module_ name", "project_page":"https://github.com/mygithubaccount/tthomsenmy_ module_name", "issues_url":"https://github.com/mygithubaccount/tthomsenmy_module_ name/issues", "tags": ["things", "and", "stuff"], "operatingsystem_support": [ { "operatingsystem":"Red Hat", "operatingsystemreleas e":[ "5.0", "6.0" ] }, { "operatingsystem": "Ubuntu", "operatingsystemrelease":[ "12.04", "10.04" ] } ], "dependencies": [ { "name": "puppetlabs/stdlib", "version_requirement": " = 3.2.0 <5.0.0" }, ] } Resources - 24 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> All resource names or<br /> <br /> must be quoted.<br /> <br /> •<br /> <br /> Hash rockets (=>) in a resource's attribute/valuelistmay aligned.<br /> <br /> •<br /> <br /> Ensure should be the first attributespecified.<br /> <br /> •<br /> <br /> Resources should be grouped by logical relationship to each other, rather than by resourcetype.<br /> <br /> • Semicolon-separated multiple resource bodies should be used only in conjunction with a local defaultbody. Example file{'/etc/ssh/ssh_config':<br /> <br /> - 25 -<br /> <br /> Puppet Study guide<br /> <br /> ensure >file,m ode >"0600" , } Classes and Defined Types • All classes and resource type definitions (defined types) must be separate files in themanifests directory of the module. Each separate file in the manifest directory of the module should contain nothing other than the class or resource typedefinition. Example #/etc/puppetlabs/code/environments/production/modules/apache/ manifests # init.pp class apache { } #ssl.pp class apache::ssl { } # virtual_host.pp define apache::virtual_host () { } • When a resource include is included in all catalogs. Thiscan have<br /> <br /> class,nodedefinition, definedtype,it and is not always easy to detect.<br /> <br /> Example #manifests/init.pp: class { 'some_class': includesome_other_class } Chaining Arrow Syntax •<br /> <br /> When you<br /> <br /> many interdependent or order-specificitems,chaining<br /> <br /> Example #Pointslefttoright Package['package_name'] >Service['service_name'] #Onthelineoftheright-handoperand Package['package_name'] > Service['service_name'] - 26 -<br /> <br /> be used.<br /> <br /> Puppet Study guide<br /> <br /> Nested Classes or Defined Types •<br /> <br /> Don't define classes and defined resource types in other classes or definedtypes.<br /> <br /> •<br /> <br /> Classes and defined types should be declared as close to node scope aspossible.<br /> <br /> - 27 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> Seriously, dude, don't nest classes or definedtypes!<br /> <br /> Example of Bad Behavior: class some_class { classa_nested_class{ .} } class some_class { definea_nested_define_type(){ .} } Parameter •<br /> <br /> Declare required parameters<br /> <br /> •<br /> <br /> Optional parameters<br /> <br /> •<br /> <br /> Declare<br /> <br /> • For Puppet 4.9.0 for class parameters.<br /> <br /> automatic parameter lookup<br /> <br /> • Puppet versions less than 4.9.0, use specify the default values directly in the class ordefined<br /> <br /> In simple cases, you<br /> <br /> also<br /> <br /> Example: # parameter defaults provided via APL > puppet 4.9.0 class some_module ( String$source, String$config,) { .puppetcode . } Class Inheritance •<br /> <br /> Class inheritance should not be used.<br /> <br /> •<br /> <br /> Usedatabindinginsteadofparams.pppattern.<br /> <br /> •<br /> <br /> Inheritance should only be used for params.pp, which is not recommended in Puppet 4.9.<br /> <br /> • For maintaining older modules inheritance can be used but must not be used across module namespaces. Example: - 28 -<br /> <br /> Puppet Study guide<br /> <br /> classssh{ .} classssh::clientinheritsssh{ classssh::serverinheritsssh{<br /> <br /> .} .}<br /> <br /> - 29 -<br /> <br /> Puppet Study guide<br /> <br /> Defined Resource Types •<br /> <br /> Defined resource types are notsingletons.<br /> <br /> •<br /> <br /> Uniqueness •<br /> <br /> Can have multiple instances.<br /> <br /> •<br /> <br /> Resource names must be unique.<br /> <br /> Variables •<br /> <br /> Referencing facts •<br /> <br /> Whenreferencing •<br /> <br /> $facts<br /> <br /> variables.<br /> <br /> It's<br /> <br /> • • • •<br /> <br /> Distinguishes<br /> <br /> Example: $facts['operatingsystem']<br /> <br /> Namespacing variables • When referencing top-scope variables other than facts, explicitly specify absolute namespaces for clarity improved readability. This includes top-scope variablessetby nodeclassifierand in the main manifest. •<br /> <br /> •<br /> <br /> This<br /> <br /> necessary for:<br /> <br /> •<br /> <br /> the$factshash.<br /> <br /> •<br /> <br /> the$trustedhash.<br /> <br /> •<br /> <br /> the $server_factshash.<br /> <br /> Variable •<br /> <br /> Usenumbers<br /> <br /> •<br /> <br /> Use lowercase letters<br /> <br /> •<br /> <br /> Useunderscores<br /> <br /> •<br /> <br /> Don't use camel case<br /> <br /> •<br /> <br /> Don't use dashes<br /> <br /> Good Examples: •<br /> <br /> $this_is_vairable - 30 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> $so_is_this<br /> <br /> •<br /> <br /> $also_good123<br /> <br /> Bad Examples: •<br /> <br /> $ThisIsNotGood<br /> <br /> •<br /> <br /> $neither-is-this<br /> <br /> Conditionals •<br /> <br /> •<br /> <br /> Keep resource declarations simple. •<br /> <br /> Don't mix conditionals<br /> <br /> •<br /> <br /> Separate<br /> <br /> Defaults •<br /> <br /> Case statements<br /> <br /> •<br /> <br /> Case and selector values<br /> <br /> Example: $file_mode=$facts['os']['family' ]?{ 'Debian'>'0007', 'RedHat' >'0776', default >'0700', } file { '/tmp/readme.txt': ensure >file, content >"HelloWorld\ n", mode >$file_mode, } case $Facts[::operatingsystem] { 'centos':{ $version='1.2.3' } 'debian':{ $version='3.4.5' } default: { fail("Module${module_name}isnotsupportedon ${::operatingsystem}") } } •<br /> <br /> Review the Puppet StyleGuide. - 31 -<br /> <br /> Puppet Study guide<br /> <br /> DataTypes Core Data Types •<br /> <br /> The most common data types:<br /> <br /> - 32 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> String<br /> <br /> •<br /> <br /> Integer, Float, andNumeric<br /> <br /> •<br /> <br /> Boolean<br /> <br /> •<br /> <br /> Array<br /> <br /> •<br /> <br /> Hash<br /> <br /> •<br /> <br /> Regexp<br /> <br /> •<br /> <br /> Undef<br /> <br /> •<br /> <br /> Default<br /> <br /> Resource and Class References •<br /> <br /> Resources<br /> <br /> •<br /> <br /> However,they<br /> <br /> Abstract Data Types •<br /> <br /> Abstract data types let you do more sophisticated or permissive type checking. •<br /> <br /> Scalar<br /> <br /> •<br /> <br /> Collection<br /> <br /> •<br /> <br /> Variant<br /> <br /> •<br /> <br /> Data<br /> <br /> •<br /> <br /> Pattern<br /> <br /> •<br /> <br /> Enum<br /> <br /> •<br /> <br /> Tuple<br /> <br /> •<br /> <br /> Struct<br /> <br /> •<br /> <br /> Optional<br /> <br /> •<br /> <br /> Catalogentry<br /> <br /> •<br /> <br /> Type<br /> <br /> •<br /> <br /> Any<br /> <br /> •<br /> <br /> Callable<br /> <br /> - 33 -<br /> <br /> Puppet Study guide<br /> <br /> The Type Data Type •<br /> <br /> All data types are of typeType.<br /> <br /> Syntax: Type[<ANY DATA TYPE rel="nofollow">] Example: •<br /> <br /> Type: matches any data type, such as Integer String, Any, or Type.<br /> <br /> • Type[String]: matches the like String[3] or Enum["running", •<br /> <br /> of its more specific subtypes<br /> <br /> Type[Resource]<br /> <br /> reference.<br /> <br /> RelationshipsandDependencies Relationship Metaparameters By default, Puppet applies resources in the order they're declared in their manifest. However, if a group of resources must always be managed in a specific order, you should explicitly declarerelationships with relationship metaparameters, chaining arrows, and the require function. •<br /> <br /> before:Appliesaresourcebeforethetargetresource.<br /> <br /> •<br /> <br /> require Applies a resource afterthetar resource.<br /> <br /> • notify: a resource before the target resource.The target resource refreshes if the notifying resource changes. •<br /> <br /> subscribe aresourceafterthetargetresource.Thesubscribing refreshesifthe targetresource<br /> <br /> Chaining Arrows You can create relationships between two resources operators. •<br /> <br /> groups of resources using the -> and ~><br /> <br /> -> ordering arrow: Applies the resource on the left before the resource on theright.<br /> <br /> • ~> notifying arrow: Applies the resource on the left first. If the left-hand resource changes,the right-hand resource will refresh. Both chaining arrows have a reversed form (<- and <~).<br /> <br /> - 34 -<br /> <br /> Puppet Study guide<br /> <br /> Chaining Arrows: Operands •<br /> <br /> The chaining arrows accept the following kinds of operands on either side of the arrow: •<br /> <br /> Resource references, including multi-resource references<br /> <br /> •<br /> <br /> Arrays of resource references<br /> <br /> •<br /> <br /> Resource declarations<br /> <br /> •<br /> <br /> Resource collectors<br /> <br /> Ordering All relationships cause Puppet<br /> <br /> or more other resources.<br /> <br /> Bydefault,unrelated you declare<br /> <br /> manifest file.If<br /> <br /> Refreshing and Notification •<br /> <br /> Some resource types can be refreshed<br /> <br /> •<br /> <br /> Built-in resource types that can refreshed<br /> <br /> •<br /> <br /> •<br /> <br /> service<br /> <br /> •<br /> <br /> mount<br /> <br /> •<br /> <br /> exec<br /> <br /> dependency is changed.<br /> <br /> Sometimes package •<br /> <br /> Rules<br /> <br /> notification and refreshingare:<br /> <br /> •<br /> <br /> Receiving<br /> <br /> •<br /> <br /> Sending<br /> <br /> •<br /> <br /> No-op<br /> <br /> events<br /> <br /> Refreshing and Notification • Certain resource types can have automatic relationships with other resources, using autorequire, autonotify, autobefore, orautosubscribe. •<br /> <br /> A complete list can be found in the resource typereference.<br /> <br /> •<br /> <br /> Auto relationships between types and resources are established when applying a catalog.<br /> <br /> - 35 -<br /> <br /> Puppet Study guide<br /> <br /> Missing Dependencies •<br /> <br /> If one of the resources in a relationship is not declared the catalog will fail tocompile. •<br /> <br /> Could not find dependency <OTHER RESOURCE> for<RESOURCE><br /> <br /> •<br /> <br /> Could not find resource '<OTHER RESOURCE>' for relationship on'<RESOURCE>'.<br /> <br /> Failed Dependencies •<br /> <br /> If a resource with dependencies fails to be applied, all dependent resource will be skipped. •<br /> <br /> notice: <RESOURCE>: Dependency<br /> <br /> •<br /> <br /> warning: <RESOURCE>:<br /> <br /> RESOURCE> has failures: true<br /> <br /> Dependency Cycles • If two or more because this causes a<br /> <br /> be applied<br /> <br /> • err: Could apply complete <OTHER RESOURCE> =><RESOURCE>) •<br /> <br /> cycle: (<RESOURCE> =><br /> <br /> Try the--graphoption and opening the resulting.dotfile in OmniGraffle or GraphViz<br /> <br /> Conditional Statements ConditionalstatementsletyourPuppetcodebehave ferently indifferentsituations. aremosthelpful when combined facts or with data retrieved source. •<br /> <br /> •<br /> <br /> Conditionals<br /> <br /> external<br /> <br /> alter logic:<br /> <br /> •<br /> <br /> if statement<br /> <br /> •<br /> <br /> unless<br /> <br /> •<br /> <br /> case statement<br /> <br /> Conditionals that return a value: •<br /> <br /> selector<br /> <br /> "If" Statements "If" statements take a boolean condition and an arbitrary block of Puppet code, and will only execute the block if the condition is true. They can optionally include elsif and else clauses.<br /> <br /> - 36 -<br /> <br /> Puppet Study guide<br /> <br /> Syntax: if condition { block ofcode } elsif condition { block of code } else { default option } Example: if$facts['os']['name']=='Windo ws'{ includerole::windows } elsif ($facts['os']['name'] == 'RedHat') and ($facts['os']['name'] == 'CentOS') { includerole::redhat } elsif$facts['os']['name']=~/^(Debian|Ubun tu)$/{ includerole::debian } else { include::generic: :os } •<br /> <br /> •<br /> <br /> •<br /> <br /> Behavior •<br /> <br /> The<br /> <br /> •<br /> <br /> If none<br /> <br /> if statement behaves like statements in any otherlanguage. the conditions match and there<br /> <br /> no else block, Puppet will donothing.<br /> <br /> Conditions •<br /> <br /> Variables<br /> <br /> •<br /> <br /> Expressions,<br /> <br /> •<br /> <br /> Functions that return values<br /> <br /> arbitrarily nested and and or expressions<br /> <br /> Regex capture variables - 37 -<br /> <br /> Puppet Study guide<br /> <br /> • If you use a regular expression match operator as your condition, any captures from parentheses in the pattern will be available inside the associated code block as numbered variables ($1, $2, etc.), and the entire match will be available as $0: Example: if$trusted['certname'] =~ /^www(\d+)\./ { notice("This is web servernumber $1.")<br /> <br /> - 38 -<br /> <br /> Puppet Study guide<br /> <br /> } "Unless" statements "Unless" is the reversed "if" statements. It takes a boolean condition and an arbitrary block of Puppet code. It will only execute the block of code if the condition is false. There cannot be a elsif clauses. Syntax: unless condition { block of code } Example: unless $facts['memory']['system']['totalbytes'] > 1073741824 { $maxclient = 500 } •<br /> <br /> Behavior •<br /> <br /> The condition is evaluated first and,ifit false, the code block is executed.<br /> <br /> •<br /> <br /> If the condition is true, Puppet will do nothing.<br /> <br /> • The statement is also an expression that produces a value, and can wherever a value is allowed. •<br /> <br /> •<br /> <br /> used<br /> <br /> Conditions •<br /> <br /> Variables<br /> <br /> •<br /> <br /> Expressions, including arbitrarily nested and and or expressions<br /> <br /> •<br /> <br /> Functions<br /> <br /> return values<br /> <br /> Regex capture variables • Although "unless" statements usually aren't used.<br /> <br /> variables like "if" statements, they<br /> <br /> Case Statements Similar to the "if" statements, case statements choose one of several blocks of arbitrary Puppet code. Syntax: - 39 -<br /> <br /> Puppet Study guide<br /> <br /> case condition {<br /> <br /> - 40 -<br /> <br /> Puppet Study guide<br /> <br /> 'control expression': { block of code } default: { block of code } } Example: case $facts['os']['name'] { 'Windows': {includerole::window s} 'RedHat','CentOS': {includerole::redhat } /^(Debian|Ubuntu)$/:{includerole::de bian} default: {include::generic::o s} } •<br /> <br /> •<br /> <br /> •<br /> <br /> Behavior •<br /> <br /> Compares<br /> <br /> defined.<br /> <br /> •<br /> <br /> The<br /> <br /> •<br /> <br /> The code block<br /> <br /> •<br /> <br /> Amaximum<br /> <br /> •<br /> <br /> If none<br /> <br /> one code<br /> <br /> the cases match, Puppet<br /> <br /> Conditions •<br /> <br /> Variables<br /> <br /> •<br /> <br /> Expressions, including arbitrarily nested and or expressions<br /> <br /> •<br /> <br /> Functions that return values<br /> <br /> Case matching •<br /> <br /> Most<br /> <br /> == equality operator<br /> <br /> •<br /> <br /> Regular<br /> <br /> •<br /> <br /> Data types =~ matching operator<br /> <br /> •<br /> <br /> Arrays are compared to the<br /> <br /> •<br /> <br /> Hashes compare each key/valuepair.<br /> <br /> =~ matching operator<br /> <br /> - 41 -<br /> <br /> Puppet Study guide<br /> <br /> • Default matches anything, and unless nested inside an array or hash, is always tested last, regardless of its position in the list. •<br /> <br /> When used as a value • In addition to executing the code in a block, a case statement is also an expression thatproduces a value, and can be used wherever a value is allowed.<br /> <br /> - 42 -<br /> <br /> Puppet Study guide<br /> <br /> • The value of a case expression is the value of the last expression in the executed block, or undef if no block was executed. •<br /> <br /> Regex capture variables • If you use a regular expression match operator as your condition, any captures from parentheses in the pattern will be available inside the associated code block as numbered variables ($1, $2, etc.), and the entire match will be available as $0:<br /> <br /> Example: case $trusted['certname'] { /www(\d+)/: { notice("This is web server number $1."); } default: { notice("Now for something completely different")} } Selectors Selectorexpressions selectors in variable assignments.<br /> <br /> generally onlyuse<br /> <br /> Syntax: case condition { 'control expression': { block of code } default: { block of code } } Example: $role = $facts['os']['name'] ? { 'Windows' >'role::windo ws', /^(Debian|Ubuntu)$/ >'role::debia n', default >'role::redhat' , } •<br /> <br /> Behavior •<br /> <br /> The entire selector expression is<br /> <br /> value. - 43 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> •<br /> <br /> The control expression is compared to each of the cases in the order they aredefined.<br /> <br /> •<br /> <br /> The default case is evaluated last.<br /> <br /> •<br /> <br /> The value of the matching case is returned.<br /> <br /> •<br /> <br /> If no conditions match the catalog will fail to compile.<br /> <br /> Conditions<br /> <br /> - 44 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> •<br /> <br /> Variables<br /> <br /> •<br /> <br /> Expressions, including arbitrarily nested and and or expressions<br /> <br /> •<br /> <br /> Functions that return values<br /> <br /> Case matching •<br /> <br /> You cannot use lists ofcases.<br /> <br /> •<br /> <br /> Most data types == equality operator<br /> <br /> •<br /> <br /> Regular expressions =~ matching operator<br /> <br /> •<br /> <br /> Data types =~ matching<br /> <br /> •<br /> <br /> Arrays are compared<br /> <br /> • • default regardless of its •<br /> <br /> tested last,<br /> <br /> Regex capture variables • If you use regularexpression match your condition, any captures from parentheses in the pattern will be available inside the associated code block as numbered variables ($1, $2, etc.), and the entire match will be available as $0:<br /> <br /> Example: $role = $facts['os']['name'] ? { /^(Debian|Ubuntu)$/ >"Youarerunning${1}", default >"Youarerunninganunknownoperatingsystem!", } VariablesandScope •<br /> <br /> Variables storevalues so<br /> <br /> •<br /> <br /> Variables are actually constants andcan't<br /> <br /> •<br /> <br /> Facts and built-in variables.<br /> <br /> •<br /> <br /> Variable names are prefixed with a $ (dollarsign).<br /> <br /> •<br /> <br /> They are assigned using the = (equal sign) assignmentoperator.<br /> <br /> •<br /> <br /> Variable names caninclude: •<br /> <br /> be accessedlater.<br /> <br /> Uppercase and lowercase letters - 45 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> •<br /> <br /> •<br /> <br /> Numbers<br /> <br /> •<br /> <br /> Underscores<br /> <br /> Append a variable by using the + symbol •<br /> <br /> '$variable = ['a','b']'<br /> <br /> •<br /> <br /> '$variable += ['c']'<br /> <br /> •<br /> <br /> '$variable now equals ['a', 'b', 'c']'<br /> <br /> Assigning multiple variables •<br /> <br /> You canassign multiple<br /> <br /> •<br /> <br /> Arrays<br /> <br /> hash.<br /> <br /> • • •<br /> <br /> Arrays<br /> <br /> Hashes •<br /> <br /> Variables are listedin an<br /> <br /> the assignmentoperator.<br /> <br /> •<br /> <br /> The hash is on the right of the assignmentoperator.<br /> <br /> •<br /> <br /> Hash keys must match their corresponding variable name.<br /> <br /> Variable Assignment Example: $variable_name1 = "value" Array Assignment Example: [$a, [$a, [$a, [$a,<br /> <br /> $b, $c]= [1,2,3] #$a=1,$b=2,$c=3 [$b, $c]]= [1,[2,3]] #$a=1,$b=2,$c=3 $b] =[1,[2]] # $a = 1, $b = [2] [$b]] =[1,[2]] # $a = 1, $b = 2<br /> <br /> Hash Assignment Example: [$a, $b] = [$a, $c] = {a {a<br /> <br /> > 10, b >20} >5, b > 10, c<br /> <br /> > 15, d<br /> <br /> > 22}<br /> <br /> # $a = 10, $b = # $a 20 = 5, $c = 15<br /> <br /> Variable Interpolation •<br /> <br /> Variable interpolation is when a variables is resolved in a double-quotedstrings. - 46 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> Inside the double-quoted strings the variable is referenced using a dollar sign with curly braces.<br /> <br /> - 47 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> ${var_name}<br /> <br /> •<br /> <br /> Single quotes will treat the variable as a literal.<br /> <br /> Example: $variable="${some_other_variable}isbeinginterpolationinhere." Arrays and Hashes •<br /> <br /> •<br /> <br /> Arrays •<br /> <br /> Arrays are ordered lists of<br /> <br /> •<br /> <br /> There are functions<br /> <br /> functions like each.<br /> <br /> Hashes •<br /> <br /> Hashes<br /> <br /> •<br /> <br /> The entries<br /> <br /> •<br /> <br /> Hashes are merged using the+<br /> <br /> maintained<br /> <br /> Array Example: $array_variable = [ 'a', 'b', 'c'] Hash Example: $hash_variable ={key1 >"value1",key2<br /> <br /> > "value2"}<br /> <br /> Scope •<br /> <br /> Scope is<br /> <br /> •<br /> <br /> Topscope<br /> <br /> of code that is partially isolated from other<br /> <br /> • Code that is outside any class definition, or node definition exists attopscope. Variables and defaults declared at top scope are availableeverywhere. •<br /> <br /> Node scope • Code inside a node definition exists at node scope. Note that since only one node definitioncan match a given node, only one node scope can exist at a time.<br /> <br /> •<br /> <br /> Local scopes - 48 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> Code inside a class definition, defined type, or lambda exists in a localscope.<br /> <br /> - 49 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> Variables and defaults declared in a local scope are only available in that scope and itschildren.<br /> <br /> Metaparameters •<br /> <br /> Metaparameters are attributes that all resource type, custom types and defined typeshave.<br /> <br /> •<br /> <br /> AvailableMetaparameters •<br /> <br /> alias<br /> <br /> •<br /> <br /> audit<br /> <br /> •<br /> <br /> before<br /> <br /> •<br /> <br /> consume<br /> <br /> •<br /> <br /> export<br /> <br /> •<br /> <br /> loglevel<br /> <br /> •<br /> <br /> noop<br /> <br /> •<br /> <br /> notify<br /> <br /> •<br /> <br /> require<br /> <br /> •<br /> <br /> schedule<br /> <br /> •<br /> <br /> stage<br /> <br /> •<br /> <br /> subscribe<br /> <br /> •<br /> <br /> tag<br /> <br /> Example: file {'/etc/ssh/sshd_confi g': owner >root, group >root, alias >'sshdconfig', } service { 'sshd': subscribe >File['sshdconfig'], } IterationandLoops - 50 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> Iteration features are implemented as functions that accept blocks of code calledlambdas.<br /> <br /> •<br /> <br /> List of iteration functions<br /> <br /> - 51 -<br /> <br /> Puppet Study guide<br /> <br /> • each: Repeat a block of code any number of times, using a collection of values to provide different parameters eachtime. • slice: Repeat a block of code any number of times, using groups of values from a collection as parameters. • filter: Use a block of code to transform some data structure by removing nonmatching elements. •<br /> <br /> map: Use a block of code to transform every value in some datastructure.<br /> <br /> •<br /> <br /> reduce: Use a block of code tocreatea valueordatastructurebycombiningvaluesfromaprovideddatastructure.<br /> <br /> • with: Evaluate a block has a family resemblance<br /> <br /> scope. Doesn't iterate, but<br /> <br /> Example: $values = ['a', 'b', 'c', 'd','e'] #functioncallwithlambda: $values.each|String$value|{ notice { "Value from a lambda code block: ${value}": } ClassParametersandDefaults •<br /> <br /> Classes, defined types, and lambdascanall<br /> <br /> •<br /> <br /> Which is<br /> <br /> parameters.<br /> <br /> for you to pass external data.<br /> <br /> Syntax: Class <CLASS NAME>( <DATA TYPE><PARAMETER NAME>, <DATA TYPE><PARAMETER NAME> = <VALUE>, # . ) { # . } Example: class ntp ( Boolean $service_manage = true, Boolean$autoupdate = - 52 -<br /> <br /> }<br /> <br /> Puppet Study guide<br /> <br /> false,String $package_ensure='present ', # . ) {<br /> <br /> - 53 -<br /> <br /> Puppet Study guide<br /> <br /> #<br /> <br /> .<br /> <br /> } params.pp •<br /> <br /> The main classes inherit from a <MODULE>::params class, which only sets variables.<br /> <br /> •<br /> <br /> Using the params.pp pattern is nowdeprecated.<br /> <br /> •<br /> <br /> Using a function or Hiera to your defaults data is now the recommended method.<br /> <br /> Function Data Provider •<br /> <br /> The function provider<br /> <br /> •<br /> <br /> Thisfunction<br /> <br /> •<br /> <br /> It takes<br /> <br /> •<br /> <br /> Setdata_provider<br /> <br /> •<br /> <br /> Puppet will try find therequested<br /> <br /> •<br /> <br /> The <MODULE NAME>::data function can •<br /> <br /> params.pp<br /> <br /> metadata.json<br /> <br /> one of:<br /> <br /> A Puppet language function, located at <MODULE ROOT>/functions/data.pp.<br /> <br /> • ARubyfunction(usingthemodernPuppet::FunctionsAPI),locatedat<MODULEROO T>/ lib/puppet/functions/<MODULENAME>/data.rb. Example: #ntp/metadata.json { . "data_provider": "function" } # ntp/functions/data.pp function ntp::data() { $base_params = { 'ntp::autoupdate' >false,' ntp::service_name' >'ntpd' , } $os_params = case $facts['os']['family'] { 'AIX':{ - 54 -<br /> <br /> Puppet Study guide<br /> <br /> {'ntp::service_name'<br /> <br /> >'xntpd'}<br /> <br /> } 'Debian':{ {'ntp::service_name' >'ntp'} } default: { {}<br /> <br /> - 55 -<br /> <br /> Puppet Study guide<br /> <br /> } } # Merge the hashes and return a single hash. $base_params + $os_params } #ntp/manifests/ini t.pp class ntp ( # default values are inntp/functions/data.pp $autoupdate, $service_name, ) { . } PuppetFunctions There are Functions •<br /> <br /> Statements •<br /> <br /> •<br /> <br /> •<br /> <br /> They do<br /> <br /> returnarguments.<br /> <br /> Rvalues •<br /> <br /> They return values.<br /> <br /> •<br /> <br /> They<br /> <br /> •<br /> <br /> variable assignment<br /> <br /> •<br /> <br /> case<br /> <br /> only be used in a statement<br /> <br /> a value.<br /> <br /> Statement •<br /> <br /> alert<br /> <br /> ontheserveratlevelalert.<br /> <br /> •<br /> <br /> create_resources:<br /> <br /> •<br /> <br /> err:Logamessageontheserveratlevelerr.<br /> <br /> •<br /> <br /> fail: Fail with a parse error.<br /> <br /> ahashintoasetof<br /> <br /> andaddsthemtothecatalog.<br /> <br /> • hiera_include: Uses an array merge lookup to retrieve the classes array, so every node gets every class from thehierarchy. • include: Declares one or more classes, causing the resources in them to be evaluated and addedtothecatalog. - 56 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> warning:Logamessageontheserveratlevelwarning.<br /> <br /> - 57 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> Rvalue Functions • defined: Determines whether a given class or resource type is defined and returns a Boolean value. •<br /> <br /> file: Loads a file from a module and returns its contents as a string.<br /> <br /> • generate: Calls an external command on the Puppet master and returns the results of the command. • hiera: Performs a standard priority lookup of the hierarchy and returns the most specific value for a given key. •<br /> <br /> hiera_array: Findsallmatches thehierarchyandreturnsthemasasingleflattenedarrayofunique<br /> <br /> • hiera_hash merged<br /> <br /> •<br /> <br /> returnsthemina<br /> <br /> •<br /> <br /> regsubst<br /> <br /> •<br /> <br /> sha1:Returns<br /> <br /> •<br /> <br /> template LoadsanERB evaluatesit,andreturnstheresultingvalueasastring.<br /> <br /> Review the [Puppet Function list].<br /> <br /> [Puppet Function<br /> <br /> (https://docs.puppet.com/puppet/latest/function.html)<br /> <br /> Templates • template Loads an ERB template from a module, evaluates it,andreturns resulting value as a string. •<br /> <br /> Atemplate •<br /> <br /> •<br /> <br /> by template(<MODULE NAME>/<TEMPLATE FILE>)<br /> <br /> template('modulename/motd.erb')<br /> <br /> The file is located in <MODULES DIRECTORY>/<MODULE NAME>/templates/motd.erb<br /> <br /> Example: file { '/etc/motd': ensure >file, content >template('modulename/motd.erb') }<br /> <br /> - 58 -<br /> <br /> Puppet Study guide<br /> <br /> Embedded Ruby (ERB) Template Syntax •<br /> <br /> ERB is a templating language based onRuby.<br /> <br /> •<br /> <br /> Puppetusesthetemplateandinline_templatefunctionstoevaluateatemplatefile.<br /> <br /> Expression-printing: <%= @value %> If statement: <% ifcondition%> .text .<% end %> Comments: <%# This is a co ment.%> Looping: <% @valuse.each -%> <% do |values| %>some value <%= value %> <% end -%> DefinedResourceTypes •<br /> <br /> Defined<br /> <br /> types alsocalleddefined<br /> <br /> ordefines.<br /> <br /> •<br /> <br /> Are blocks<br /> <br /> •<br /> <br /> They act<br /> <br /> •<br /> <br /> They are<br /> <br /> •<br /> <br /> Definitions should be stored themanifests/directory.<br /> <br /> •<br /> <br /> Defined type instance caninclude<br /> <br /> •<br /> <br /> Defined type names can consist of one or more namespacesegments.<br /> <br /> •<br /> <br /> Each namespace segment must begin with a lowercase letter and caninclude:<br /> <br /> code that can be evaluated multiple times with differentparameters. resource type.<br /> <br /> •<br /> <br /> Lowercase letters<br /> <br /> •<br /> <br /> Digits<br /> <br /> resource type.<br /> <br /> - 59 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> Underscores<br /> <br /> - 60 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> Namespace segments should match the following regular expression: •<br /> <br /> \\A[a-z]\[a-z0-9_\]\*\\Z<br /> <br /> •<br /> <br /> define_name123<br /> <br /> • Multiple namespace segments can be joined together in a define type name with the ::(double colon) namespaceseparator. •<br /> <br /> \\A(\[a-z\][a-z0-9_]\*)?(::[a-z]\[a-z0-9_]\*)\*\\Z<br /> <br /> •<br /> <br /> module_name::defined_type_name<br /> <br /> Syntax: define name ( <DATA TYPE><PARAMETER> = <VALUE>, ) { .puppetcode . } Declaring an Instance: <DEFINED TYPE>{'<TITLE>': <ATTRIBUTE rel="nofollow"> ><VALUE>, } Example: define apache::vhost ( Integer $port, String[1]$docroot, String$servername=$titl e, String[1]$vhost_name='* ', ) { # . } apache::vhost {'mywebsite': port >80, docroot >'/var/www/mywebsite', }<br /> <br /> - 61 -<br /> <br /> Puppet Study guide<br /> <br /> ResourceCollectors •<br /> <br /> Resource collectors also called the spaceshipoperator.<br /> <br /> •<br /> <br /> It selects a group of resources by searching the attributes of every resource in the catalog.<br /> <br /> •<br /> <br /> This search is independent ofevaluation-order.<br /> <br /> - 62 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> Collectors realize virtual resources.<br /> <br /> •<br /> <br /> Can be used in chaining statements<br /> <br /> •<br /> <br /> Can override resource attributes.<br /> <br /> •<br /> <br /> Can function as both a statement and a value.<br /> <br /> •<br /> <br /> The resource type, capitalized.<br /> <br /> Operators •<br /> <br /> ==<br /> <br /> •<br /> <br /> !=<br /> <br /> •<br /> <br /> and<br /> <br /> •<br /> <br /> or<br /> <br /> Syntax: <RESOURCE TYPE><| <SEARCH EXPRESSION> |> Example: User <| groups == 'admin' |> ExportedResources •<br /> <br /> Exported resources require catalog storage and searching to be enabled on Puppetmaster.<br /> <br /> •<br /> <br /> Formerly<br /> <br /> •<br /> <br /> Both the<br /> <br /> •<br /> <br /> Exported resource declaration specifies a desired state fora<br /> <br /> •<br /> <br /> It does not manage the resource on<br /> <br /> •<br /> <br /> Publishes the resource for use by other nodes.<br /> <br /> •<br /> <br /> Any node can then collect the exported resource and manage its own copy of it.<br /> <br /> "storeconfigs". and the searching (among other features) are<br /> <br /> PuppetDB.<br /> <br /> Purpose • Exported resources allow the Puppet compiler to share information among nodes by combining information from multiple nodes' catalogs. - 63 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> This helps you manage things that rely on nodes knowing the states or activity of other nodes.<br /> <br /> Syntax: class <CLASS NAME>{ #Declare: @@<RESOURCE BEING EXPORTED>{ <TITLE>: <ATTRIBUTE rel="nofollow"> ><VALUE>, } #Collect: <REFERENCE RESOURCE BEING EXPORTED><<| |>> } Example: class ssh { #Declare: @@sshkey{$::hostname : type >dsa, key >$::sshdsakey, } # Collect: Sshkey <<| |>> } Declaring an Exported Resource • To declare exported resource, prepend @@ (a double "at" sign) to the resource type of a standard resource declaration: Syntax: @@<RESOUCE TYPE>{ <TITLE>: <ATTRIBUTE rel="nofollow"> ><VALUE>, } NTPModule ntp.conf.erb # File Managed by Puppet #Formoreinformationaboutthisfile,seethemanpages #ntp.conf(5),ntp_acc(5),ntp_auth(5),ntp_clock(5),ntp_misc(5),ntp_ - 64 -<br /> <br /> Puppet Study guide<br /> <br /> mon(5). driftfile /var/lib/ntp/drift #Permittimesynchronizationwithourtimesource,butdonot #permitthesourcetoqueryormodifytheserviceonthissystem. restrictdefaultnomodifynotrapnopeernoquery<br /> <br /> - 65 -<br /> <br /> Puppet Study guide<br /> <br /> #Permitallaccessovertheloopbackinterface. Thiscould #betightenedaswell,buttodosowouldeffectsomeof # the administrative functions. restrict 127.0.0.1 restrict ::1 # Hosts on local network are less restricted. #restrict192.168.1.0mask255.255.255.0nomodifynotrap #Usepublicserversfromthepool.ntp.orgproject. #Pleaseconsiderjoiningthepool(http://www.pool.ntp.org/join.htm l). <% @servers.each do |server| -%> <%= server %> <% end -%> #broadcast192.168.1.255autokey # broadcast server #broadcastclient # broadcastclient #broadcast224.0.1.1autokey #multicastserver #multicastclient224.0.1.1 #multicastclient #manycastserver 239.255.254.254 # manycastserver #manycastclient 239.255.254.254 autokey # manycast client # Enable public key cryptography. #crypto includefile/etc/ntp/crypto/pw #Keyfilecontainingthekeysandkeyidentifiersusedwhenoperating #withsymetrickeycryptography. keys /etc/ntp/keys #Specifythekeyidentifierswhicharetrusted. #trustedkey 4 8 42 #Specifythekeyidentifiertousewiththentpdcutility. #requestkey 8 #Specifythekeyidentifiertousewiththentpqutility. #controlkey 8 #Enablewritingofstatisticsrecords. #statistics clockstats cryptostats loopstatspeerstats #Disablethemonitoringfacilitytopreventamplificationattacksusi ng ntpdc #monlistcomandwhendefaultrestrictdoesnotincludethenoquery flag. See #CVE-2013-5211formoredetails. #Note:Monitoringwillnotbedisabledwiththelimitedrestrict ion flag. disablemonitor ExportedResources [puppet-sshkeys] - 66 -<br /> <br /> Puppet Study guide<br /> <br /> Roles andProfiles Overview<br /> <br /> - 67 -<br /> <br /> Puppet Study guide<br /> <br /> Therolesandprofilesareusedtobuildreliable, reusable, configurable, andrefactorablesystemconfigurations. They are two extra layers of indirection between your node classifier and your component modules. • (Component modules: Normal modules that manage one particular technology. (Forexample, puppetlabs/apache.) • Profiles:Wrapperclassesthatusemultiplecomponentmodulestoconfigurealayeredtechnolog y stack. •<br /> <br /> Roles:Wrapperclassesthatusemultipleprofilestobuildacompletesystemconfiguration.<br /> <br /> Profiles •<br /> <br /> A profile is justa<br /> <br /> • Make on them.<br /> <br /> declarations<br /> <br /> •<br /> <br /> Profiles caninclude<br /> <br /> •<br /> <br /> Profilesownall<br /> <br /> •<br /> <br /> Components class shouldn't use a value<br /> <br /> •<br /> <br /> There are<br /> <br /> class parameters data.<br /> <br /> ways a profile can get the data it needs to configure componentclasses:<br /> <br /> •<br /> <br /> Hardcode it in theprofile.<br /> <br /> •<br /> <br /> Look<br /> <br /> from Hiera.<br /> <br /> Example: classprofiles::apache( String$apache_vhost_na me, String$apache_vhost_docroot, Bolean $apache_default_vhost = false, String$apache_vhost_port=80, ) { class { 'apache': default_vhost >$apache_default_vhost, } apache::vhost{$apache_vhost_nam e: port >$apache_vhost_port, docroot >$apache_vhost_docro - 68 -<br /> <br /> Puppet Study guide<br /> <br /> ot, } } Roles •<br /> <br /> The only thing roles should do is declare profileclasses.<br /> <br /> - 69 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> Useinclude<PROFILENAME>.<br /> <br /> •<br /> <br /> Don't declare any component classes or normal resources in a role.<br /> <br /> •<br /> <br /> Roles can use conditional logic to decide which profiles touse.<br /> <br /> •<br /> <br /> Roles should not have any class parameters of their own.<br /> <br /> •<br /> <br /> Roles should not set class parameters for anyprofiles.<br /> <br /> • The name of a role should be based on your business's conversational name for the type of node it manages. •<br /> <br /> Assigning a role to a node •<br /> <br /> The PE console node<br /> <br /> •<br /> <br /> The main<br /> <br /> •<br /> <br /> Hiera<br /> <br /> Roles Names Example: role::web role::jenkins::master role::jenkins::slave Example: class role::web { includeprofile::bas e includeprofile::apa che includeprofile::ph p } HieraOverview •<br /> <br /> Hiera is a key/value datastore for looking up data.<br /> <br /> •<br /> <br /> Let you set node-specific datawithout<br /> <br /> Why use Hiera? •<br /> <br /> Single source of truth for your data. - 70 -<br /> <br /> Puppet Study guide<br /> <br /> • •<br /> <br /> Configure default data with hierarchaloverrides.<br /> <br /> Use Puppet modules from theforge. •<br /> <br /> No need to edit the module, just put the data in Hiera.<br /> <br /> - 71 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> Publish your own modules for collaboration. •<br /> <br /> Keeps your data out of your module before sharing it.<br /> <br /> •<br /> <br /> No more clashing variable names.<br /> <br /> Setting Up Hiera •<br /> <br /> Thehiera.yamlfile is located in/etc/puppetlabs/puppet/.<br /> <br /> • :backends:tells Hiera what kind of data sources it should process. In this case, we'll be using YAMLfiles. •<br /> <br /> :yaml:configures theYAML<br /> <br /> •<br /> <br /> :datadir:tells<br /> <br /> •<br /> <br /> :hierarchy:<br /> <br /> •<br /> <br /> •<br /> <br /> Separate<br /> <br /> •<br /> <br /> Morespesific<br /> <br /> •<br /> <br /> Least spesific at thebottom.<br /> <br /> You can use facts in your Hieralookups.<br /> <br /> hiera.yaml --:backends: -yaml :yaml: :datadir:"/etc/puppetlabs/code/environments/%{environment} /hieradata" :hierarchy: - "nodes/%{::trusted.certname}" - comon Automatic Parameter Lookup •<br /> <br /> Process of automatic parameter<br /> <br /> •<br /> <br /> Look for parameters passed using the class {} declaration • If no pass parameter it will look in hiera data source for the parameter <CLASS NAMESPACE>::parameter •<br /> <br /> If not found in hiera data source it will use the default set "default" - 72 -<br /> <br /> Puppet Study guide<br /> <br /> Hiera Lookup Functions hiera: Performsastandardprioritylookupofthehierarchyandreturnsthemostspecificvalueforagivenkey.The returned value can be any type of data. Arguments: •<br /> <br /> A string key that Hiera searches for in the hierarchy.Required.<br /> <br /> •<br /> <br /> An optional default value to return if Hiera<br /> <br /> •<br /> <br /> The optional name of an arbitrary<br /> <br /> find anything matching thekey. top of thehierarchy.<br /> <br /> hiera_array: Findsall values. Ifanyof an array merge lookup.<br /> <br /> ofunique This iscalled<br /> <br /> Arguments: •<br /> <br /> Astring key<br /> <br /> Hiera searches for in the<br /> <br /> Required.<br /> <br /> •<br /> <br /> An optional default value to return if Hiera doesn't find anything matching thekey.<br /> <br /> •<br /> <br /> The optional name of an arbitrary hierarchy level to insert the top of thehierarchy.<br /> <br /> hiera_hash: Finds all matches a key throughout the hierarchy and returns them in a merged hash. If any of the matchedhashes keys, the final hashusesthe from thehighestpriority This iscalleda hash mergelookup. Arguments: •<br /> <br /> A string key that Hiera searches for in the hierarchy.Required.<br /> <br /> •<br /> <br /> An optional default value to<br /> <br /> •<br /> <br /> The optional name of an arbitrary hierarchy level to insert at the top of thehierarchy.<br /> <br /> if Hieradoesn'tfind<br /> <br /> matching thekey.<br /> <br /> ManagingandDeployingPuppetCode Overview •<br /> <br /> Code Manager and r10k are used to manage and deploying your Puppet code.<br /> <br /> - 73 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> •<br /> <br /> •<br /> <br /> Install Puppet modules.<br /> <br /> •<br /> <br /> Create and maintain environments.<br /> <br /> •<br /> <br /> Deploy new code to your masters.<br /> <br /> •<br /> <br /> Keep your module code in Git.<br /> <br /> Code Manager automates the management and deployment of your new Puppet code. •<br /> <br /> Push your code updates to your Gitrepository.<br /> <br /> •<br /> <br /> Puppet creates environmentsbasedoff<br /> <br /> •<br /> <br /> Installs modules.<br /> <br /> •<br /> <br /> Deploys and<br /> <br /> •<br /> <br /> All<br /> <br /> branch.<br /> <br /> You canr10k •<br /> <br /> Youshould<br /> <br /> •<br /> <br /> Code Manager works withr10k.<br /> <br /> •<br /> <br /> Both tool are built into Puppet Enterprise.<br /> <br /> •<br /> <br /> Create a<br /> <br /> •<br /> <br /> Set up Puppetfiles, if you want to install modules in yourenvironments.<br /> <br /> •<br /> <br /> Configure Code Manager(recommended)<br /> <br /> •<br /> <br /> Existing environments will not preserved.<br /> <br /> •<br /> <br /> /etc/puppetlabs/code/environments/production will be overwritten.<br /> <br /> repository for maintaining your environments and code.<br /> <br /> Set Up and Configuring CodeManager •<br /> <br /> Create your own control repo.<br /> <br /> wgethttps://github.com/puppetlabs/controlrepo/archive/production.zip yuminstallunzip-y unzip production.zip cdproduction •<br /> <br /> Create a control repo in GitHub. •<br /> <br /> Log in to your Github account. - 74 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> Click Repositories.<br /> <br /> - 75 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> •<br /> <br /> Click the New button.<br /> <br /> •<br /> <br /> Enter puppet-control for the Repository name.<br /> <br /> •<br /> <br /> Click CreateRepository.<br /> <br /> Initialize your the control repo. •<br /> <br /> Check in code.<br /> <br /> •<br /> <br /> Add remote repo.<br /> <br /> •<br /> <br /> Push code.<br /> <br /> git init git remote add origin <URL_TO_REPOSITORY>git co mit -am "first co mit" git push origin master •<br /> <br /> Create an<br /> <br /> mkdir-p/etc/puppetlabs/puppetserver/ssh ssh-keygen -trsa -b 4096 -C "your_email@example.com" •<br /> <br /> Enter the path to where the rsa key will go. •<br /> <br /> /etc/puppetlabs/puppetserver/ssh/id_rsa<br /> <br /> •<br /> <br /> Press enter<br /> <br /> an empty passphrase<br /> <br /> •<br /> <br /> Make sure<br /> <br /> is owned by pe-puppet<br /> <br /> chmod -R pe-puppet:pe-puppet /etc/puppetlabs/puppetserver/ssh •<br /> <br /> Update PE<br /> <br /> node group.<br /> <br /> •<br /> <br /> Add the<br /> <br /> parameters to thepuppet_enterprise::profile::master<br /> <br /> •<br /> <br /> code_manager_auto_configure totrue<br /> <br /> •<br /> <br /> update r10k_remotewith<br /> <br /> •<br /> <br /> updater10k_private_keywiththepathtoyourrsakey<br /> <br /> /etc/puppetlabs/puppetserver/ssh/id_rsa •<br /> <br /> Executeapuppetagent-tonthePuppetmasterserver. - 76 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> View code managerconfiguration.<br /> <br /> r10k deploy display --fetch<br /> <br /> - 77 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> Create a deployuser.<br /> <br /> •<br /> <br /> Reset the password for your deployuser.<br /> <br /> •<br /> <br /> Add the deploy user to the Code Deployers User role.<br /> <br /> •<br /> <br /> Create a token for your deployuser.<br /> <br /> puppet-accesslogin--serviceurlhttps://<HOSTNAMEOFPUPPETENTERPRISECONSOLE>:4433/rbacapi--lifetime180d. •<br /> <br /> Deploying your code to themaster.<br /> <br /> puppet-code deploy --all--wait Git URL Example: git@<YOUR.GIT.SERVER.COM>:puppet/control.git RSA Key Example: "/etc/puppetlabs/puppetserver/ssh/id-control_repo.rsa" NginxModule nginx.conf.erb # File Managed by Puppet user <%= @process_user %>; worker_processes <%=@processorcount%>;error_log <%= @log_dir %>/error.log;pid <%=@pid_file%>; events { worker_connections 1024; } http { server_tokens off; include <%=@config_dir%>/mime.types ; default_type - 78 -<br /> <br /> Puppet Study guide<br /> <br /> application/octet-stream; access_log <%=@log_dir%>/access.log;se ndfile on; #tcp_nopush on; tcp_nodelay on; include<%=@confd%>/*.conf; <% if@vdir_enable %> include<%=@vdir_enable%>/*; <% end %> } vhost.conf.erb # File Managed by Puppet server { listen<%=@port%>; root <%= @vhost_docroot%>; server_name <%= @name %><%= @serveraliases %>; access_log <%=@log_dir%>/<%=@name%>.access.log; error_log <%=@log_dir%>/<%=@name%>.error.log; } NodeClassification Node Definition Lookup Node Definition Attempt to match webserver01.mylabserver Attempt to webserver01.mylabserver Attempt to webserver01 Match Default No Match (if no default) Note: if a node with no guarantee<br /> <br /> multiple node definitions which one it will use. - 79 -<br /> <br /> regular expressions, puppet<br /> <br /> use ONE of them<br /> <br /> Puppet Study guide<br /> <br /> External Node Classifiers • ENCs can standard node definitions insite.pp, and each source are effectivelymer •<br /> <br /> node_terminus:TellsPuppet •<br /> <br /> declared in<br /> <br /> using.<br /> <br /> Default node_terminus=classifier<br /> <br /> •<br /> <br /> external_nodes:ThisisthepathtotheexecutableoftheENC<br /> <br /> •<br /> <br /> Replace node_terminus=console withnode_terminus=exec.<br /> <br /> Example: [master] node_terminus = exec<br /> <br /> external_nodes=/usr/local/bin/puppet_node_classifier Using Hiera as an ENCs • hiera_include: Assigns classes to a node using an array merge lookup that retrieves the value for a user-specified key from Hiera'sdata. •<br /> <br /> You can use Hiera as an ENCby: •<br /> <br /> Use your default node insites.pp<br /> <br /> •<br /> <br /> Add hiera_include('classes'))<br /> <br /> •<br /> <br /> Define classes inyour<br /> <br /> Example: # Assuming apache.yaml: classes: - role::apache # Assuming co mon.yaml: classes: - role::base External Node Classifiers (ENCs) & Site.pp Merging •<br /> <br /> A Puppet catalog is made upof: •<br /> <br /> ENCs<br /> <br /> • All executable<br /> <br /> with thesite.ppby mer<br /> <br /> node objects<br /> <br /> specified in the node object defined insite.ppORnode_terminus - 80 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> Any<br /> <br /> resources which are in the site manifest but outside<br /> <br /> definitions<br /> <br /> Puppet OrchestratorOverview Overview • The Puppet orchestrator is a set of interactive command line tools that give you the ability to control the rollout of configuration changes when and how you wantthem. •<br /> <br /> Tools: •<br /> <br /> puppetjob •<br /> <br /> Allows you to manage and enforce the order if Puppet agent runs across an environment.<br /> <br /> - 81 -<br /> <br /> Puppet Study guide<br /> <br /> • Enforces the order of agent runs by instantiating an application model and assigning nodes to application components. •<br /> <br /> puppet app • Lets you view the application models and application instances written and stored on the Puppetmaster. •<br /> <br /> Lets you see what is available to include in an orchestration run.<br /> <br /> •<br /> <br /> You control when Puppet runs and where node catalogs areapplied.<br /> <br /> •<br /> <br /> You no longer need to waiton arbitrary<br /> <br /> update your nodes.<br /> <br /> Orchestrator Workflow •<br /> <br /> WritePuppet<br /> <br /> •<br /> <br /> puppet parservalidate<br /> <br /> • puppet app show looks correct. •<br /> <br /> application instances<br /> <br /> puppet job plan commandto applicationinstancesandthenoderunorderthatwouldbeincludedinajob.<br /> <br /> • puppet job run command to enforce change on your infrastructure and configureyour application. • •<br /> <br /> The<br /> <br /> with the--noop<br /> <br /> puppet job show commandtoreview<br /> <br /> abouttherun.<br /> <br /> MCollectiveOverview Overview •<br /> <br /> Puppet Enterprise includes MCollective.<br /> <br /> •<br /> <br /> Which is used to invoke actions in<br /> <br /> •<br /> <br /> You can write custom plugins to add newactions.<br /> <br /> •<br /> <br /> MCollective is built around the idea of predefinedactions.<br /> <br /> •<br /> <br /> It is essentially a highly parallel remote procedure call (RPC) system.<br /> <br /> •<br /> <br /> Actions are distributed in plugins<br /> <br /> multiple nodes.<br /> <br /> MCollective Plugins:<br /> <br /> - 82 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> package:Installanduninstallsoftwarepackages.<br /> <br /> •<br /> <br /> puppet:RunPuppetagent,getitsstatus,andenable/disableit.<br /> <br /> •<br /> <br /> puppetral:ViewresourceswithPuppet'sresourceabstractionlayer.<br /> <br /> •<br /> <br /> rpcutil: General helpful actions that expose stats and internals to SimpleRPC clients.<br /> <br /> •<br /> <br /> service: Start and stop systemservices.<br /> <br /> MCollective Components: • pe-activemq: Service (whichrunson related messages.<br /> <br /> master server) routes all MCollective-<br /> <br /> • pe-mcollective: and invokes actions in<br /> <br /> for authorized commands<br /> <br /> • mco authorized commands<br /> <br /> ssue<br /> <br /> UsingMCollective •<br /> <br /> To run MCollective commands youmust: •<br /> <br /> Be logged in to the Puppet masterserver.<br /> <br /> •<br /> <br /> Use the peadmin user account.<br /> <br /> •<br /> <br /> By<br /> <br /> the peadmin account cannot<br /> <br /> with a password.<br /> <br /> Using sudo sudo -i -u peadmin Adding SSH keys •<br /> <br /> You can have other users to runcommands.<br /> <br /> •<br /> <br /> Add the user's public SSH keys to peadmin's authorized keysfile.<br /> <br /> •<br /> <br /> /var/lib/peadmin/.ssh/authorized_keys<br /> <br /> The mco command •<br /> <br /> All MCollective actions are invoked with the mcocommand.<br /> <br /> •<br /> <br /> The mco command relies on a configfile.<br /> <br /> - 83 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> /var/lib/peadmin/.mcollective<br /> <br /> •<br /> <br /> It is only readable by the peadmin use.<br /> <br /> Using mco help mcohelp mco help <SUBCOMMAND> mco <SUBCOMMAND>-help Synstax: mco <SUBCOMMAND><ACTION rel="nofollow"> mco rpc <AGENT PLUGIN rel="nofollow"><ACTION rel="nofollow"><INPUT =<VALUE> Examples: mcoping mcorpcrpcutilping mco rpc service restart service=puppet Host Filters •<br /> <br /> -W, --withFILTER<br /> <br /> Combined classes and facts filter<br /> <br /> •<br /> <br /> -S,--select FILTER<br /> <br /> •<br /> <br /> -F, --wf--with-factfact=valMatch hosts with a certain fact<br /> <br /> •<br /> <br /> -C, --wc--with-classCLASS Match<br /> <br /> •<br /> <br /> -A, --wa--with-agentAGENT Match hosts with a certain agent<br /> <br /> •<br /> <br /> -I, --wi--with-identityIDENTMatch hosts with a certain configured identity<br /> <br /> Compound filter combining facts andclasses<br /> <br /> with a certain config management class<br /> <br /> Troubleshooting Common Installer Problems •<br /> <br /> Check yourDNS<br /> <br /> •<br /> <br /> Puppet communicates on ports 8140, 61613, and 443.<br /> <br /> • If you are installing the console and the Puppet master on separate servers and tried to install the console first, the installer mayfail. - 84 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> Recovering from a failed install.<br /> <br /> - 85 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> If you encounter errors during installation, you can fix them and run the installeragain.<br /> <br /> Troubleshooting Connections •<br /> <br /> Troubleshooting connections betweencomponents •<br /> <br /> Is the agent able to reach the Puppet master?<br /> <br /> •<br /> <br /> Try 'telnet <puppet master's hostname>8140'<br /> <br /> •<br /> <br /> Make sure the agent can reach the DNS name that is configured inpuppet.conf.<br /> <br /> •<br /> <br /> Check that the pe-puppetserver service<br /> <br /> •<br /> <br /> Make sure the agent has<br /> <br /> •<br /> <br /> Check the logs •<br /> <br /> •<br /> <br /> Revoke thecertificate •<br /> <br /> On the master: •<br /> <br /> •<br /> <br /> puppet cert clean <NODENAME><br /> <br /> On the agent: • rm-r$(puppetagent--configprintssldir) t (or--test)<br /> <br /> Troubleshooting<br /> <br /> puppetagent-<br /> <br /> filebucket:<br /> <br /> If you get the following error during a Puppet run: err: /Stage[main]/Pe_mcollective/File[/etc/puppetlabs/mcollective / server.cfg] /content:change from {md5}778087871f76ce08be02a672b1c48bdc to{md5} e33a27e4b9a 87bb17a2bdff115c4b080 failed: Could not back up/etc/puppetlabs/ mcollective/se rver.cfg: getaddrinfo: Name or service not known Example: #Definefilebucket'mai n': filebucket{'main': server > '<PUPPET MASTER'S DNS NAME>', - 86 -<br /> <br /> Puppet Study guide<br /> <br /> path<br /> <br /> >false,<br /> <br /> }<br /> <br /> - 87 -<br /> <br /> Puppet Study guide<br /> <br /> General Troubleshooting •<br /> <br /> Use--profiloraddprofiletotrueintheagent'spuppet.conffile.<br /> <br /> •<br /> <br /> Use--logdestand--debugtologadditionaldetailstosyslog.<br /> <br /> Database Troubleshooting •<br /> <br /> Troubleshootclassification •<br /> <br /> You can cURL the console to troubleshoot the nodeclassifier.<br /> <br /> Determine What Node Groups the NC Has and What Data They Contain: curl https://$(hostname -f):4433/classifier-api/v1/groups >classifier_ groups.json --cacert/etc/puppetlabs/puppet/ssl/certs/ca.pem -cert/etc/puppetlabs/puppet/ssl/certs/<WHITELISTEDCERTNAME >.pem --key /etc/puppetlabs/puppet/ssl/private_keys/<WHITELISTED CERTNAME>.pem Determine What Data the NC Will Generate for a Given Node Name: curl https://$(hostname -f):4433/classifierapi/v1/classified/ nodes/<SOMENODENAME>>node_classification.json --cacert/etc/puppetlabs/puppet/ssl/certs/ca.pem -cert/etc/puppetlabs/puppet/ssl/certs/<WHITELISTEDCERTNAME >.pem --key /etc/puppetlabs/puppet/ssl/private_keys/<WHITELISTED CERTNAME>.pem •<br /> <br /> PostgreSQL •<br /> <br /> •<br /> <br /> taking up too much space<br /> <br /> PostgreSQL should have autovacuum=on set bydefault.<br /> <br /> PostgreSQL<br /> <br /> memory causes PE install to fail<br /> <br /> Check /var/log/pe-postgresql/pgstartup.log FATAL: could not create shared memory segment: No space left ondeviceDETAIL:Failedsystemcallwasshmget(key=5432001, size=34427584512,03600). - 88 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> Tweaking the machine's shmmax and shmall kernel settings before installingPE. •<br /> <br /> shmmax should equal 50% of the total RAM.<br /> <br /> •<br /> <br /> shmall should be calculated by dividing the new shmmax setting by thePAGE_SIZE.<br /> <br /> •<br /> <br /> Get the PAGE_SIZE by running getconfPAGE_SIZE.<br /> <br /> - 89 -<br /> <br /> Puppet Study guide<br /> <br /> To Set the New Kernel Settings by Run: sysctl -w kernel.sh max=<your sh max calculation>sysctlwkernel.shmall=<yourshmallcalculation> Optimizing the Databases •<br /> <br /> •<br /> <br /> Changing PuppetDB's parameters. •<br /> <br /> PuppetDBparametersaresetinthejetty.ini.<br /> <br /> •<br /> <br /> jetty.iniismanagedbyPE.<br /> <br /> •<br /> <br /> You need toupdate the<br /> <br /> overwritten.<br /> <br /> Changing the •Onthedatabase •<br /> <br /> psql execute<br /> <br /> ALTER USER console PASSWORD '<newpassword>';<br /> <br /> •<br /> <br /> Edit /etc/puppetlabs/puppetdb/conf.d/database.ini and update password.<br /> <br /> •<br /> <br /> Start the pe-puppetdb service.<br /> <br /> Vacuuming PostgreSQL su - pe-postgres -s /bin/bash -c "vacuumdb -z --verbose <DATABASE NAME>" Backing Up PostgreSQL sudo -u pe-postgres /opt/puppetlabs/server/apps/postgresql/bin/pg_ dumpallc-f<BACKUP_FILE>.sql Reporting •<br /> <br /> Information found on reports: •<br /> <br /> Total: Total number of resources beingmanaged.<br /> <br /> •<br /> <br /> Skipped: How many resources were skipped (either due to tags or schedule metaparameter).<br /> <br /> •<br /> <br /> Scheduled: How many resources met the scheduling restriction, if one is present. - 90 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> Out of Sync: How many resources were out of sync (not in the desired configurationstate).<br /> <br /> •<br /> <br /> Applied: How many resources were aelempted to be put into the desired configurationstate.<br /> <br /> - 91 -<br /> <br /> Puppet Study guide<br /> <br /> • Failed: How many resources were not successfully fixed (put into the desiredconfiguration state).<br /> <br /> •<br /> <br /> •<br /> <br /> •<br /> <br /> Restarted: How many resources were restarted.<br /> <br /> •<br /> <br /> Failed restarts: how many resources could not be restarted.<br /> <br /> •<br /> <br /> Total time for configuration run (puppet agentexecution).<br /> <br /> •<br /> <br /> How long it took to retrieve the configuration (compiled catalog) from the puppetmaster.<br /> <br /> Built in report processors •<br /> <br /> http: send reports to https/http.<br /> <br /> •<br /> <br /> log: Send logs to local<br /> <br /> •<br /> <br /> store:<br /> <br /> setting<br /> <br /> Report •<br /> <br /> tagmail: send<br /> <br /> Puppet Enterprise Roles Based Access Control RBAC Permissions RemovingNodes •<br /> <br /> You will<br /> <br /> to do the following step to<br /> <br /> •<br /> <br /> Deactivates the node in PuppetDB.<br /> <br /> •<br /> <br /> Deletes<br /> <br /> •<br /> <br /> Frees<br /> <br /> •<br /> <br /> Allows you to re-use<br /> <br /> a node from Puppet Enterprise:<br /> <br /> Puppet master's information cache for the node. that the node was using. hostname for a new node.<br /> <br /> On the Agent Node: service puppet stop On the Puppet Master: puppet node purge <CERTNAME>puppet agent-t service pe-puppetserver restart - 92 -<br /> <br /> Puppet Study guide<br /> <br /> •<br /> <br /> If the deactivated node still shows up, stop MCollective.<br /> <br /> On the Agent Node: servicemcollectivestop /etc/puppetlabs/mcollective/ssl/clients. Checking Values ofSettings •<br /> <br /> puppetmaster--configprint<CONFIGNAME><br /> <br /> •<br /> <br /> puppetconfigprint<CONFIGNAME><br /> <br /> •<br /> <br /> puppetconfigprint<CONFIGNAME>--section<SECTIONNAME><br /> <br /> Puppet ResourceCommand •<br /> <br /> puppet resource <RESOURCENAME><br /> <br /> •<br /> <br /> puppet resource <RESOURCENAME><br /> <br /> - 93 -<br /> <br /> </div> </div> </div> </div> </div> </div> </div> </div> <div class="modal fade" id="report" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <form role="form" method="post" action="https://zombiedoc.com/report/contents-definitions" style="border: none;"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">Report "Contents Definitions"</h4> </div> <div class="modal-body"> <div class="form-group"> <label>Your name</label> <input type="text" name="name" required="required" class="form-control" /> </div> <div class="form-group"> <label>Email</label> <input type="email" name="email" required="required" class="form-control" /> </div> <div class="form-group"> <label>Reason</label> <select name="reason" required="required" class="form-control"> <option value="">-Select Reason-</option> <option value="pornographic" selected="selected">Pornographic</option> <option value="defamatory">Defamatory</option> <option value="illegal">Illegal/Unlawful</option> <option value="spam">Spam</option> <option value="others">Other Terms Of Service Violation</option> <option value="copyright">File a copyright complaint</option> </select> </div> <div class="form-group"> <label>Description</label> <textarea name="description" required="required" rows="3" class="form-control" style="border: 1px solid #cccccc;"></textarea> </div> <div class="form-group"> <div style="display: inline-block;"> <div class="g-recaptcha" data-sitekey="6LfZ4lUUAAAAABcx8T21A6fGZmGsmLUKNLplEfvt"></div> </div> </div> <script src='https://www.google.com/recaptcha/api.js'></script> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="submit" class="btn btn-success">Send</button> </div> </form> </div> </div> </div> <script> $(document).ready(function () { var inner_height = $(window).innerHeight() - 250; $('#pdfviewer').css({"height": inner_height + "px"}); }); </script> <footer class="footer" style="margin-top: 60px;"> <div class="container-fluid"> Copyright © 2022 ZOMBIEDOC.COM. All rights reserved. <div class="pull-right"> <span><a href="https://zombiedoc.com/about">About Us</a></span> | <span><a href="https://zombiedoc.com/privacy">Privacy Policy</a></span> | <span><a href="https://zombiedoc.com/term">Terms of Service</a></span> | <span><a href="https://zombiedoc.com/copyright">Copyright</a></span> | <span><a href="https://zombiedoc.com/contact">Contact Us</a></span> </div> </div> </footer> <!-- Modal --> <div class="modal fade" id="login" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close" on="tap:login.close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="add-note-label">Sign In</h4> </div> <div class="modal-body"> <form action="https://zombiedoc.com/login" method="post"> <div class="form-group"> <label class="sr-only" for="email">Email</label> <input class="form-input form-control" type="text" name="email" id="email" value="" placeholder="Email" /> </div> <div class="form-group"> <label class="sr-only" for="password">Password</label> <input class="form-input form-control" type="password" name="password" id="password" value="" placeholder="Password" /> </div> <div class="form-group"> <div class="checkbox"> <label class="form-checkbox"> <input type="checkbox" name="remember" value="1" /> <i class="form-icon"></i> Remember me </label> <label class="pull-right"><a href="https://zombiedoc.com/forgot">Forgot password?</a></label> </div> </div> <button class="btn btn-success btn-block" type="submit">Sign In</button> </form> <hr style="margin-top: 15px;" /> <a href="https://zombiedoc.com/login/facebook" class="btn btn-facebook btn-block"><i class="fa fa-facebook"></i> Login with Facebook</a> <hr style="margin-top: 15px;" /> <a href="https://zombiedoc.com/register" style="text-align: center; display: block;"><i class="fa fa-key"></i> Create an account</a> </div> </div> </div> </div> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-118282339-1"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-118282339-1'); </script> <script src="https://zombiedoc.com/assets/js/jquery-ui.min.js"></script> <link rel="stylesheet" href="https://zombiedoc.com/assets/css/jquery-ui.css"> <script> $(function () { $("#document_search").autocomplete({ source: function (request, response) { $.ajax({ url: "https://zombiedoc.com/suggest", dataType: "json", data: { term: request.term }, success: function (data) { response(data); } }); }, autoFill: true, select: function( event, ui ) { $(this).val(ui.item.value); $(this).parents("form").submit(); } }); }); </script> </html>