使用分组

修改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操作的更多相关文章

  1. Saltstack 操作目标,正则匹配,及组管理

    如果我们要维护好一个庞大的配置管理系统那么首选得维护好我们的管理对象,在saltstack系统中我们的管理对象叫做Target, 在master上我们可以采用不同Target去管理不同的Minion. ...

  2. 自动化运维工具 SaltStack 搭建

    原文地址:https://www.ibm.com/developerworks/cn/opensource/os-devops-saltstack-in-cloud/index.html#N10072 ...

  3. SaltStack远程执行Windows job程序(黑窗口)填坑经过

    近期接到领导通知,要将公司内的所有Windows服务添加到自动发布系统中,由于这种服务很多,节点分布散乱,每次都是由开发主管手动替换(虽然他们自己开发了自动打包替换工具,但仍需要一台一台登陆到服务器上 ...

  4. SaltStack 的基本概念与工作原理 架构设计

    随着云计算技术的快速普及与发展,越来越多的企业开始学习和搭建自己的云平台代替传统的 IT 交付模式,企业的 IT 环境也随之越来越复杂,常规的运维方法与技术已经无法满足现在云环境中系统的配置与变更.基 ...

  5. 学习saltstack (二)

    saltstack使用教程: 1.安装: 需要epel的yum源,没有的话把下面的复制并新建个文件 /etc/yum.repos.d/epel.repo 粘贴即可: [epel] name=Extra ...

  6. Saltstack自动化操作记录(2)-配置使用 【转】

    之前梳理了Saltstack自动化操作记录(1)-环境部署,下面说说saltstack配置及模块使用: 为了试验效果,再追加一台被控制端minion机器192.168.1.118需要在master控制 ...

  7. Saltstack自动化操作记录(1)-环境部署【转】

    早期运维工作中用过稍微复杂的Puppet,下面介绍下更为简单实用的Saltstack自动化运维的使用. Saltstack知多少Saltstack是一种全新的基础设施管理方式,是一个服务器基础架构集中 ...

  8. Saltstack自动化操作记录(2)-配置使用

    之前梳理了Saltstack自动化操作记录(1)-环境部署,下面说说saltstack配置及模块使用: 为了试验效果,再追加一台被控制端minion机器192.168.1.118需要在master控制 ...

  9. python 操作 saltstack Api(二) 示例

    获取token #!/usr/bin/env python #-*-coding:utf--*- import urllib import urllib.parse import urllib.req ...

随机推荐

  1. oracle函数 lag()和lead()

    [语法] lag(EXPR,<OFFSET>,<DEFAULT>) LEAD(EXPR,<OFFSET>,<DEFAULT>) [功能]表示根据COL1 ...

  2. oralce GROUPING

    /*从上面的结果中我们很容易发现,每个统计数据所对应的行都会出现null, 如何来区分到底是根据那个字段做的汇总呢,grouping函数判断是否合计列!*/ select decode(groupin ...

  3. 阿里云BaaS:降低区块链应用门槛,用技术构建商业互信

    5月8日,阿里云召开区块链服务(BaaS)商业化发布会,会上对BaaS产品.业务应用场景及生态策略进行了全面解读. 对于广大IT服务商和开发者而言,构建区块链应用存在三大痛点问题:成本高,研发投入大. ...

  4. 从HelloWorld看Knative Serving代码实现

    摘要: Knative Serving以Kubernetes和Istio为基础,支持无服务器应用程序和函数的部署并提供服务.我们从部署一个HelloWorld示例入手来分析Knative Servin ...

  5. H3C Telnet配置例子

  6. 20190608笔试题のCSS-属性继承

    以下的CSS属性哪些可以继承?(单选) A.   font-sizeB.   marginC.   widthD.   padding emmm,这题答案是A,看到这题我是能选对的,但又不由让我想到一 ...

  7. iptables发布内部网络服务器

    要使因特网上的计算机访问到内部网的FTP服务器.WEB服务器,在做为防火墙的计算机上应添加以下规则: 1. echo 1 > /proc/sys/net/ipv4/ip_forward 2. 发 ...

  8. H3C 配置帧中继交换

  9. php Restful设计

    1.restful是基于资源的,面向资源架构风格(一个链接,一张图.一个文本等等) 2.restful的http协议 2.1 url: 2.1.1 port 服务端口,默认为80 2.1.2 path ...

  10. CF1B.Spreadsheets(电子表格) 题解 模拟

    作者:zifeiy 标签:模拟 题目出处:Spreadsheets 题目描述 在流行的电子表格系统中(例如,在Excel中),使用如下计算方式来对列号进行计算. 第1列对应A,第2列对应B,--,第2 ...