File resource
Manage system Local Files
Set file permissions and owner
Manage file content and manage content based on templates
Support for managing catalogs
Copy entire directory from remote server to local
As the puppet manual mentions, we want you to manage content as sparingly as possible with the file type. Instead, it is replaced with a better wrapper resource type. If you find that you often copy files from the puppet server to the local, please contact Puppetlabs to have them develop the type of private resource that is right for you.
Depend on
The resource type is not dependent on
Platform
This resource type supports all platforms
Example
Here is a simple example of creating a file ABC and adding content
file {'/etc/abc ':
ensure = File,
Content = "Hello World",
}
1. Common properties of file resources and their introduction
File {' Resource title ':
Path
Ensure
Backup
Checksum
Content
Force
Group
Links
Mode
Owner
Source
Target
......
}
◆ Path : Specifies the paths to the files or directories to be managed and must be enclosed in quotation marks (usually the path is equal to the title of the resource, which can be omitted)
◆ ensure: You can set 5 values respectively, namely absent, present, file, directory, link. if present is specified, the file is checked for existence, if it is not present, a new file is created, if it is specified as absent, the file identifier is set to create the document, the directory is created, and if the directory is deleted, additional force is required. >true, setting the link value creates a soft connection to the file based on the path, followed by the path of the soft connection via the target property.
# Delete ABC Directory
file {'/tmp/abc/':
ensure = absent,
force = True,
}
◆ Backup: Determines whether the contents of the file are backed up before being modified. Use Filebucket to back up files, classify them according to the md5sum of files, and find the files when the files are recovered. You can back up files to the puppet client, or you can set Backpup and Bucket_name Backup files to other machines on the network. If the value of backup is a dot, "." Starting with the string, Puppet will back up the file in the same directory, and the extension of the backup file is the string inside the Bakcup. If you set backup = False, the file is not backed up.
# Make a backup before overwriting
file {'/etc/abc ':
Backup = '. Bak ',
}
◆ Checksum: How to check whether the file is modified, this state is used when copying files, there are several detection methods, including MD5, mtime, etc., the default detection is MD5.
Content: Sets the contents of the file to the string following the text parameter.
◆ Force: Can turn a directory into a link, the available values are ture, false, yes and no, where true and yes parameters are marked here to create a directory connection, false and no parameter indicates that no directory connection is created.
◆ Group: Specifies the user group for that file, which can be a GID or group name.
◆ Links: Defines actions that conform to linked files. The values that can be set are follow and manage; When the file is copied, the follow will copy the contents of the file, rather than just copy the link itself, if set to manage, the copy will conform to the link itself.
◆ mode: The permission to set the file.
# Modify file permissions to set the passwd value to 644
file {'/etc/passwd ':
mode = ' 644 ',
}
◆ Owner: Sets the owner of the file.
◆ Source: Copy a file overwrite the current file, with checksum to determine whether it is necessary to copy, can set the value is a reference to the full file path, or a URI, the currently supported URI only puppet and file; This is a common use of files, you can let puppet modify the system configuration file.
Class SendMail {
file {"/ETC/MAIL/SENDMAIL.CF":
Source = "PUPPET:///SERVER/MODULE/SENDMAIL.CF"
}
}
The above code downloads SENDMAIL.CF from the puppet server, overwriting to/ETC/MAIL/SENDMAIL.CF
Currently support puppet this URI, puppet will connect to puppet server above the Fileserver service, you can refer to puppet fileserver configuration file to better understand file server.
◆ Target: Specifies the destination for creating a soft connection
file {'/etc/issue ':
ensure = link,
target = '/tmp/issue ',
}
Case 1
Use the file resource to modify the/etc/passwd and/etc/shadow file properties on the system before you proceed, set the hostname, and then edit the/etc/puppet/manifests/file.pp file.
file {'/etc/passwd ':
Owner = ' Root ',
Group = ' Root ',
mode = ' 777 ',
}
file {'/etc/shadow ':
Owner = ' Root ',
Group = ' Root ',
mode = ' 777 ',
}
# puppet APPLY/ETC/PUPPET/MANIFESTS/FILE.PP
Notice:/stage[main]//file[/etc/shadow]/mode:mode changed ' 0000 ' to ' 0777 '
Notice:/stage[main]//file[/etc/passwd]/mode:mode changed ' 0644 ' to ' 0777 '
notice:finished catalog run in 0.02 seconds
Case 2
This case is the C/s structure, the master above the hosts file synchronization to the agent above, if the synchronization file is found to be inconsistent, you need to backup the source files before overwriting, edit/etc/puppet/manifests/site.pp on Master
Node Default {
file {'/etc/hosts ':
Backup = '. Bak ',
Source = "Puppet:///files/hosts",
}
}
Where the puppet:///mount path is specified by the fileserver.conf file on master, as follows:
# Cat Fileserver.conf
[Files]
Path/etc/puppet/files
Allow *
Put the Hosts file under the/etc/puppet/files path, set it up and we'll do a review on the agent.
# Puppet Agent--test--server=puppet
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/71/87/wKiom1XS5kGAWA5PAAJkKSWXgzI306.jpg "title=" Qq20150818160043.jpg "alt=" Wkiom1xs5kgawa5paajkkswxgzi306.jpg "/>
Please pay attention to http://www.wzlinux.com:45 and http://www.wzlinux.com.
This article is from the "Small Drops Linux" blog, make sure to keep this source http://wangzan18.blog.51cto.com/8021085/1685594
Puppet Advanced Guide--file Resources detailed