Salt combined with crontab Auto-sync configuration file

Source: Internet
Author: User
Tags saltstack

Saltstack automatic synchronization configuration file, in fact, I am a combination of crontab to get, is to put the Minion end of the machine into a group, and then for this group to do job execution State.sls to do.


Note: In fact saltstack have their own schedule planning tasks. Just look at the dazed, and I bright actually job, and again, if you use automatic synchronization configuration file, if you have already know, and have been tested in the test environment, responsible for you know ... and auto-sync, you don't see the state of execution at all. So you know. In fact, these are and egg east.

One: To group the Minion, in order not to confuse with Master Master profile, create a separate configuration file, in the master configuration file, open the corresponding comments as follows


[Email protected]:~# grep "^default"/etc/salt/master

Default_include:master.d/*.conf

The Web in the configuration file is a group set for minion. Group name is web

[Email protected]:/etc/salt/master.d# cat nodegroup.conf

Nodegroups:

Web: ' [email protected] '


Test with a terminal command

[Email protected]:/etc/salt/master.d# salt-n Web test.ping

Iz23f6c5z8tz:

True

Two: Use salt to install Nginx, in the default base environment to create the APT directory, because I use apt to install Nginx, easy to test ....

[Email protected]:/srv/salt/base# Tree apt/

apt/

├──files

│└──nginx.conf

└──install.sls

1 directory, 2 files


The contents of the installed Nginx SLS file are as follows:

[Email protected]:/srv/salt/base/apt# cat Install.sls

Apt-nginx-install:

Cmd.run:

-Name:apt-get Install Nginx-y

-Unless:test-d/etc/nginx

Apt-nginx-config:

File.managed:

-Name:/etc/nginx/nginx.conf

-Source:salt://apt/files/nginx.conf

-User:root

-Group:root

-mode:644

Apt-nginx-service:

Service.running:

-Name:nginx

-Reload:true

-Require:

-Cmd:apt-nginx-install

-File:apt-nginx-config

-Watch:

-File:apt-nginx-config

Three: Installation Nginx

[Email protected]:/srv/salt/base/apt# salt-n web State.sls apt.install

Iz23f6c5z8tz:

----------

State:-cmd

Name:apt-get Install Nginx-y

Function:run

Result:true

Comment:unless Execution succeeded

Changes:

----------

State:-File

Name:/etc/nginx/nginx.conf

Function:managed

Result:true

Comment:file/etc/nginx/nginx.conf is in the correct state

Changes:

----------

State:-Service

Name:nginx

Function:running

Result:true

comment:started Service Nginx

Changes:nginx:True


Summary

------------

Succeeded:3

failed:0

------------

Total:3

View the minion-side Nginx service status for a Web group

[Email protected]:/srv/salt/base/apt/files# salt-n web cmd.run ' service nginx status '

Iz23f6c5z8tz:

* Nginx is running

Four: Set up scheduled Tasks, as well as modify Nginx configuration file, to see if the Nginx configuration file changes and load services, easy to test my setup every 1 minutes to execute,

#web Group Test Salt

*/1 * * * * salt-n web State.sls apt.install


Modify the nginx.conf configuration and stop the Nginx service to see if the configuration is changed and the service is overloaded

Stop Nginx Service for Web group minion

[Email protected]:/srv/salt/base/apt/files# salt-n web service.stop nginx

Iz23f6c5z8tz:

True


[Email protected]:/srv/salt/base/apt/files# salt-n web cmd.run ' service nginx status '

Iz23f6c5z8tz:

* Nginx is not running

Adding content to the nginx.conf file

[Email protected]:/srv/salt/base/apt/files# tail-n 1 nginx.conf

#This is a test salt


View the Minion-side nginx configuration file for the Web group and view the service status after 1 minutes

[Email protected]:/srv/salt/base/apt/files# salt-n web cmd.run ' tail-n 1/etc/nginx/nginx.conf '

Iz23f6c5z8tz:

#This is a test salt


[Email protected]:/srv/salt/base/apt/files# salt-n web cmd.run ' service nginx status '

Iz23f6c5z8tz:

* Nginx is running




This article is from the "Village Boys" blog, please make sure to keep this source http://noodle.blog.51cto.com/2925423/1750779

Salt combined with crontab Auto-sync configuration file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.