saltstack操作
使用分组
修改minon的ID,做一个标识
[root@node2 ~]# vim /etc/salt/minion
master: 172.25.254.130
id: web1 #node2
[root@node2 ~]# systemctl restart salt-minion
[root@node3 ~]# vim /etc/salt/minion
master: 172.25.254.130
id: web2 #node3
[root@node3 ~]# vim /etc/salt/minion
[root@node4 ~]# systemctl restart salt-minion
master: 172.25.254.130
id: web3 #node3
[root@node4 ~]# systemctl restart salt-minion
[root@node5 ~]# vim /etc/salt/minion
master: 172.25.254.130
id: db1 #node4
[root@node5 ~]# systemctl restart salt-minion
[root@node6 ~]# vim /etc/salt/minion
master: 172.25.254.130
id: db2 #node5
[root@node6 ~]# systemctl restart salt-minion
master重新添加秘钥
[root@node1 ~]# salt-key -D
[root@node1 ~]# salt-key -A
[root@node1 ~]# salt-key -L
Accepted Keys:
db1
db2
web1
web2
web3
Denied Keys:
Unaccepted Keys:
Rejected Keys:
测试连通性
[root@node1 ~]# salt '*' test.ping
web2:
True
web3:
True
db1:
True
db2:
True
web1:
True
[root@node1 ~]# salt '*' cmd.run 'date'
db2:
Wed Apr :: CST
web3:
Wed Apr :: CST
web2:
Wed Apr :: CST
db1:
Wed Apr :: CST
web1:
Wed Apr :: CST
[root@node1 ~]# salt -E "web\d" test.ping #\d 匹配一个数字 \d+ 匹配 1..n 个数字
web2:
True
web3:
True
web1:
True
[root@node1 ~]# salt -L "web1,web2,db2" test.ping #L 列表 后面跟随主机的名称,用 “,”分割
web2:
True
web1:
True
db2:
True
分组
[root@node1 ~]# vim /etc/salt/master
nodegroups:
group1: "L@web1,web2,db2"
groupweb: "L@web1,web2,web3"
groupdb: "L@db1,db2"
[root@node1 ~]# systemctl restart salt-master
测试组
[root@node1 ~]# salt -S "172.25.254.0/24" test.ping
web2:
True
web3:
True
web1:
True
db1:
True
db2:
True
[root@node1 ~]# salt -N group1 test.ping
web2:
True
web1:
True
db2:
True
[root@node1 ~]# salt -N groupweb test.ping
web2:
True
web1:
True
web3:
True
[root@node1 ~]# salt -N groupdb test.ping
db2:
True
db1:
True
发送文件和文件夹
[root@node1 ~]# mkdir -p /srv/salt/files
[root@node1 ~]# cd /srv/salt/files
[root@node1 files]# echo testfile >> testfile
[root@node1 files]# salt -N groupweb cp.get_file salt://files/testfile /var/tmp/f1
检测
[root@node1 files]# salt -N groupweb cmd.run 'md5sum /var/tmp/f1'
源文件对比
[root@node1 files]# md5sum testfile
e9409172a4036cc688f169c72131e921 testfile
查看内容
[root@node1 files]# salt -N groupweb cmd.run 'cat /var/tmp/f1'
修改文件内容传递,内容覆盖
[root@node1 files]# echo >>testfile
[root@node1 files]# salt -N groupweb cp.get_file salt://files/testfile /var/tmp/f1
web3:
/var/tmp/f1
web1:
/var/tmp/f1
web2:
/var/tmp/f1
[root@node1 files]# salt -N groupweb cmd.run 'cat /var/tmp/f1'
web3:
testfile web2:
testfile web1:
testfile
传输文件夹
[root@node1 files]# cd ..
[root@node1 salt]# salt -N groupweb cp.get_dir salt://files /var/tmp/testdir
检测:
[root@node1 salt]# salt -N groupweb cmd.run 'cat /var/tmp/testdir/files/testfile'
查看模块,功能和使用方法
[root@node1 salt]# salt 'web1' sys.list_modules
web1:
- acl
- aliases
- alternatives
- archive
- artifactory
- beacons
- bigip
- blockdev
- btrfs
- buildout
- cloud
- cmd
- composer
- config
- consul
- container_resource
- cp
- cron
- data
- defaults
- devmap
- disk
- django
- dnsmasq
- dnsutil
- drbd
- elasticsearch
- environ
- etcd
- ethtool
- event
- extfs
- file
- firewalld
- gem
- genesis
- gnome
- grains
- group
- hashutil
- hipchat
- hosts
- http
- img
- incron
- infoblox
- ini
- inspector
- introspect
- ip
- ipset
- iptables
- jboss7
- jboss7_cli
- k8s
- key
- keyboard
- kmod
- locale
- locate
- logrotate
- lowpkg
- lvm
- match
- mine
- minion
- modjk
- mount
- nagios_rpc
- network
- nova
- nspawn
- openscap
- openstack_config
- pagerduty
- pagerduty_util
- pam
- partition
- pillar
- pip
- pkg
- pkg_resource
- postfix
- publish
- pushover
- pyenv
- random
- random_org
- rbenv
- rest_sample_utils
- ret
- rvm
- s3
- s6
- salt_proxy
- saltutil
- schedule
- scsi
- sdb
- seed
- serverdensity_device
- service
- shadow
- slack
- slsutil
- smbios
- smtp
- sqlite3
- ssh
- state
- status
- supervisord
- sys
- sysctl
- sysfs
- syslog_ng
- system
- telemetry
- temp
- test
- timezone
- tuned
- udev
- uptime
- user
- vbox_guest
- virtualenv
- xfs
- zenoss
modules
[root@node1 salt]# salt 'web1' sys.list_functions test
web1:
- test.arg
- test.arg_repr
- test.arg_type
- test.assertion
- test.attr_call
- test.collatz
- test.conf_test
- test.cross_test
- test.echo
- test.exception
- test.false
- test.fib
- test.get_opts
- test.kwarg
- test.module_report
- test.not_loaded
- test.opts_pkg
- test.outputter
- test.ping
- test.provider
- test.providers
- test.rand_sleep
- test.rand_str
- test.retcode
- test.sleep
- test.stack
- test.true
- test.try_
- test.tty
- test.version
- test.versions
- test.versions_information
- test.versions_report
functions
[root@node1 salt]# salt web1 sys.doc test
test.arg: Print out the data passed into the function ``*args`` and ```kwargs``, this
is used to both test the publication data and cli argument passing, but
also to display the information available within the publication data.
Returns {"args": args, "kwargs": kwargs}. CLI Example: salt '*' test.arg "two" 3.1 txt="hello" wow='{a: 1, b: "hello"}' test.arg_repr: Print out the data passed into the function ``*args`` and ```kwargs``, this
is used to both test the publication data and cli argument passing, but
also to display the information available within the publication data.
Returns {"args": repr(args), "kwargs": repr(kwargs)}. CLI Example: salt '*' test.arg_repr "two" 3.1 txt="hello" wow='{a: 1, b: "hello"}' test.arg_type: Print out the types of the args and kwargs. This is used to test the types
of the args and kwargs passed down to the minion CLI Example: salt '*' test.arg_type 'int' test.assertion: Assert the given argument CLI Example: salt '*' test.assertion False test.attr_call: Call grains.items via the attribute CLI Example: salt '*' test.attr_call test.collatz: Execute the collatz conjecture from the passed starting number,
returns the sequence and the time it took to compute. Used for
performance tests. CLI Example: salt '*' test.collatz test.conf_test: Return the value for test.foo in the minion configuration file, or return
the default value CLI Example: salt '*' test.conf_test test.cross_test: Execute a minion function via the __salt__ object in the test
module, used to verify that the minion functions can be called
via the __salt__ module. CLI Example: salt '*' test.cross_test file.gid_to_group test.echo: Return a string - used for testing the connection CLI Example: salt '*' test.echo 'foo bar baz quo qux' test.exception: Raise an exception Optionally provide an error message or output the full stack. CLI Example: salt '*' test.exception 'Oh noes!' test.false: Always return False CLI Example: salt '*' test.false test.fib: Return the num-th Fibonacci number, and the time it took to compute in
seconds. Used for performance tests. This function is designed to have terrible performance. CLI Example: salt '*' test.fib test.get_opts: Return the configuration options passed to this minion CLI Example: salt '*' test.get_opts test.kwarg: Print out the data passed into the function ``**kwargs``, this is used to
both test the publication data and cli kwarg passing, but also to display
the information available within the publication data. CLI Example: salt '*' test.kwarg num= txt="two" env='{a: 1, b: "hello"}' test.module_report: Return a dict containing all of the execution modules with a report on
the overall availability via different references CLI Example: salt '*' test.module_report test.not_loaded: List the modules that were not loaded by the salt loader system CLI Example: salt '*' test.not_loaded test.opts_pkg: Return an opts package with the grains and opts for this minion.
This is primarily used to create the options used for master side
state compiling routines CLI Example: salt '*' test.opts_pkg test.outputter: Test the outputter, pass in data to return CLI Example: salt '*' test.outputter foobar test.ping: Used to make sure the minion is up and responding. Not an ICMP ping. Returns ``True``. CLI Example: salt '*' test.ping test.provider: Pass in a function name to discover what provider is being used CLI Example: salt '*' test.provider service test.providers: Return a dict of the provider names and the files that provided them CLI Example: salt '*' test.providers test.rand_sleep: Sleep for a random number of seconds, used to test long-running commands
and minions returning at differing intervals CLI Example: salt '*' test.rand_sleep test.rand_str: Return a random string size
size of the string to generate
hash_type
hash type to use New in version 2015.5. CLI Example: salt '*' test.rand_str test.retcode: Test that the returncode system is functioning correctly CLI Example: salt '*' test.retcode test.sleep: Instruct the minion to initiate a process that will sleep for a given
period of time. CLI Example: salt '*' test.sleep test.stack: Return the current stack trace CLI Example: salt '*' test.stack test.true: Always return True CLI Example: salt '*' test.true test.try_: Try to run a module command. On an exception return None.
If `return_try_exception` is set True return the exception.
This can be helpful in templates where running a module might fail as expected. CLI Example: <pre>
{% for i in range(,) %}
{{ salt['test.try'](module='ipmi.get_users', bmc_host='172.2.2.'+i)|yaml(False) }}
{% endfor %}
</pre> test.tty: Deprecated! Moved to cmdmod. CLI Example: salt '*' test.tty tty0 'This is a test'
salt '*' test.tty pts3 'This is a test' test.version: Return the version of salt on the minion CLI Example: salt '*' test.version test.versions: This function is an alias of ``versions_report``. Returns versions of components used by salt CLI Example: salt '*' test.versions_report test.versions_information: Report the versions of dependent and system software CLI Example: salt '*' test.versions_information test.versions_report: Returns versions of components used by salt CLI Example: salt '*' test.versions_report
help
拷贝文件
相当于 ssh 到目的主机执行 cp
[root@node1 salt]# salt -N groupweb file.copy /etc/passwd /var/tmp/passwd
web3:
True
web1:
True
web2:
True
[root@node1 salt]# salt -N groupweb cmd.run 'ls /var/tmp/passwd'
web2:
/var/tmp/passwd
web3:
/var/tmp/passwd
web1:
/var/tmp/passwd
grains 模块
查看 节点 grains 的所有信息
[root@node1 salt]# salt 'web1' grains.items
web1:
----------
SSDs:
biosreleasedate:
//
biosversion:
6.00
cpu_flags:
- fpu
- vme
- de
- pse
- tsc
- msr
- pae
- mce
- cx8
- apic
- sep
- mtrr
- pge
- mca
- cmov
- pat
- pse36
- clflush
- mmx
- fxsr
- sse
- sse2
- ss
- ht
- syscall
- nx
- pdpe1gb
- rdtscp
- lm
- constant_tsc
- arch_perfmon
- nopl
- xtopology
- tsc_reliable
- nonstop_tsc
- eagerfpu
- pni
- pclmulqdq
- ssse3
- fma
- cx16
- pcid
- sse4_1
- sse4_2
- x2apic
- movbe
- popcnt
- tsc_deadline_timer
- aes
- xsave
- avx
- f16c
- rdrand
- hypervisor
- lahf_lm
- abm
- fsgsbase
- tsc_adjust
- bmi1
- avx2
- smep
- bmi2
- invpcid
- xsaveopt
- arat
cpu_model:
Intel(R) Core(TM) i5- CPU @ .20GHz
cpuarch:
x86_64
disks:
- sda
- sdb
- sdc
- sdd
- sr0
- dm-
- dm-
dns:
----------
domain:
ip4_nameservers:
- 172.25.254.2
ip6_nameservers:
nameservers:
- 172.25.254.2
options:
search:
- localdomain
sortlist:
domain:
fqdn:
node2
fqdn_ip4:
- 172.25.254.131
fqdn_ip6:
- fe80:::96e2:b57b:be1d
gid: gpus:
|_
----------
model:
SVGA II Adapter
vendor:
unknown
groupname:
root
host:
node2
hwaddr_interfaces:
----------
ens33:
:0c:::2e:
ens34:
:0c:::2e:
lo:
:::::
id:
web1
init:
systemd
ip4_interfaces:
----------
ens33:
- 172.25.254.131
ens34:
lo:
- 127.0.0.1
ip6_interfaces:
----------
ens33:
- fe80:::96e2:b57b:be1d
ens34:
lo:
- ::
ip_interfaces:
----------
ens33:
- 172.25.254.131
- fe80:::96e2:b57b:be1d
ens34:
lo:
- 127.0.0.1
- ::
ipv4:
- 127.0.0.1
- 172.25.254.131
ipv6:
- ::
- fe80:::96e2:b57b:be1d
kernel:
Linux
kernelrelease:
3.10.-.el7.x86_64
locale_info:
----------
defaultencoding:
UTF-
defaultlanguage:
en_US
detectedencoding:
UTF-
localhost:
node2
lsb_distrib_codename:
CentOS Linux (Core)
lsb_distrib_id:
CentOS Linux
machine_id:
8ebd8732ba9148f79a787d6901b7e2a9
manufacturer:
VMware, Inc.
master:
172.25.254.130
mdadm:
mem_total: nodename:
node2
num_cpus: num_gpus: os:
CentOS
os_family:
RedHat
osarch:
x86_64
oscodename:
CentOS Linux (Core)
osfinger:
CentOS Linux-
osfullname:
CentOS Linux
osmajorrelease: osrelease:
7.4.
osrelease_info:
-
-
-
path:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/bin:/sbin
pid: productname:
VMware Virtual Platform
ps:
ps -efH
pythonexecutable:
/usr/bin/python
pythonpath:
- /usr/bin
- /usr/lib64/python27.zip
- /usr/lib64/python2.
- /usr/lib64/python2./plat-linux2
- /usr/lib64/python2./lib-tk
- /usr/lib64/python2./lib-old
- /usr/lib64/python2./lib-dynload
- /usr/lib64/python2./site-packages
- /usr/lib/python2./site-packages
pythonversion:
-
-
-
- final
-
saltpath:
/usr/lib/python2./site-packages/salt
saltversion:
2016.11.
saltversioninfo:
-
-
-
-
selinux:
----------
enabled:
True
enforced:
Enforcing
serialnumber:
VMware- 4d 8c fc c0 - fd ee 2e
server_id: shell:
/bin/sh
systemd:
----------
features:
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN
version: uid: username:
root
uuid:
fc8c4d56--88c0-77fd-ee6097122e59
virtual:
VMware
zmqversion:
4.1.
web-grains
查看网卡信息
[root@node1 salt]# salt 'web1' grains.item ip4_interfaces
web1:
----------
ip4_interfaces:
----------
ens33:
- 172.25.254.131
ens34:
lo:
- 127.0.0.1
查询主机名
[root@node1 salt]# salt 'web1' grains.item fqdn
web1:
----------
fqdn:
node2
saltstack操作的更多相关文章
- Saltstack 操作目标,正则匹配,及组管理
如果我们要维护好一个庞大的配置管理系统那么首选得维护好我们的管理对象,在saltstack系统中我们的管理对象叫做Target, 在master上我们可以采用不同Target去管理不同的Minion. ...
- 自动化运维工具 SaltStack 搭建
原文地址:https://www.ibm.com/developerworks/cn/opensource/os-devops-saltstack-in-cloud/index.html#N10072 ...
- SaltStack远程执行Windows job程序(黑窗口)填坑经过
近期接到领导通知,要将公司内的所有Windows服务添加到自动发布系统中,由于这种服务很多,节点分布散乱,每次都是由开发主管手动替换(虽然他们自己开发了自动打包替换工具,但仍需要一台一台登陆到服务器上 ...
- SaltStack 的基本概念与工作原理 架构设计
随着云计算技术的快速普及与发展,越来越多的企业开始学习和搭建自己的云平台代替传统的 IT 交付模式,企业的 IT 环境也随之越来越复杂,常规的运维方法与技术已经无法满足现在云环境中系统的配置与变更.基 ...
- 学习saltstack (二)
saltstack使用教程: 1.安装: 需要epel的yum源,没有的话把下面的复制并新建个文件 /etc/yum.repos.d/epel.repo 粘贴即可: [epel] name=Extra ...
- Saltstack自动化操作记录(2)-配置使用 【转】
之前梳理了Saltstack自动化操作记录(1)-环境部署,下面说说saltstack配置及模块使用: 为了试验效果,再追加一台被控制端minion机器192.168.1.118需要在master控制 ...
- Saltstack自动化操作记录(1)-环境部署【转】
早期运维工作中用过稍微复杂的Puppet,下面介绍下更为简单实用的Saltstack自动化运维的使用. Saltstack知多少Saltstack是一种全新的基础设施管理方式,是一个服务器基础架构集中 ...
- Saltstack自动化操作记录(2)-配置使用
之前梳理了Saltstack自动化操作记录(1)-环境部署,下面说说saltstack配置及模块使用: 为了试验效果,再追加一台被控制端minion机器192.168.1.118需要在master控制 ...
- python 操作 saltstack Api(二) 示例
获取token #!/usr/bin/env python #-*-coding:utf--*- import urllib import urllib.parse import urllib.req ...
随机推荐
- 二分查找 Day08
package com.sxt.arraytest2; /* * 二分查找 前提:有序 */ public class TestBinarySearch { public static void ma ...
- java代码简单实现栈
1. 基于数组简单实现 /** * @author <a herf="mailto:yanwu0527@163.com">XuBaofeng</a> * @ ...
- python 浮点型(float)
- This cache store does not support tagging.
用户权限管理系统 https://github.com/Zizaco/entrust 再添加角色的时候... 报了一个错.. BadMethodCallException in Repository. ...
- TensorFlow 池化层
在 TensorFlow 中使用池化层 在下面的练习中,你需要设定池化层的大小,strides,以及相应的 padding.你可以参考 tf.nn.max_pool().Padding 与卷积 pad ...
- 学习layui框架
Layui是一款功能齐全的前端框架,需要引入对应的CSS文件和JS文件,附属官网链接:Layui官网
- adam调参
微调 #阿尔法 "learning_rate": 3e-5, #学习率衰减 "weight_decay": 0.1,// "weight_decay& ...
- SuperSocket获取会话的连接和断开事件
关键字: 连接事件, 断开事件, OnSessionStarted,OnSessionClosed, NewSessionConnected, SessionClosed AppSession 的虚方 ...
- torch中的copy()和clone()
torch中的copy()和clone() 1.torch中的copy()和clone() y = torch.Tensor(2,2):copy(x) ---1 修改y并不改变原来的x y = x:c ...
- 如何将为Android开发的AIR应用转移到SD卡
如果你想用户能够将为Android开发的AIR应用转移到SD卡上,所需要做的是在你的应用程序描述符中修改一下.如果你想你的应用程序默认安装到内置存储器中,但是允许用户把它转移到SD卡上,设置andro ...