Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
puppet_dsl [2020/11/20 09:45] – [Creating & Modifying Users] andonovj | puppet_dsl [2020/11/20 10:28] (current) – andonovj | ||
---|---|---|---|
Line 16: | Line 16: | ||
* Resources (e.g. in-build functions & operations: file, user, router, etc, perform individual tasks) | * Resources (e.g. in-build functions & operations: file, user, router, etc, perform individual tasks) | ||
* Classes (e.g. combination of resources, multiple small operations) | * Classes (e.g. combination of resources, multiple small operations) | ||
- | * Manifest (e.g. definitions and declarion of puppet classes) | + | * Manifest (e.g. definitions and declarion of puppet classes, very similar to C# Classes) |
* Modules (e.g. collection of files and manifest, example: mysql & jenkins module) | * Modules (e.g. collection of files and manifest, example: mysql & jenkins module) | ||
Line 23: | Line 23: | ||
{{ : | {{ : | ||
- | So let's see that in an example: | + | =====Resources===== |
+ | As already explained, Puppet has in-build resources and function, we can describe all in-built resources as so: | ||
- | =====Creating & Modifying Users===== | + | < |
+ | [root@puppetmaster demo]# puppet describe --list | ||
+ | These are the types known to puppet: | ||
+ | augeas | ||
+ | cron - Installs and manages cron jobs | ||
+ | exec - Executes external commands | ||
+ | file - Manages files, including their content, owner ... | ||
+ | filebucket | ||
+ | group - Manage groups | ||
+ | host - Installs and manages host entries | ||
+ | mount - Manages mounted filesystems, | ||
+ | notify | ||
+ | package | ||
+ | resources | ||
+ | schedule | ||
+ | scheduled_task | ||
+ | selboolean | ||
+ | selmodule | ||
+ | service | ||
+ | ssh_authorized_key - Manages SSH authorized keys | ||
+ | sshkey | ||
+ | stage - A resource type for creating new run stages | ||
+ | tidy - Remove unwanted files based on specific crite ... | ||
+ | user - Manage users | ||
+ | whit - Whits are internal artifacts of Puppet' | ||
+ | yumrepo | ||
+ | zfs - Manage zfs | ||
+ | zone - Manages Solaris zones | ||
+ | zpool - Manage zpools | ||
+ | [root@puppetmaster demo]# | ||
+ | </ | ||
+ | |||
+ | Let's discuss some of them here. | ||
+ | |||
+ | ====User==== | ||
To create a user, we will use a simple resource (e.g. function: user, to ensure that it exist) | To create a user, we will use a simple resource (e.g. function: user, to ensure that it exist) | ||
- | ====Create==== | ||
< | < | ||
[root@puppetmaster demo]# vi demouser.pp | [root@puppetmaster demo]# vi demouser.pp | ||
Line 39: | Line 73: | ||
Then we can validate the code, for syntax error using the parser: | Then we can validate the code, for syntax error using the parser: | ||
- | ===Check=== | ||
< | < | ||
--If error exists | --If error exists | ||
Line 51: | Line 84: | ||
</ | </ | ||
- | ===Test=== | ||
We can test if the application of the change will be possible: | We can test if the application of the change will be possible: | ||
- | |||
< | < | ||
[root@puppetmaster demo]# puppet apply --noop demouser.pp | [root@puppetmaster demo]# puppet apply --noop demouser.pp | ||
Line 64: | Line 95: | ||
Finally we can apply the change: | Finally we can apply the change: | ||
- | |||
- | ===Apply==== | ||
< | < | ||
[root@puppetmaster demo]# puppet apply demouser.pp | [root@puppetmaster demo]# puppet apply demouser.pp | ||
Line 82: | Line 111: | ||
</ | </ | ||
- | ====Modify==== | + | ===Modify=== |
What if we want to modify the user, let's say put the UID as 7777 and the shell as /bin/sh. Well, we can use the same file with more attributes: | What if we want to modify the user, let's say put the UID as 7777 and the shell as /bin/sh. Well, we can use the same file with more attributes: | ||
Line 117: | Line 146: | ||
--Verify | --Verify | ||
[root@puppetmaster demo]# id julienandonov | [root@puppetmaster demo]# id julienandonov | ||
- | uid=**7777**(julienandonov) gid=1001(julienandonov) groups=1001(julienandonov) | + | uid=7777(julienandonov) gid=1001(julienandonov) groups=1001(julienandonov) |
[root@puppetmaster demo]# | [root@puppetmaster demo]# | ||
</ | </ | ||
+ | |||
+ | ====File==== | ||
+ | The File resource is as easy to be used as user. Let's see which attributes are in that resource: | ||
+ | |||
+ | |||
+ | < | ||
+ | [root@puppetmaster demo]# puppet describe file | ||
+ | ******************************************************* | ||
+ | Parameters | ||
+ | ---------- | ||
+ | - **owner** | ||
+ | The user to whom the file should belong. | ||
+ | auser ID. | ||
+ | - **group** | ||
+ | Which group should own the file. Argument can be either a group | ||
+ | name or a group ID. | ||
+ | - **ensure** | ||
+ | Whether the file should exist, and if so what kind of file it should be. | ||
+ | Possible values are `present`, `absent`, `file`, `directory`, | ||
+ | `link`. | ||
+ | - **mode** | ||
+ | The desired permissions mode for the file, in symbolic or numeric | ||
+ | notation. This value **must** be specified as a string; | ||
+ | </ | ||
+ | |||
+ | There are many more, but we will focuse only on these 4. | ||
+ | So let's create our DSL file: | ||
+ | |||
+ | < | ||
+ | [root@puppetmaster demo]# vi demouser.pp | ||
+ | user { " | ||
+ | ensure => " | ||
+ | uid => " | ||
+ | shell => "/ | ||
+ | } | ||
+ | :wq | ||
+ | </ | ||
+ | |||
+ | Now, we can check the syntax, dry run and finally apply the changes: | ||
+ | |||
+ | < | ||
+ | --Check Syntax | ||
+ | [root@puppetmaster demo]# puppet parser validate demofile.pp | ||
+ | |||
+ | --Dry Run | ||
+ | [root@puppetmaster demo]# puppet apply --noop demofile.pp | ||
+ | Notice: Compiled catalog for puppetmaster.example.com in environment production in 0.01 seconds | ||
+ | Notice: / | ||
+ | Notice: Class[Main]: | ||
+ | Notice: Stage[main]: | ||
+ | Notice: Applied catalog in 0.02 seconds | ||
+ | |||
+ | --Apply Changes | ||
+ | [root@puppetmaster demo]# puppet apply demofile.pp | ||
+ | Notice: Compiled catalog for puppetmaster.example.com in environment production in 0.01 seconds | ||
+ | Notice: / | ||
+ | Notice: Applied catalog in 0.01 seconds | ||
+ | |||
+ | --Verify Results | ||
+ | [root@puppetmaster demo]# ls -lart / | ||
+ | -rwxrwxrwx. 1 julienandonov julienandonov 0 Nov 20 05:20 / | ||
+ | [root@puppetmaster demo]# | ||
+ | </ | ||
+ |