Apt get no more let Vagrant, Puppet and Docker take the stage
Managing Files via Puppet: Let Me Count The Ways
-
Upload
michael-arnold -
Category
Technology
-
view
57 -
download
1
Transcript of Managing Files via Puppet: Let Me Count The Ways
![Page 1: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/1.jpg)
Managing Filesvia Puppet
Let Me Count The WaysMike Arnold ( )
Puppet Camp Phoenix 2015
razorsedge
![Page 2: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/2.jpg)
AgendaIntroManaging FilesManaging LinesVarious PatternsQuestionsLinks
![Page 3: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/3.jpg)
Intro
![Page 4: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/4.jpg)
Who is Mike Arnold?Unix Systems AdministratorPuppet Certified Professional15 years in ITPresently doing:
Hadoop Infrastructure EngineeringBuilding Puppet modules
![Page 5: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/5.jpg)
What Is This Topic?Puppet can manage files. (This may be obvious.)
entire filesor just linesvia static contentor templates
Lets see all the ways.
![Page 6: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/6.jpg)
Managing Files
![Page 7: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/7.jpg)
Basic File resource:file { '/tmp/testFile': ensure => present, mode => '0644', owner => 'root', group => 'root',}
![Page 8: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/8.jpg)
With source attribute:file { '/tmp/testFileA': ensure => present, mode => '0644', source => 'puppet:///modules/example/fileA',}
![Page 9: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/9.jpg)
With multiple sourceattributes:
file { '/tmp/testFileB': ensure => present, mode => '0644', source => [ "puppet:///modules/example/fileB.${::operatingsystem}", 'puppet:///modules/example/fileB', ],}
![Page 10: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/10.jpg)
With content attribute:file { '/tmp/testFileC': ensure => present, mode => '0644', content => 'Some fancy string.',}
Note: no carriage return
![Page 11: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/11.jpg)
With content attribute stringvariables:
file { '/tmp/testFileD': ensure => present, mode => '0644', content => "Your operating system is: ${::operatingsystem}\${::operatingsystemrelease}\nYour CPU architecture\is: ${::architecture}\n",}
![Page 12: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/12.jpg)
With content attributetemplate():
$variableA = 'good'$variableB = 'horrible'file { '/tmp/testFileE': ensure => present, mode => '0644', content => template('example/templateA.erb'),}
This is a <%= @variableA %> day.There will be a <%= @variableB %> calamity.
![Page 13: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/13.jpg)
With mutiple content attributetemplate()s:
$variableA = 'good'$variableB = 'horrible'file { '/tmp/testFileF': ensure => present, mode => '0644', content => template('example/templateA.erb','example/templateB.erb'),}
We are using <%= scope['::osfamily'] %> osfamily.
![Page 14: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/14.jpg)
With content attributeinline_template():
$options = [ 'blue', 'heavy', 'yummy' ]$item = 'The sky is'file { '/tmp/testFileG': ensure => present, mode => '0644', content => inline_template("${item}: <%= @options.join ' ' %>\n"),}
![Page 15: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/15.jpg)
With content attribute file():file { '/tmp/testFileH': ensure => present, mode => '0644', content => file('/etc/hosts'),}
![Page 16: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/16.jpg)
With content attribute epp():$variableA = 'good'$variableB = 'horrible'file { '/tmp/testFileI': ensure => present, mode => '0644', content => epp('example/templateA.epp'),}
This is a <%= $variableA %> day.There will be a <%= $variableB %> calamity.
puppet apply --parser=future
![Page 17: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/17.jpg)
Difference between source andcontent?
Unlike c o n t e n t , the s o u r c e attribute can be used to recursivelycopy directories if the r e c u r s e attribute is set to t r u e or r e m o t e .
![Page 18: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/18.jpg)
concatThe concat module constructs files from multiple fragments in an
ordered way.concat { '/tmp/testFileJ': ensure => present, mode => '0644'}concat::fragment { 'testfileJ01': target => '/tmp/testFileJ', content => "This is a concat line 01.\n", order => '01',}concat::fragment { 'testfileJ02': target => '/tmp/testFileJ', source => 'puppet:///modules/example/fileA', order => '02',}
![Page 19: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/19.jpg)
Managing Lines
![Page 20: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/20.jpg)
augeasApply a change or an array of changes to the filesystem using the
augeas tool.file { '/tmp/testFileK': ensure => present, mode => '0644', content => file('/etc/resolv.conf'),} >augeas { 'testFileK' : incl => '/tmp/testFileK', # only needed for this demo lens => 'Resolv.lns', # only needed for this demo changes => 'set domain example.net',}
![Page 21: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/21.jpg)
file_lineThe file_line resource ensures that a given line, including whitespaceat the beginning and end, is contained within a file. If the line is not
present, Puppet will add the line. Multiple resources can be declaredto manage multiple lines in the same file.
file { '/tmp/testFileL': ensure => present, mode => '0644',} >file_line { 'testFileL': ensure => present, path => '/tmp/testFileL', line => 'This line shall be present.',}
![Page 22: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/22.jpg)
file_line with line replacement:You can also use m a t c h to replace existing lines.
file { '/tmp/testFileM': ensure => present, mode => '0644', content => file('/etc/resolv.conf'),} >file_line { 'testFileM#search': ensure => present, path => '/tmp/testFileM', line => 'search localdomain', match => '̂search .*',}
![Page 23: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/23.jpg)
inifileThe inifile module allows you to manage settings and subsettings in
INI-style configuration files. This module tries hard not tomanipulate your file any more than it needs to. In most cases, itshould leave the original whitespace, comments, ordering, etc.
intact.ini_setting { 'testFileN#foo#bar': ensure => present, path => '/tmp/testFileN', section => 'foo', setting => 'bar', value => 'GIBBERISH',}
![Page 24: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/24.jpg)
inifile adding to an existingsection:
file { '/tmp/testFileO': ensure => present, mode => '0644', content => file('/usr/share/perl5/vendor_perl/XML/SAX/ParserDetails.ini'),} >ini_setting { 'testFileO#foo#bar': ensure => present, path => '/tmp/testFileO', section => 'Build', setting => 'testN', value => 'WeDidIt',}
![Page 25: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/25.jpg)
datacatThe datacat module constructs a file by stitching line fragments
together into the same line in one or multiple files.datacat { '/tmp/testFileP': ensure => present, mode => '0644', template => 'example/templateP.erb',}datacat_fragment { "${::fqdn} in device hostgroup": target => '/tmp/testFileP', data => { myhostgroup => [ $::fqdn ], }, order => '01',}$ilo_fqdn = regsubst($::fqdn, '\.', 'ilo.')datacat_fragment { "${ilo_fqdn} in device hostgroup": target => '/tmp/testFileP', data => { myhostgroup => [ $ilo_fqdn ], }, order => '02',}
![Page 26: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/26.jpg)
The File and Concat resource can make backups of the file beingmodified into the Puppet filebucket. File_line, inifile, etc do not.
![Page 27: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/27.jpg)
Various Patterns
![Page 28: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/28.jpg)
sudoclass { 'sudo': # only needed for this demo purge => false, # only needed for this demo config_file_replace => false, # only needed for this demo} # only needed for this demosudo::conf { 'web': source => 'puppet:///modules/example/etc/sudoers.d/web',}sudo::conf { 'admins': priority => 10, content => "%admins ALL=(ALL) NOPASSWD: ALL",}sudo::conf { 'joe': priority => 60, source => 'puppet:///modules/example/etc/sudoers.d/joe',}
![Page 29: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/29.jpg)
augeasproviderssshd_config { 'PermitRootLogin': ensure => present, value => 'no',}
grep PermitRootLogin /etc/ssh/sshd_config
![Page 30: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/30.jpg)
augeasproviderskernel_parameter { 'elevator': ensure => present, value => 'deadline',}
grep linux16 /boot/grub2/grub.cfg
![Page 31: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/31.jpg)
augeasprovidersshellvar { 'HOSTNAME': ensure => present, target => '/etc/sysconfig/network', value => 'host.example.com',}
cat /etc/sysconfig/network
![Page 32: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/32.jpg)
augeasproviderssysctl { 'net.ipv4.ip_forward': ensure => present, value => '1', comment => 'This is a routing test.',}
sysctl net.ipv4.ip_forwardcat /etc/sysctl.conf
![Page 33: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/33.jpg)
Apache vhostapache::vhost { 'first.example.com': port => '80', docroot => '/var/www/first',}
cat /etc/httpd/conf.d/25-first.example.com.conf
![Page 34: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/34.jpg)
Questions?
![Page 35: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/35.jpg)
Linkshttps://docs.puppetlabs.com/references/latest/type.html#file-attribute-contenthttps://docs.puppetlabs.com/references/latest/type.html#file-attribute-sourcehttps://docs.puppetlabs.com/references/latest/function.html#templatehttps://docs.puppetlabs.com/references/latest/function.html#filehttps://docs.puppetlabs.com/references/latest/function.html#epphttps://forge.puppetlabs.com/puppetlabs/concat
![Page 36: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/36.jpg)
Linkshttps://docs.puppetlabs.com/references/latest/type.html#augeashttps://puppetlabs.com/blog/module-of-the-week-puppetlabsstdlib-puppet-labs-standard-libraryhttps://forge.puppetlabs.com/puppetlabs/stdlibhttps://forge.puppetlabs.com/puppetlabs/inifilehttps://forge.puppetlabs.com/richardc/datacat
![Page 37: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/37.jpg)
Linkshttps://forge.puppetlabs.com/saz/sudohttps://forge.puppetlabs.com/herculesteam/augeasprovidershttps://forge.puppetlabs.com/puppetlabs/apache
![Page 38: Managing Files via Puppet: Let Me Count The Ways](https://reader036.fdocuments.us/reader036/viewer/2022062420/55c0c001bb61eb72328b459c/html5/thumbnails/38.jpg)
ContactMike Arnold <[email protected]>https://intelligentsysadmin.wordpress.com/https://github.com/razorsedgehttps://forge.puppetlabs.com/razorsedge
This presentation sourcecode can be found at:https://github.com/razorsedge/presentation-managing-files-via-puppet