我积极解决 发表于 2018-1-3 19:56:02

自动化运维工具SaltStack

  在使用 SaltStack 对主机进行批量管理的时候,因为不同的服务器组所做的业务功能不同,因此为了更加方便的管理,势必要对主机进行分组管理。

[*]G -- 针对 Grains 做单个匹配,例如:G@os:Ubuntu
[*]E -- 针对 minion 针对正则表达式做匹配,例如:E@web\d+.(dev|qa|prod).loc
[*]P -- 针对 Grains 做正则表达式匹配,例如:P@os:(RedHat|Fedora|CentOS)
[*]L -- 针对 minion 做列表匹配,例如:L@minion1.example.com,minion3.domain.com or bl*.domain.com
[*]I -- 针对 Pillar 做单个匹配,例如:I@pdata:foobar
[*]S -- 针对子网或是 IP 做匹配,例如:S@192.168.1.0/24 or S@192.168.1.100
[*]R -- 针对客户端范围做匹配,例如: R@%foo.bar
  #nodegroups:
  #group1: 'L@foo.domain.com,bar.domain.com,baz.domain.com or bl*.domain.com'
  #group2: 'G@os:Debian and foo.domain.com'
  #group3: 'G@os:Debian and N@group1'
  #group4:
  #    - 'G@foo:bar'
  #    - 'or'
  #    - 'G@foo:baz'
  nodegroups:
  testgroup1: 'E@192.168.8.11'
  testgroup2: 'L@192.168.8.116,192.168.8.117'
  testgroup3: 'G@os:Centos'
  testgroup4: 'S@192.168.8.0/24'
  # salt -N testgroup1 'test.ping'
  192.168.8.117:
  True
  192.168.8.116:
  True
  # salt -N testgroup2 'test.ping'
  192.168.8.117:
  True
  192.168.8.116:
  True
  # salt -N testgroup3 'test.ping'
  192.168.8.117:
  True
  # salt -N testgroup4 'test.ping'
  192.168.8.117:
  True
  192.168.8.116:
  True
结论
  使用 L 列表的方式,必须把 minion 列出来,或者是列出几台后,在后面接 or 或者 and 表达式, or 或者 and 后面接的表达式后面可以使用正则表达式。
  注:想使用正则表达式,最好的方式就是使用 E
页: [1]
查看完整版本: 自动化运维工具SaltStack