SaltStack常用模块

自定义模块

自定义modules的文件目录应该是放在/srv/salt/_modules下面

[root@server1 ~]# mkdir /srv/salt/_modules
[root@server1 ~]# cd /srv/salt/_modules/
[root@server1 _modules]# vim my_disk.py
[root@server1 _modules]# cat my_disk.py 
#! /usr/bin/env python

def df():
    return __salt__['cmd.run']('df -h')
[root@server1 _modules]# salt server2 saltutil.sync_modules		##将自定义文件同步到server2
server2:
    - modules.my_disk

SaltStack常用模块_第1张图片
server2

[root@server2 ~]# cd /var/cache/salt/
[root@server2 salt]# tree minion/
minion/
├── accumulator
├── extmods
│   ├── grains
│   │   ├── my_grains.py
│   │   └── my_grains.pyc
│   └── modules	
│       └── my_disk.py											##master的自定义文件
├── files
│   └── base
│       ├── apache
│       │   ├── files
│       │   │   └── httpd.conf
│       │   └── install.sls
│       ├── _grains
│       │   └── my_grains.py
│       ├── _modules
│       │   └── my_disk.py
│       └── top.sls
├── highstate.cache.p
├── module_refresh
├── pkg_refresh
├── proc
└── sls.p

11 directories, 12 files

SaltStack常用模块_第2张图片

server1

[root@server1 _modules]# salt server2 my_disk.df
server2:
    Filesystem             Size  Used Avail Use% Mounted on
    /dev/mapper/rhel-root  9.8G  1.3G  8.6G  13% /
    devtmpfs               486M     0  486M   0% /dev
    tmpfs                  497M   12K  497M   1% /dev/shm
    tmpfs                  497M   13M  484M   3% /run
    tmpfs                  497M     0  497M   0% /sys/fs/cgroup
    /dev/sda1             1014M  139M  876M  14% /boot
    tmpfs                  100M     0  100M   0% /run/user/0

SaltStack常用模块_第3张图片

ssh模块

server2

[root@server2 salt]# systemctl stop salt-minion

server1

[root@server1 salt]# pwd
/etc/salt
[root@server1 salt]# vim roster
[root@server1 salt]# cat roster 
# Sample salt-ssh config file
#web1:
#  host: 192.168.42.1 # The IP addr or DNS hostname
#  user: fred         # Remote executions will be executed as user fred
#  passwd: foobarbaz  # The password to use for login, if omitted, keys are used
#  sudo: True         # Whether to sudo to root, not enabled by default
#web2:
#  host: 192.168.42.2

server2:
  host: 172.25.68.2
  user: root
  passwd: redhat

server3:
  host: 172.25.68.3
  user: root
  passwd: redhat

[root@server1 salt]# vim /etc/salt/master
把mysql的都注释					##因为minion连接了mysql,但此时minion已经关闭

[root@server1 salt]# systemctl restart salt-master
[root@server1 salt]# salt-ssh '*' test.ping
server2:
    True
server3:
    True

SaltStack常用模块_第4张图片

你可能感兴趣的:(SaltStack常用模块)