Reference: This blog post is prepared by referring the book "Salt Essentials; Craig Sebenik & Thomas Hatch; Oreilly publications"
Installation
- yum list salt salt-master salt-minion
- yum install -y salt salt-minion #Install these 2 packages on minions & master
- yum install -y salt-master # Install this package on master
Configuring master IP/DNS in minions
The basic minion configuration is located in /etc/salt/minion.You need to configure each minion with the DNS name or IP address of your Salt master.
The default Salt master configured is
$ grep '#master:' /etc/salt/minion
#master: salt
$ vi /etc/salt/minion
master 10.0.2.15
Starting Daemons
- service salt-master start # start this only on master
- service salt-minion start # start this both in master & minions
What is my minion-id?
- cat /etc/salt/minion_id #vagrant-centos65.vagrantup.com
What are the publish port and the return port numbers?
- 4505 and 4506 respectively
Where is the minion log file?
- /var/log/salt/minion
Key management
- salt-key
Example:
$ salt-key
Accepted Keys:
Denied Keys:
Unaccepted Keys:
vagrant-centos65.vagrantup.com
Rejected Keys:
- salt-key --list=unaccepted # view just the keys in the unaccepted state
Accepting a key
- salt-key --accept=vagrant-centos65.vagrantup.com --yes
- salt-key --accept-all
- salt-key --finger ubuntu-14.04-amd64-vbox
- salt-key --finger-all
- salt-call --local key.finger
- salt-call --local key.finger_master # to view fingerprint of the master
- salt-key --delete-all # on master
- service salt-minion restart # on all minions including master
- salt-key --accept-all
- /etc/salt/pki/master
- /etc/salt/pki/minion
salt-call: Execution on the Minion
- salt-call test.ping # salt-call will run an execution module or enforce a state, but only on localhost.
- salt-call --log-level=debug disk.percent / # debug mode
- salt-call --local test.ping
salt
- Format: salt target command
- salt vagrant-centos65.vagrantup.com test.ping #Target is Minion ID
- salt * test.ping # Target is Glob
- salt -L centos65-minion,ubuntu-14.04-amd64-vbox test.ping # Target is List (-L)
- salt 'ubun*' test.ping # Glob
- salt -E 'minion(1|2)\.example' test.ping # Regular expression (-E)
- salt -G 'os:CentOS' test.ping # Grains (-G)
- salt -G 'os:ubuntu' test.ping # Grains (-G)
- salt -C 'centos* or G@os:Ubuntu' test.ping # Compound (-C)
salt-run: Coordination of Jobs on the Master
Say you want to deploy a new application to 10 hosts, but you only want to take one down at a time. When you use the salt command with a target set of minions, the command is sent asynchronously to every minion. But if you want to run a command sequentially across many minions, a runner can help.The salt-run command is a master-only command. It does not take a target set of minions.
- salt-run manage.up
[root@vagrant-centos65 ~]# salt-run manage.up
- vagrant-centos65.vagrantup.com
- vagrant-centos65.vagrantup.com
This particular module, manage.up, uses the test.ping execution module, to determine whether a minion is healthy.
Difference between Modules and Functions
An execution module is actually a collection of execution functions. You run specific execution functions on a minion. For example, the test execution module has a function called ping. So, you run the test.ping execution function on a minion. Specifically, an execution module is a Python file. Each public method defined in that Python file is exposed as an execution function. Again, in our example, when you call test.ping, Salt looks for a file called test.py and then for a public function called ping inside that file.
No comments:
Post a Comment