| 
									
										
										
										
											2011-02-26 20:41:33 +01:00
										 |  |  | cdist-manifest(7) | 
					
						
							|  |  |  | ================= | 
					
						
							|  |  |  | Nico Schottelius <nico-cdist--@--schottelius.org> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NAME | 
					
						
							|  |  |  | ---- | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | cdist-manifest - (Re-)Use types | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-16 18:11:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | DESCRIPTION | 
					
						
							|  |  |  | ----------- | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | Manifests are used to define which objects to create. | 
					
						
							| 
									
										
										
										
											2013-07-07 12:44:42 +02:00
										 |  |  | Objects are instances of **types**, like in object oriented programming languages. | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | An object is represented by the combination of | 
					
						
							| 
									
										
										
										
											2014-04-30 11:17:09 +02:00
										 |  |  | **type + slash + object name**: **\__file/etc/cdist-configured** is an | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | object of the type ***__file*** with the name ***etc/cdist-configured***. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-09 14:41:50 -08:00
										 |  |  | All available types can be found in the **cdist/conf/type/** directory, | 
					
						
							|  |  |  | use **ls cdist/conf/type** to get the list of available types. If you have | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | setup the MANPATH correctly, you can use **man cdist-reference** to access | 
					
						
							|  |  |  | the reference with pointers to the manpages. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Types in manifests are used like normal command line tools. Let's have a look | 
					
						
							|  |  |  | at an example: | 
					
						
							|  |  |  | -------------------------------------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2013-10-05 11:24:12 +02:00
										 |  |  | # Create object of type __package with the parameter state = absent | 
					
						
							|  |  |  | __package apache2 --state absent | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Same with the __directory type | 
					
						
							| 
									
										
										
										
											2014-04-30 11:28:13 +02:00
										 |  |  | __directory /tmp/cdist --state present | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | -------------------------------------------------------------------------------- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | These two lines create objects, which will later be used to realise the  | 
					
						
							|  |  |  | configuration on the target host. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Manifests are executed locally as a shell script using **/bin/sh -e**. | 
					
						
							|  |  |  | The resulting objects are stored in an internal database. | 
					
						
							| 
									
										
										
										
											2012-01-16 18:11:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | The same object can be redefined in multiple different manifests as long as | 
					
						
							|  |  |  | the parameters are exactly the same. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | In general, manifests are used to define which types are used depending | 
					
						
							|  |  |  | on given conditions. | 
					
						
							| 
									
										
										
										
											2011-02-26 20:41:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | INITIAL AND TYPE MANIFESTS | 
					
						
							|  |  |  | -------------------------- | 
					
						
							| 
									
										
										
										
											2012-05-10 15:51:22 +00:00
										 |  |  | Cdist knows about two types of manifests: The initial manifest and type | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | manifests. The initial manifest is used to define, which configurations | 
					
						
							|  |  |  | to apply to which hosts. The type manifests are used to create objects | 
					
						
							|  |  |  | from types. More about manifests in types can be found in cdist-type(7). | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-11 17:21:38 +01:00
										 |  |  | DEFINE STATE IN THE INITIAL MANIFEST | 
					
						
							|  |  |  | ------------------------------------ | 
					
						
							|  |  |  | The **initial manifest** is the entry point for cdist to find out, which | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | **objects** to configure on the selected host. | 
					
						
							| 
									
										
										
										
											2013-07-07 12:44:42 +02:00
										 |  |  | Cdist expects the initial manifest at **cdist/conf/manifest/init**. | 
					
						
							| 
									
										
										
										
											2012-01-11 17:21:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-07 12:44:42 +02:00
										 |  |  | Within this initial manifest you define, which objects should be | 
					
						
							| 
									
										
										
										
											2012-01-11 17:21:38 +01:00
										 |  |  | created on which host. To distinguish between hosts, you can use the | 
					
						
							|  |  |  | environment variable **__target_host**. Let's have a look at a simple | 
					
						
							|  |  |  | example: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | -------------------------------------------------------------------------------- | 
					
						
							|  |  |  | __cdistmarker | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | case "$__target_host" in | 
					
						
							|  |  |  |    localhost) | 
					
						
							|  |  |  |         __directory /home/services/kvm-vm --parents yes | 
					
						
							|  |  |  |    ;; | 
					
						
							|  |  |  | esac | 
					
						
							|  |  |  | -------------------------------------------------------------------------------- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | This manifest says: Independent of the host, always use the type  | 
					
						
							|  |  |  | ***__cdistmarker***, which creates the file **/etc/cdist-configured**, | 
					
						
							|  |  |  | with the timestamp as content. | 
					
						
							|  |  |  | The directory ***/home/services/kvm-vm***, including all parent directories,  | 
					
						
							|  |  |  | is only created on the host ***localhost***. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | As you can see, there is no magic involved, the manifest is simple shell code that | 
					
						
							|  |  |  | utilises cdist types. Every available type can be executed like a normal  | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | command. | 
					
						
							| 
									
										
										
										
											2012-01-11 17:21:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | SPLITTING UP THE INITIAL MANIFEST | 
					
						
							|  |  |  | --------------------------------- | 
					
						
							|  |  |  | If you want to split up your initial manifest, you can create other shell | 
					
						
							| 
									
										
										
										
											2012-12-09 14:41:50 -08:00
										 |  |  | scripts in **cdist/conf/manifest/** and include them in **cdist/conf/manifest/init**. | 
					
						
							| 
									
										
										
										
											2014-04-30 11:45:13 +02:00
										 |  |  | Cdist provides the environment variable ***__manifest*** to reference | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | the directory containing the initial manifest (see cdist-reference(7)). | 
					
						
							| 
									
										
										
										
											2011-02-26 20:41:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | The following example would include every file with a **.sh** suffix: | 
					
						
							| 
									
										
										
										
											2011-02-26 20:41:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | -------------------------------------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | # Include *.sh | 
					
						
							|  |  |  | for manifest in $__manifest/*.sh; do | 
					
						
							|  |  |  |     # And source scripts into our shell environment | 
					
						
							|  |  |  |     . "$manifest" | 
					
						
							|  |  |  | done | 
					
						
							| 
									
										
										
										
											2011-02-26 20:41:33 +01:00
										 |  |  | -------------------------------------------------------------------------------- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-18 02:01:37 +01:00
										 |  |  | DEPENDENCIES | 
					
						
							|  |  |  | ------------ | 
					
						
							|  |  |  | If you want to describe that something requires something else, just | 
					
						
							|  |  |  | setup the variable "require" to contain the requirements. Multiple | 
					
						
							| 
									
										
										
										
											2013-06-03 18:11:19 +02:00
										 |  |  | requirements can be added white space separated. | 
					
						
							| 
									
										
										
										
											2011-03-18 02:01:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | -------------------------------------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2014-04-30 15:57:44 +02:00
										 |  |  |  1 # No dependency | 
					
						
							|  |  |  |  2 __file /etc/cdist-configured | 
					
						
							|  |  |  |  3  | 
					
						
							|  |  |  |  4 # Require above object | 
					
						
							|  |  |  |  5 require="__file/etc/cdist-configured" __link /tmp/cdist-testfile \ | 
					
						
							|  |  |  |  6    --source /etc/cdist-configured  --type symbolic | 
					
						
							|  |  |  |  7  | 
					
						
							|  |  |  |  8 # Require two objects | 
					
						
							|  |  |  |  9 require="__file/etc/cdist-configured __link/tmp/cdist-testfile" \ | 
					
						
							|  |  |  | 10    __file /tmp/cdist-another-testfile | 
					
						
							| 
									
										
										
										
											2011-03-18 02:01:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-30 15:57:44 +02:00
										 |  |  | -------------------------------------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2011-03-18 02:01:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-30 15:57:44 +02:00
										 |  |  | Above the "require" variable is only set for the command that is  | 
					
						
							|  |  |  | immediately following it. Dependencies should allways be declared that way. | 
					
						
							| 
									
										
										
										
											2011-03-18 02:01:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-30 15:57:44 +02:00
										 |  |  | On line 4 you can see that the instantion of a type "__link" object needs | 
					
						
							|  |  |  | the object "__file/etc/cdist-configured" to be present, before it can proceed. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | This also means that the "__link" command must make sure, that either | 
					
						
							|  |  |  | "__file/etc/cdist-configured" allready is present, or, if it's not, it needs | 
					
						
							|  |  |  | to be created. The task of cdist is to make sure, that the dependency will be | 
					
						
							|  |  |  | resolved appropriately and thus "__file/etc/cdist-configured" be created | 
					
						
							|  |  |  | if necessary before "__link" proceeds (or to abort execution with an error). | 
					
						
							| 
									
										
										
										
											2011-03-18 02:01:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | All objects that are created in a type manifest are automatically required | 
					
						
							|  |  |  | from the type that is calling them. This is called "autorequirement" in | 
					
						
							|  |  |  | cdist jargon. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-30 15:57:44 +02:00
										 |  |  | You can find an more in depth description of the flow execution of manifests | 
					
						
							|  |  |  | in cdist-stages(7) and of how types work in cdist-type(7). | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-06 15:55:41 +01:00
										 |  |  | CREATE DEPENDENCIES FROM EXECUTION ORDER | 
					
						
							|  |  |  | ----------------------------------------- | 
					
						
							|  |  |  | You can tell cdist to execute all types in the order in which they are created  | 
					
						
							|  |  |  | in the manifest by setting up the variable CDIST_ORDER_DEPENDENCY. | 
					
						
							|  |  |  | When cdist sees that this variable is setup, the current created object | 
					
						
							|  |  |  | automatically depends on the previously created object. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | It essentially helps you to build up blocks of code that build upon each other | 
					
						
							|  |  |  | (like first creating the directory xyz than the file below the directory). | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | THIS IS A BETA FEATURE AND MAY BE REMOVED OR CHANGED AT ANY TIME. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-31 21:48:09 +01:00
										 |  |  | OVERRIDES | 
					
						
							|  |  |  | --------- | 
					
						
							|  |  |  | In some special cases, you would like to create an already defined object  | 
					
						
							|  |  |  | with different parameters. In normal situations this leads to an error in cdist. | 
					
						
							| 
									
										
										
										
											2014-02-06 16:03:07 +01:00
										 |  |  | If you whish, you can setup the environment variable CDIST_OVERRIDE | 
					
						
							| 
									
										
										
										
											2014-02-05 21:09:24 +01:00
										 |  |  | (any value or even empty is ok) to tell cdist, that this object override is  | 
					
						
							| 
									
										
										
										
											2014-01-31 21:48:09 +01:00
										 |  |  | wanted and should be accepted. | 
					
						
							|  |  |  | ATTENTION: Only use this feature if you are 100% sure in which order  | 
					
						
							| 
									
										
										
										
											2014-04-30 11:53:04 +02:00
										 |  |  | cdist encounters the affected objects, otherwhise this results  | 
					
						
							|  |  |  | in an undefined situation.  | 
					
						
							| 
									
										
										
										
											2014-01-31 21:48:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-30 11:57:10 +02:00
										 |  |  | If CDIST_OVERRIDE and CDIST_ORDER_DEPENDENCY are set for an object, | 
					
						
							| 
									
										
										
										
											2014-02-12 10:31:46 +01:00
										 |  |  | CDIST_ORDER_DEPENDENCY will be ignored, because adding a dependency in case of | 
					
						
							|  |  |  | overrides would result in circular dependencies, which is an error. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-06 15:55:41 +01:00
										 |  |  | THIS IS A BETA FEATURE AND MAY BE REMOVED OR CHANGED AT ANY TIME. | 
					
						
							| 
									
										
										
										
											2014-01-17 23:35:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | EXAMPLES | 
					
						
							|  |  |  | -------- | 
					
						
							|  |  |  | The initial manifest may for instance contain the following code: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | -------------------------------------------------------------------------------- | 
					
						
							|  |  |  | # Always create this file, so other sysadmins know cdist is used. | 
					
						
							| 
									
										
										
										
											2013-10-05 11:24:12 +02:00
										 |  |  | __file /etc/cdist-configured | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | case "$__target_host" in | 
					
						
							|  |  |  |    my.server.name) | 
					
						
							| 
									
										
										
										
											2013-10-05 11:24:12 +02:00
										 |  |  |       __directory /root/bin/ | 
					
						
							|  |  |  |       __file /etc/issue.net --source "$__manifest/issue.net | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  |    ;; | 
					
						
							|  |  |  | esac | 
					
						
							|  |  |  | -------------------------------------------------------------------------------- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The manifest of the type "nologin" may look like this: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | -------------------------------------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2013-10-05 11:24:12 +02:00
										 |  |  | __file /etc/nologin --source "$__type/files/default.nologin" | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | -------------------------------------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2012-01-16 18:11:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-10 09:51:26 +09:00
										 |  |  | This example makes use of dependencies: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | -------------------------------------------------------------------------------- | 
					
						
							|  |  |  | # Ensure that lighttpd is installed | 
					
						
							|  |  |  | __package lighttpd --state present | 
					
						
							|  |  |  | # Ensure that munin makes use of lighttpd instead of the default webserver | 
					
						
							|  |  |  | # package as decided by the package manager | 
					
						
							|  |  |  | require="__package/lighttpd" __package munin --state present | 
					
						
							|  |  |  | -------------------------------------------------------------------------------- | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-31 21:50:32 +01:00
										 |  |  | How to override objects: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | -------------------------------------------------------------------------------- | 
					
						
							|  |  |  | # for example in the inital manifest | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-30 11:57:10 +02:00
										 |  |  | # create user account foobar with some hash for password | 
					
						
							| 
									
										
										
										
											2014-02-02 20:29:41 +01:00
										 |  |  | __user foobar --password 'some_fancy_hash' --home /home/foobarexample | 
					
						
							| 
									
										
										
										
											2014-01-31 21:50:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # ... many statements and includes in the manifest later ... | 
					
						
							|  |  |  | # somewhere in a conditionaly sourced manifest  | 
					
						
							|  |  |  | # (e.g. for example only sourced if a special application is on the target host) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # this leads to an error ... | 
					
						
							|  |  |  | __user foobar --password 'some_other_hash'  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # this tells cdist, that you know that this is an override and should be accepted | 
					
						
							| 
									
										
										
										
											2014-02-06 16:03:07 +01:00
										 |  |  | CDIST_OVERRIDE=yes __user foobar --password 'some_other_hash' | 
					
						
							| 
									
										
										
										
											2014-04-30 11:59:07 +02:00
										 |  |  | # it's only an override, means the parameter --home is not touched  | 
					
						
							|  |  |  | # and stays at the original value of /home/foobarexample | 
					
						
							| 
									
										
										
										
											2014-01-31 21:50:32 +01:00
										 |  |  | -------------------------------------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2013-10-10 09:51:26 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-06 15:55:41 +01:00
										 |  |  | Dependencies defined by execution order work as following: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | -------------------------------------------------------------------------------- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Tells cdist to execute all types in the order in which they are created ... | 
					
						
							|  |  |  | export CDIST_ORDER_DEPENDENCY=on | 
					
						
							|  |  |  | __sample_type 1 | 
					
						
							|  |  |  | require="__some_type_somewhere/id" __sample_type 2 | 
					
						
							|  |  |  | __example_type 23 | 
					
						
							|  |  |  | # Now this types are executed in the creation order until the variable is unset | 
					
						
							|  |  |  | unset CDIST_ORDER_DEPENDENCY | 
					
						
							|  |  |  | # all now following types cdist makes the order .. | 
					
						
							|  |  |  | __not_in_order_type 42 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # how it works : | 
					
						
							|  |  |  | # this lines above are translated to: | 
					
						
							|  |  |  | __sample_type 1 | 
					
						
							|  |  |  | require="__some_type_somewhere/id __sample_type/1" __sample_type 2 | 
					
						
							|  |  |  | require="__sample_type/2" __example_type 23 | 
					
						
							|  |  |  | __not_in_order_type 42 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | -------------------------------------------------------------------------------- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-26 20:41:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | SEE ALSO | 
					
						
							|  |  |  | -------- | 
					
						
							| 
									
										
										
										
											2012-01-16 18:11:28 +01:00
										 |  |  | - cdist-tutorial(7) | 
					
						
							| 
									
										
										
										
											2012-01-17 21:57:32 +01:00
										 |  |  | - cdist-type(7) | 
					
						
							| 
									
										
										
										
											2011-02-26 20:41:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | COPYING | 
					
						
							|  |  |  | ------- | 
					
						
							| 
									
										
										
										
											2014-02-06 15:55:41 +01:00
										 |  |  | Copyright \(C) 2010-2014 Nico Schottelius. Free use of this software is | 
					
						
							| 
									
										
										
										
											2011-02-26 20:41:33 +01:00
										 |  |  | granted under the terms of the GNU General Public License version 3 (GPLv3). |