Detailed explanation of puppet (3) - detailed explanation of file resources

Today, I will continue to introduce the relevant knowledge of Linux operation and maintenance. The main content of this article is the detailed explanation of file resources in puppet.

1. File resource support parameters

Puppet's file resource supports the following parameters:
ensure: the default is file or directory
backup: use
checksum when performing file backup: check whether the file has been modified
ctime: the update time of the
file mtime: the modification time of the
file content: the content of the file
force: to force Sexual operation
owner: the owner of the file
group: the group
of the file link: soft link to the file
mode: file permission
path: file path

Second, the actual combat of file resources

Next, we will carry out the actual combat of the file resource in puppet, the purpose is to use the puppet client to create a directory, make a soft connection to the specified file, and copy the file from the puppet server to the specified location.
If you want to use puppet to control the client, you must create the site.pp file in the /etc/puppet/manifests/ directory according to the puppet configuration format, and write the corresponding resources and operations. In this actual combat, the content of the site.pp file is as follows:

node default{
    
    
        file {
    
    
                "/tmp/puppet":
                ensure => directory;
        }
        file {
    
    
                "/tmp/puppet/httpd.conf":
                ensure => link,
                target => "/etc/httpd/conf/httpd.conf"
        }
        file {
    
    
                "/tmp/puppet/exp.txt":
                mode => '644',
                owner => 'root',
                group => 'root',
                source => 'puppet://puppet-server/files/exp.txt'
        }
}

The above configuration respectively means creating the /tmp/puppet directory on the puupet client; making a soft link to the specified file of the puppet client to the specified directory; copying the exp.txt file from the puppet server to the specified location with the specified permissions.
After completing the configuration, we create the /etc/puppet/files/ directory to serve as the download directory for the puppet client. Then, create the file exp.txt in this directory. After that, we have to authorize the directory, open the /etc/puppet/fileserver.conf file, and add the following content to the file:

[files]
path  /etc/puppet/files/
allow *

Once done, restart the puppet service.

3. Effect test

After completing the above configuration, let's check the result of the configuration just now. First, we execute the command on the puppet client:

puppet agent --server puppet-server --test

The results are as follows:
insert image description here
It can be seen that the puppet client has completed the corresponding operations according to the configuration of the puppet server, and the file resource in puppet has been successfully deployed!
Originality is not easy, please indicate the source for reprinting: https://blog.csdn.net/weixin_40228200

Guess you like

Origin blog.csdn.net/weixin_40228200/article/details/123654954