devops:puppet
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| devops:puppet [2023/11/01 07:15] – removed - external edit (Unknown date) 127.0.0.1 | devops:puppet [2023/11/01 07:15] (current) – ↷ Page moved from camunda:devops:puppet to devops:puppet skipidar | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ===== Puppet ===== | ||
| + | The Learning VM TUtorial is here: https:// | ||
| + | |||
| + | Te learning VM is available here: https:// | ||
| + | |||
| + | |||
| + | ==== Glossary ==== | ||
| + | |||
| + | |||
| + | |Resources |< | ||
| + | Describing node configuration works by declaring resources. Server provides the descriptions of relevant resources to the nodes then. | ||
| + | |||
| + | Resource may describe | ||
| + | * a single file | ||
| + | * a package | ||
| + | * a service daemons | ||
| + | * a maintenance tasks | ||
| + | |||
| + | Abstract declaration of a resource " | ||
| + | < | ||
| + | user { ' | ||
| + | ensure | ||
| + | comment | ||
| + | gid => ' | ||
| + | home => '/ | ||
| + | password | ||
| + | password_max_age => ' | ||
| + | password_min_age => ' | ||
| + | shell => '/ | ||
| + | uid => ' | ||
| + | } | ||
| + | </ | ||
| + | </ | ||
| + | |Classes |< | ||
| + | The class is the next level of abstraction above a resource. \\ | ||
| + | Groups the resources. \\ | ||
| + | Groups other classes. | ||
| + | |||
| + | Class may describe | ||
| + | * describe entire system role as " | ||
| + | * some abstract aspect as " | ||
| + | |||
| + | To **define** a class - means to describe it in a module, so that it can be used on nodes. \\ | ||
| + | To **declare** a class - means to apply the class to a node. So it will execute there and do its modifications, | ||
| + | |||
| + | <fc # | ||
| + | |||
| + | </ | ||
| + | | defined resource types | like classes, but appliable to nodes multiple times | | ||
| + | |node definition | The task of configuring which classes will be applied to a given node - is called **node classification**. \\ Node definitions are a puppet concept to write node classification down. | | ||
| + | |.pp manifests|< | ||
| + | Puppet language files. | ||
| + | |||
| + | Rules | ||
| + | * Must use UTF8 encoding | ||
| + | * May use Unix (LF) or Windows (CRLF) line breaks (note that the line break format also affects literal line breaks in strings) | ||
| + | </ | ||
| + | |Modules|< | ||
| + | A Puppet module is a self-contained bundle of all the Puppet code and other data needed to manage some aspect of your configuration. \\ You can download pre-built modules from the [[https:// | ||
| + | </ | ||
| + | |Puppet master | The puppet server which configures the puppet agents| | ||
| + | |Puppet agent| Installed on machines, which should be controlled by puppet (by puppet master)| | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ==== Commands ==== | ||
| + | |||
| + | | puppet module search < | ||
| + | | puppet module install < | ||
| + | | puppet agent --test \\ puppet agent -t| manually trigger puppet agent run. \\ Puppet run is the check for new configurations. \\ It usually occurs every 30 Minutes automatically| | ||
| + | | puppet resource user root | check user root as resource | | ||
| + | | puppet describe user | describe resource " | ||
| + | | puppet apply -e "user { ' | ||
| + | | puppet apply --noop -e "user | --noop allows to try out what would be if your would do that on the node | | ||
| + | | puppet resource -e user galatea | Modify resourece user in VIM. (**ESC i** is editing. **:wq** is quit and save.) | | ||
| + | |< | ||
| + | puppet resource package fortune-mod ensure=absent \\ | ||
| + | puppet resource package cowsay ensure=absent provider=gem | ||
| + | </ | ||
| + | |puppet master --configprint all \\ puppet config print graphdir |print configs| | ||
| + | |puppet module list|print module list| | ||
| + | |tree -L 2 -d / | ||
| + | Print the modules as a tree, and only modules from one location, limiting modules to 2 levels | ||
| + | < | ||
| + | âââ cowsayings | ||
| + | â  âââ examples | ||
| + | â  âââ manifests | ||
| + | âââ graphite | ||
| + | â  âââ manifests | ||
| + | â  âââ spec | ||
| + | â  âââ templates | ||
| + | âââ vsftpd | ||
| + | âââ examples | ||
| + | âââ manifests | ||
| + | âââ templates | ||
| + | âââ tests | ||
| + | </ | ||
| + | </ | ||
| + | ==== Class example in modules ==== | ||
| + | |||
| + | == definition == | ||
| + | |||
| + | |||
| + | Class **definition** - description of the class. Done before association with nodes. | ||
| + | < | ||
| + | # / | ||
| + | class cowsayings:: | ||
| + | package { ' | ||
| + | ensure => present, | ||
| + | provider => ' | ||
| + | } | ||
| + | } | ||
| + | |||
| + | # / | ||
| + | class cowsayings:: | ||
| + | package { ' | ||
| + | ensure => present, | ||
| + | } | ||
| + | } | ||
| + | |||
| + | # / | ||
| + | class cowsayings { | ||
| + | include cowsaying:: | ||
| + | include cowsaying:: | ||
| + | } | ||
| + | |||
| + | |||
| + | Pefix **cowsayings** is the name of the module in this case. | ||
| + | Default path **manifests/ | ||
| + | |||
| + | == declaration == | ||
| + | |||
| + | Class **declaration** of a class " | ||
| + | < | ||
| + | # / | ||
| + | include cowsayings:: | ||
| + | </ | ||
| + | |||
| + | Class **declaration** of a parent class " | ||
| + | Parent class " | ||
| + | < | ||
| + | # / | ||
| + | include cowsayings | ||
| + | </ | ||
| + | |||
| + | |||
| + | == Apply == | ||
| + | |||
| + | Apply the class " | ||
| + | < | ||
| + | puppet apply / | ||
| + | </ | ||
| + | |||
| + | Apply the parent class " | ||
| + | < | ||
| + | puppet apply / | ||
| + | </ | ||
| + | |||
| + | == Parameterized class include == | ||
| + | You can pass some parameters, when including external classes. \\ | ||
| + | Here instead of writing **include poodle** and so accepting the defaults, | ||
| + | we define the **$ensure to be true**. | ||
| + | |||
| + | example of **NO parametrized** poodle class include | ||
| + | < | ||
| + | node ' | ||
| + | include basicstuff | ||
| + | include poodle | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | example of **parametrized** poodle class include \\ | ||
| + | Here **NO INCLUDE-keyword** was used. | ||
| + | < | ||
| + | node ' | ||
| + | include basicstuff | ||
| + | class { ' | ||
| + | $ensure => ' | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== Defined Resource types ==== | ||
| + | |||
| + | * Use **define** keyword instead of **class** | ||
| + | * **$title** is a special variable, which must be unique on a node and is mandatory | ||
| + | * Binding of parameter variables ($content, $password) to values happens in parallel, meaning that you cannot use the value of one parameter to set another. The exception is the $title variable. | ||
| + | |||
| + | |||
| + | # / | ||
| + | < | ||
| + | define web_user:: | ||
| + | $content | ||
| + | $password = undef, | ||
| + | ) { | ||
| + | $home_dir | ||
| + | $public_html = " | ||
| + | user { $title: | ||
| + | ensure | ||
| + | password => $password, | ||
| + | } | ||
| + | file { [$home_dir, $public_html]: | ||
| + | ensure => directory, | ||
| + | owner => $title, | ||
| + | group => $title, | ||
| + | mode => ' | ||
| + | } | ||
| + | file { " | ||
| + | ensure | ||
| + | owner => $title, | ||
| + | group => $title, | ||
| + | replace => false, | ||
| + | content => $content, | ||
| + | mode => ' | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | **Declaration** of users on a node. \\ | ||
| + | ' | ||
| + | |||
| + | # / | ||
| + | < | ||
| + | web_user:: | ||
| + | web_user:: | ||
| + | content | ||
| + | password => pw_hash(' | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== Classes Metaparameter ==== | ||
| + | |||
| + | Defines relationships between resources. | ||
| + | |||
| + | == before / required== | ||
| + | Define the ordering of reources, in which they have to be installed | ||
| + | |||
| + | SSH config File required package " | ||
| + | <ode> | ||
| + | file { '/ | ||
| + | ensure | ||
| + | source | ||
| + | require | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Package " | ||
| + | **before** turns the requirenments around | ||
| + | < | ||
| + | package { ' | ||
| + | ensure => present, | ||
| + | before => Service[' | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | You can generate a graph, to check resource dependencies | ||
| + | < | ||
| + | # generate the dependency graph | ||
| + | puppet apply sshd/ | ||
| + | |||
| + | # check where the .dot graphs are going to | ||
| + | puppet config print graphdir | ||
| + | |||
| + | #generate a png | ||
| + | dot -Tpng / | ||
| + | </ | ||
| + | ==== Files ==== | ||
| + | |||
| + | You can distribute files via puppet. \\ | ||
| + | Files under modules " | ||
| + | |||
| + | == Add File to module == | ||
| + | To create a module, which will distribute a config file do: \\ | ||
| + | add the config files to **/ | ||
| + | |||
| + | == Create file distributing class == | ||
| + | |||
| + | Creating a **class vimrc** to distribute file " | ||
| + | < | ||
| + | class vimrc { | ||
| + | file { '/ | ||
| + | ensure => present, | ||
| + | source => ' | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | The URL to file in puppet-module | ||
| + | < | ||
| + | puppet:// | ||
| + | </ | ||
| + | |||
| + | |server hostname|the name of the puppet server. Can omit that, when referencing the default server.| | ||
| + | |mount point|Where are the files? \\ **modules** is a shortcut, to the folders with puppet modules| | ||
| + | |remainder of path|Module name **vimrc**. \\ All files are always under **files** dir, so omit that. \\ **vimrc** is the name of the file. | | ||
| + | |||
| + | So path becomes | ||
| + | |||
| + | ^File^URL^ | ||
| + | | / | ||
| + | |||
| + | |||
| + | Make sure that puppet has **the rights** to change the file | ||
| + | < | ||
| + | chown pe-puppet: | ||
| + | </ | ||
| + | |||
| + | == Apply == | ||
| + | Create as usual a **init.pp** with **include vimrc**. | ||
| + | |||
| + | Install by | ||
| + | < | ||
| + | puppet apply vimrc/ | ||
| + | </ | ||
| + | |||
| + | ==== Default node definition ==== | ||
| + | |||
| + | Manifest **site.pp** \\ | ||
| + | in / | ||
| + | defines the default node configuration. | ||
| + | |||
| + | ==== Node setup ==== | ||
| + | |||
| + | Puppet master provides a bash script for setting up nodes: | ||
| + | < | ||
| + | curl -k https://< | ||
| + | </ | ||
| + | |||
| + | Puppet MASTER keeps signed certificates of each Node, which is a part of the infrastructure. | ||
| + | To involve a node - sighn its certificate. | ||
| + | |||
| + | List all unsigned certificates of Nodes. Executable on master. | ||
| + | < | ||
| + | puppet cert list | ||
| + | </ | ||
| + | |||
| + | Sign a certificate of node named **webserver.learning.puppetlabs.vm ** | ||
| + | < | ||
| + | puppet cert sign webserver.learning.puppetlabs.vm | ||
| + | </ | ||
| + | |||
| + | ==== Variables ==== | ||
| + | |||
| + | Definition | ||
| + | < | ||
| + | $doc_root = '/ | ||
| + | </ | ||
| + | |||
| + | Access | ||
| + | < | ||
| + | " | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | class web { | ||
| + | |||
| + | $doc_root = '/ | ||
| + | |||
| + | $english = 'Hello world!' | ||
| + | $french = ' | ||
| + | |||
| + | file { " | ||
| + | ensure => present, | ||
| + | content => "< | ||
| + | } | ||
| + | |||
| + | file { " | ||
| + | ensure => present, | ||
| + | content => "< | ||
| + | } | ||
| + | |||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== Facts ==== | ||
| + | Global variables, available via **facter** or in code (like variables). | ||
| + | |||
| + | Output facts | ||
| + | < | ||
| + | facter -p | less | ||
| + | facter operatingsystem | ||
| + | </ | ||
| + | |||
| + | Syntax to access facts in code | ||
| + | < | ||
| + | $::factname | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | class accounts ($user_name) { | ||
| + | |||
| + | if $:: | ||
| + | $groups = ' | ||
| + | } | ||
| + | elsif $:: | ||
| + | $groups = ' | ||
| + | } | ||
| + | else { | ||
| + | fail( "This module doesn' | ||
| + | } | ||
| + | |||
| + | notice ( " | ||
| + | |||
| + | ... | ||
| + | |||
| + | } | ||
| + | </ | ||
| + | |||
| + | Apply manifest, with modified facts, via prefix: | ||
| + | < | ||
| + | FACTER_factname=new_value | ||
| + | </ | ||
| + | |||
| + | Example | ||
| + | < | ||
| + | FACTER_operatingsystem=Debian puppet apply --noop accounts/ | ||
| + | </ | ||
| + | ==== Class parameters ==== | ||
| + | |||
| + | **Define** a class, with parameters, which can be modifed later on. | ||
| + | < | ||
| + | class classname ( $parameter = ' | ||
| + | ... | ||
| + | } | ||
| + | < | ||
| + | |||
| + | < | ||
| + | class web ( $page_name=" | ||
| + | </ | ||
| + | |||
| + | |||
| + | **Declare** (include on a node) a class, with parameters. \\ | ||
| + | Fill them with values. | ||
| + | < | ||
| + | class {' | ||
| + | parameter => ' | ||
| + | } | ||
| + | < | ||
| + | |||
| + | < | ||
| + | class {' | ||
| + | page_name => ' | ||
| + | message | ||
| + | } | ||
| + | </ | ||
| + | ==== Puppet master (server) Configurations ==== | ||
| + | |||
| + | You can retrieve ALL puppet configurations by executing | ||
| + | < | ||
| + | puppet master --configprint all | ||
| + | </ | ||
| + | |||
| + | Or just single lines by doing | ||
| + | < | ||
| + | puppet master --configprint agent_catalog_run_lockfile | ||
| + | puppet master --configprint agent_disabled_lockfile | ||
| + | ... | ||
| + | puppet master --configprint modulepath | ||
| + | ... | ||
| + | </ | ||
| + | |||
| + | Example configuration | ||
| + | < | ||
| + | agent_catalog_run_lockfile = / | ||
| + | agent_disabled_lockfile = / | ||
| + | allow_duplicate_certs = false | ||
| + | always_cache_features = true | ||
| + | app_management = true | ||
| + | archive_file_server = learning.puppetlabs.vm | ||
| + | archive_files = true | ||
| + | autoflush = true | ||
| + | autosign = / | ||
| + | basemodulepath = / | ||
| + | bindaddress = 0.0.0.0 | ||
| + | binder_config = | ||
| + | bucketdir = / | ||
| + | ca = true | ||
| + | ca_name = Puppet CA: learning.puppetlabs.vm | ||
| + | ca_port = 8140 | ||
| + | ca_server = learning.puppetlabs.vm | ||
| + | ca_ttl = 157680000 | ||
| + | cacert = / | ||
| + | cacrl = / | ||
| + | cadir = / | ||
| + | cakey = / | ||
| + | capass = / | ||
| + | caprivatedir = / | ||
| + | capub = / | ||
| + | catalog_cache_terminus = store_configs | ||
| + | catalog_terminus = compiler | ||
| + | cert_inventory = / | ||
| + | certdir = / | ||
| + | certificate_revocation = true | ||
| + | certname = learning.puppetlabs.vm | ||
| + | cfacter = false | ||
| + | classfile = / | ||
| + | client_datadir = / | ||
| + | clientbucketdir = / | ||
| + | clientyamldir = / | ||
| + | code = "" | ||
| + | codedir = / | ||
| + | color = ansi | ||
| + | confdir = / | ||
| + | config = / | ||
| + | config_file_name = puppet.conf | ||
| + | config_version = "" | ||
| + | configprint = all | ||
| + | configtimeout = 120 | ||
| + | csr_attributes = / | ||
| + | csrdir = / | ||
| + | daemonize = true | ||
| + | data_binding_terminus = hiera | ||
| + | default_file_terminus = rest | ||
| + | default_manifest = ./manifests | ||
| + | default_schedules = true | ||
| + | deviceconfig = / | ||
| + | devicedir = / | ||
| + | diff = diff | ||
| + | diff_args = -u | ||
| + | digest_algorithm = md5 | ||
| + | disable_per_environment_manifest = false | ||
| + | disable_warnings = [" | ||
| + | dns_alt_names = "" | ||
| + | document_all = false | ||
| + | environment = production | ||
| + | environment_data_provider = none | ||
| + | environment_timeout = 0 | ||
| + | environmentpath = / | ||
| + | evaltrace = false | ||
| + | external_nodes = none | ||
| + | factpath = / | ||
| + | facts_terminus = yaml | ||
| + | fileserverconfig = / | ||
| + | filetimeout = 15 | ||
| + | forge_authorization = | ||
| + | freeze_main = false | ||
| + | genconfig = false | ||
| + | genmanifest = false | ||
| + | graph = false | ||
| + | graphdir = / | ||
| + | group = pe-puppet | ||
| + | hiera_config = / | ||
| + | hostcert = / | ||
| + | hostcrl = / | ||
| + | hostcsr = / | ||
| + | hostprivkey = / | ||
| + | hostpubkey = / | ||
| + | http_connect_timeout = 120 | ||
| + | http_debug = false | ||
| + | http_keepalive_timeout = 4 | ||
| + | http_proxy_host = none | ||
| + | http_proxy_password = none | ||
| + | http_proxy_port = 3128 | ||
| + | http_proxy_user = none | ||
| + | http_read_timeout = | ||
| + | ignorecache = false | ||
| + | ignoremissingtypes = false | ||
| + | ignoreschedules = false | ||
| + | keylength = 4096 | ||
| + | lastrunfile = / | ||
| + | lastrunreport = / | ||
| + | ldapattrs = all | ||
| + | ldapbase = "" | ||
| + | ldapclassattrs = puppetclass | ||
| + | ldapparentattr = parentnode | ||
| + | ldappassword = "" | ||
| + | ldapport = 389 | ||
| + | ldapserver = ldap | ||
| + | ldapssl = false | ||
| + | ldapstackedattrs = puppetvar | ||
| + | ldapstring = (& | ||
| + | ldaptls = false | ||
| + | ldapuser = "" | ||
| + | libdir = / | ||
| + | localcacert = / | ||
| + | log_level = notice | ||
| + | logdir = / | ||
| + | manage_internal_file_permissions = true | ||
| + | manifest = / | ||
| + | masterhttplog = / | ||
| + | masterport = 8140 | ||
| + | max_deprecations = 10 | ||
| + | max_errors = 10 | ||
| + | max_warnings = 10 | ||
| + | maximum_uid = 4294967290 | ||
| + | mkusers = false | ||
| + | module_groups = base+pe_only | ||
| + | module_repository = https:// | ||
| + | module_skeleton_dir = / | ||
| + | module_working_dir = / | ||
| + | modulepath = / | ||
| + | name = master | ||
| + | node_cache_terminus = write_only_yaml | ||
| + | node_name = cert | ||
| + | node_name_fact = "" | ||
| + | node_name_value = learning.puppetlabs.vm | ||
| + | node_terminus = classifier | ||
| + | noop = false | ||
| + | onetime = false | ||
| + | ordering = manifest | ||
| + | passfile = / | ||
| + | path = none | ||
| + | pidfile = / | ||
| + | plugindest = / | ||
| + | pluginfactdest = / | ||
| + | pluginfactsource = puppet:/// | ||
| + | pluginsignore = .svn CVS .git | ||
| + | pluginsource = puppet:/// | ||
| + | pluginsync = true | ||
| + | postrun_command = "" | ||
| + | preferred_serialization_format = pson | ||
| + | prerun_command = "" | ||
| + | preview_outputdir = / | ||
| + | priority = | ||
| + | privatedir = / | ||
| + | privatekeydir = / | ||
| + | profile = false | ||
| + | publickeydir = / | ||
| + | puppetdlog = / | ||
| + | report = true | ||
| + | report_port = 8140 | ||
| + | report_server = learning.puppetlabs.vm | ||
| + | reportdir = / | ||
| + | reports = puppetdb | ||
| + | reporturl = http:// | ||
| + | req_bits = 4096 | ||
| + | requestdir = / | ||
| + | resourcefile = / | ||
| + | rest_authconfig = / | ||
| + | route_file = / | ||
| + | rundir = / | ||
| + | runinterval = 1800 | ||
| + | serial = / | ||
| + | server = learning.puppetlabs.vm | ||
| + | server_datadir = / | ||
| + | show_diff = false | ||
| + | signeddir = / | ||
| + | skip_tags = "" | ||
| + | splay = false | ||
| + | splaylimit = 1800 | ||
| + | srv_domain = puppetlabs.vm | ||
| + | ssl_client_ca_auth = | ||
| + | ssl_client_header = HTTP_X_CLIENT_DN | ||
| + | ssl_client_verify_header = HTTP_X_CLIENT_VERIFY | ||
| + | ssl_server_ca_auth = | ||
| + | ssldir = / | ||
| + | statedir = / | ||
| + | statefile = / | ||
| + | static_catalogs = true | ||
| + | storeconfigs = true | ||
| + | storeconfigs_backend = puppetdb | ||
| + | strict_environment_mode = false | ||
| + | strict_hostname_checking = false | ||
| + | strict_variables = false | ||
| + | summarize = false | ||
| + | supported_checksum_types = [" | ||
| + | syslogfacility = daemon | ||
| + | tags = "" | ||
| + | trace = false | ||
| + | trusted_oid_mapping_file = / | ||
| + | trusted_server_facts = false | ||
| + | use_cached_catalog = false | ||
| + | use_srv_records = false | ||
| + | usecacheonfailure = true | ||
| + | user = pe-puppet | ||
| + | vardir = / | ||
| + | waitforcert = 120 | ||
| + | yamldir = / | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | ===== Orchestration ===== | ||
| + | |||
| + | Details are here: https:// | ||
| + | |||
| + | Orchestration allows to install dependent applications in the right order. | ||
| + | |||
| + | It works as following: | ||
| + | - setup the node to know the orchestrator | ||
| + | - create an Application, | ||
| + | - setup orchestrator user with the rights | ||
| + | - setup an **artificial, | ||
| + | - define, which node **produces** data to fill artificial, public resource. Which node consumes data from artificial, public resource. | ||
| + | - declare the resource | ||
| + | - in site.pp declare - which part of the application will be installed on which node. | ||
| + | |||
| + | {{http:// | ||
