- Puppet 2.7 Cookbook
- John Arundel
- 513字
- 2021-04-02 18:19:57
Retrieving files from Puppet's filebucket
"A Freudian slip is when you say one thing, but mean your mother."—Anon
We all make mistakes; that's why pencils have erasers. Whenever Puppet changes a file on the client, it keeps a backup copy of the previous version. We can see this process in action if we make a change, however small, to an existing file:
# puppet agent --test info: Caching catalog for cookbook info: Applying configuration version '1293459139' --- /etc/sudoers 2010-12-27 07:12:20.421896753 -0700 +++ /tmp/puppet-file20101227-1927-13hjvy6-0 2010-12-27 07:13:21.645702932 -0700 @@ -12,7 +12,7 @@ # User alias specification -User_Alias SYSOPS = john +User_Alias SYSOPS = john,bob info: FileBucket adding /etc/sudoers as {md5}c07d0aa2d43d58ea7b5c5307f532a0b1 info: /Stage[main]/Admin::Sudoers/File[/etc/sudoers]: Filebucketed /etc/sudoers to puppet with sum c07d0aa2d43d58ea7b5c5307f532a0b1 notice: /Stage[main]/Admin::Sudoers/File[/etc/sudoers]/content: content changed '{md5}c07d0aa2d43d58ea7b5c5307f532a0b1' to '{md5}0d218c16bd31206e312c885884fa947d' notice: Finished catalog run in 0.45 seconds
The part we're interested in is this line:
info: /Stage[main]/Admin::Sudoers/File[/etc/sudoers]: Filebucketed /etc/sudoers to puppet with sum c07d0aa2d43d58ea7b5c5307f532a0b1
Puppet creates an MD5 hash of the file's contents and uses this to create a filebucket path, based on the first few characters of the hash. The filebucket is where Puppet keeps backup copies of any files that it replaces, and it's located by default in /var/lib/puppet/clientbucket
.
# ls /var/lib/puppet/clientbucket/c/0/7/d/0/a/a/2/c07d0aa2d43d58ea7b5c5307f532a0b1 contents paths
As you just saw, the # ls
command listed the filenames. You will see two files in the bucket location: contents
and paths
. The contents
file contains, as you might expect, the original contents of the file. The paths
file contains its original path.
It's easy to find the file if you know its content hash (as we did in this case). If you don't, it's helpful to create a table of contents of the whole filebucket by building an index file.
How to do it...
- Create the index file using the following command:
# find /var/lib/puppet/clientbucket -name paths -execdir cat {} \; -execdir pwd \; -execdir date -r {} +"%F %T" \; -exec echo \; > bucket.txt
- Search the index file to find the file you're looking for:
# cat bucket.txt /etc/sudoers /var/lib/puppet/clientbucket/c/0/7/d/0/a/a/2/c07d0aa2d43d58ea7b5c5307f532a0b1 2010-12-27 07:13:21 /etc/sudoers /var/lib/puppet/clientbucket/1/0/9/0/e/2/8/a/1090e28a70ebaae872c2ec78894f49eb 2010-12-27 07:12:20
- To retrieve the file once you know its bucket path, just copy the
contents
file to the original filename:# cp /var/lib/puppet/clientbucket/1/0/9/0/e/2/8/a/1090e28a70ebaae872c2ec78894f49eb/contents /etc/sudoers
How it works...
The script will create a complete list of files in the filebucket, showing the original name of the file, the bucket path, and the modification date (in case you need to retrieve one of several previous versions of the file). Once you know the bucket path, then you can copy the file back into place.
There's more...
You can have Puppet create backup copies of the file in its original location, rather than in the filebucket. To do this, use the backup
parameter in your manifest:
file { "/etc/sudoers": mode => "440", source => "puppet:///modules/admin/sudoers", backup => ".bak", }
Now, if Puppet replaces the file, it will create a backup version in the same location with the extension .bak
. To make this the default policy for all files, use:
File { backup => ".bak", }
To disable backups altogether, use the following code:
backup => false,
- EJB 3.0 Database Persistence with Oracle Fusion Middleware 11g: LITE
- 中文版AutoCAD 2015實用教程
- Excel圖表與表格實戰技巧精粹
- Flash CC中文版動畫設計與制作/微課堂學電腦
- Excel 2013使用詳解(修訂版)
- YUI 2.8: Learning the Library
- SOLIDWORKS Visualize 實例詳解(微視頻版)
- 中文版Rhino 5.0完全自學教程(第3版)
- Apache Maven 3 Cookbook
- 科技繪圖/科研論文圖/論文配圖設計與創作自學手冊:科研動畫篇
- 從零開始:Indesign CC 2019設計基礎+商業設計實戰
- Altium Designer 20 中文版從入門到精通
- Photoshop 2020實戰從入門到精通(超值版)
- Photoshop新媒體美工設計(視頻指導版)
- 48小時精通CREO Parametric 3.0中文版鈑金設計技巧