saltstack模块

1、cmd模块,实现远程命令行调用执行(默认root权限操作,操作需谨慎)

# salt operation cmd.run "uptime"
operation:
     13:46:57 up 32 min,  1 user,  load average: 0.07, 0.05, 0.07



2、cp模块,实现远程文件、目录复制分发,以及下载URL等操作


将master上的文件、目录复制到minion被控主机。

a、get_file:salt.modules.cp.get_file(path, dest, saltenv='base', makedirs=False, template=None, gzip=None, **kwargs)

path:master需要分发文件路径
dest:目标minion存放路径和文件名
saltenv:master定义的环境名称
makedirs:目标minion如果路径目录不存在,是否创建目录。

# salt operation  cp.get_file salt://test.py /tmp1/tmp/test1.py saltenv='cmdb' makedirs=True
operation:
    /tmp1/tmp/test1.py


b、get_dir: salt.modules.cp.get_dir(path, dest, saltenv='base', template=None, gzip=None, **kwargs)

# salt operation cp.get_dir salt://upload /tmp1/tmp saltenv='cmdb' 
operation:
    - /tmp1/tmp/upload/crontab.txt
    - /tmp1/tmp/upload/python_test.txt


将master上的文件、目录复制到minion的cache目录。

c、cache_dir :salt.modules.cp.cache_dir(path, saltenv='base', include_empty=False, include_pat=None, exclude_pat=None)

# salt \* cp.cache_dir salt://user
slave01:
    - /var/cache/salt/minion/files/base/user/adduser.sls
operation:
    - /var/cache/salt/minion/files/base/user/adduser.sls


d、cache_file:salt.modules.cp.cache_file(path, saltenv='base')

# salt \* cp.cache_file salt://resin/init.sls
slave01:
    /var/cache/salt/minion/files/base/resin/init.sls
operation:
    /var/cache/salt/minion/files/base/resin/init.sls


f、cache_local_file

将目标minion主机的文件或目录收集到master的cache目录下不能执行多台minion,否则同步过来的数据是最后执行的minion主机

# salt operation cp.cache_local_file /etc/hosts
operation:
    /var/cache/salt/minion/localfiles/etc/hosts

3、svn模块

salt 'operation' svn.checkout /data/  svn://192.168.62.110 /data/svndata/  mysql kbson kbsonlong

主机名:operation

svn仓库:svn://192.168.62.110

文件存放路径/data/svndata/

导出后文件的所属用户:mysql

svn账户:kbson 

svn密码:kbsonlong


# salt 'operation' svn.checkout /data/  svn://192.168.62.110 /data/svndata/  mysql kbson kbsonlong
operation:
    A    /data/svndata/hooks
    A    /data/svndata/hooks/pre-revprop-change.tmpl
    A    /data/svndata/hooks/post-commit.tmpl
    A    /data/svndata/hooks/post-lock.tmpl
    A    /data/svndata/hooks/pre-commit.tmpl
    A    /data/svndata/hooks/pre-lock.tmpl
    A    /data/svndata/hooks/post-unlock.tmpl
    A    /data/svndata/hooks/pre-unlock.tmpl
    A    /data/svndata/hooks/post-revprop-change.tmpl
    A    /data/svndata/hooks/start-commit.tmpl
    A    /data/svndata/conf
    A    /data/svndata/conf/svnserve.conf
    A    /data/svndata/conf/passwd
    A    /data/svndata/conf/authz
    A    /data/svndata/db
    A    /data/svndata/db/revs
    A    /data/svndata/db/revs/0
    A    /data/svndata/db/revs/0/0
    A    /data/svndata/db/txn-current-lock
    A    /data/svndata/db/revprops
    A    /data/svndata/db/revprops/0
    A    /data/svndata/db/revprops/0/0
    A    /data/svndata/db/write-lock
    A    /data/svndata/db/current
    A    /data/svndata/db/fsfs.conf
    A    /data/svndata/db/min-unpacked-rev
    A    /data/svndata/db/uuid
    A    /data/svndata/db/fs-type
    A    /data/svndata/db/format
    A    /data/svndata/db/transactions
    A    /data/svndata/db/transactions/0-0.txn
    A    /data/svndata/db/transactions/0-0.txn/node._1b.0
    A    /data/svndata/db/transactions/0-0.txn/node._1d.0
    A    /data/svndata/db/transactions/0-0.txn/node._1e.0
    A    /data/svndata/db/transactions/0-0.txn/next-ids
    A    /data/svndata/db/transactions/0-0.txn/node._b.0
    A    /data/svndata/db/transactions/0-0.txn/node._11.0
    A    /data/svndata/db/transactions/0-0.txn/node._l.0.children
    A    /data/svndata/db/transactions/0-0.txn/node._d.0
    A    /data/svndata/db/transactions/0-0.txn/node._13.0
    A    /data/svndata/db/transactions/0-0.txn/node._f.0
    A    /data/svndata/db/transactions/0-0.txn/node._15.0
    A    /data/svndata/db/transactions/0-0.txn/node._0.0.children
    A    /data/svndata/db/transactions/0-0.txn/node._h.0
    A    /data/svndata/db/transactions/0-0.txn/node._17.0
    A    /data/svndata/db/transactions/0-0.txn/node._j.0
    A    /data/svndata/db/transactions/0-0.txn/node._19.0
    A    /data/svndata/db/transactions/0-0.txn/node._1d.0.children
    A    /data/svndata/db/transactions/0-0.txn/node._l.0
    A    /data/svndata/db/transactions/0-0.txn/node._v.0.children
    A    /data/svndata/db/transactions/0-0.txn/node._m.0
    A    /data/svndata/db/transactions/0-0.txn/node._o.0
    A    /data/svndata/db/transactions/0-0.txn/node._0.0
    A    /data/svndata/db/transactions/0-0.txn/node.0.0
    A    /data/svndata/db/transactions/0-0.txn/node._q.0
    A    /data/svndata/db/transactions/0-0.txn/node._2.0
    A    /data/svndata/db/transactions/0-0.txn/node._t.0
    A    /data/svndata/db/transactions/0-0.txn/node._5.0
    A    /data/svndata/db/transactions/0-0.txn/node._v.0
    A    /data/svndata/db/transactions/0-0.txn/node._w.0
    A    /data/svndata/db/transactions/0-0.txn/node._7.0
    A    /data/svndata/db/transactions/0-0.txn/node._y.0
    A    /data/svndata/db/transactions/0-0.txn/node._9.0
    A    /data/svndata/db/transactions/0-0.txn/props
    A    /data/svndata/db/transactions/0-0.txn/node._m.0.children
    A    /data/svndata/db/transactions/0-0.txn/node._o.0.children
    A    /data/svndata/db/transactions/0-0.txn/changes
    A    /data/svndata/db/transactions/0-0.txn/node.0.0.children
    A    /data/svndata/db/transactions/0-0.txn/node._w.0.children
    A    /data/svndata/db/txn-current
    A    /data/svndata/db/txn-protorevs
    A    /data/svndata/db/txn-protorevs/0-0.rev
    A    /data/svndata/db/txn-protorevs/0-0.rev-lock
    A    /data/svndata/db/rep-cache.db
    A    /data/svndata/format
    A    /data/svndata/README.txt
    A    /data/svndata/locks
    A    /data/svndata/locks/db.lock
    A    /data/svndata/locks/db-logs.lock
    Checked out revision 1.


svn新增

# salt operation svn.add /data/svndata/ /data/svndata/1.txt 
operation:
    A         /data/svndata/1.txt


svn提交

# salt operation svn.commit / /data/svndata/ '1.txt' mysql kbson kbsonlong
operation:
    Adding         data/svndata/1.txt
    Transmitting file data .
    Committed revision 2.

版本号改变为2


在/tmp/test目录导出一份,看是否提交成功,

# salt 'operation' svn.checkout /  svn://192.168.62.110 /tmp/test  mysql kbson kbsonlong
operation:
    A    /tmp/test/hooks
    A    /tmp/test/hooks/pre-revprop-change.tmpl
    A    /tmp/test/hooks/post-commit.tmpl
    A    /tmp/test/hooks/post-lock.tmpl
    A    /tmp/test/hooks/pre-commit.tmpl
    A    /tmp/test/hooks/pre-lock.tmpl
    A    /tmp/test/hooks/post-unlock.tmpl
    A    /tmp/test/hooks/pre-unlock.tmpl
    A    /tmp/test/hooks/post-revprop-change.tmpl
    A    /tmp/test/hooks/start-commit.tmpl
    A    /tmp/test/conf
    A    /tmp/test/conf/svnserve.conf
    A    /tmp/test/conf/passwd
    A    /tmp/test/conf/authz
    A    /tmp/test/db
    A    /tmp/test/db/revs
    A    /tmp/test/db/revs/0
    A    /tmp/test/db/revs/0/0
    A    /tmp/test/db/txn-current-lock
    A    /tmp/test/db/revprops
    A    /tmp/test/db/revprops/0
    A    /tmp/test/db/revprops/0/0
    A    /tmp/test/db/write-lock
    A    /tmp/test/db/current
    A    /tmp/test/db/fsfs.conf
    A    /tmp/test/db/min-unpacked-rev
    A    /tmp/test/db/uuid
    A    /tmp/test/db/fs-type
    A    /tmp/test/db/format
    A    /tmp/test/db/transactions
    A    /tmp/test/db/transactions/0-0.txn
    A    /tmp/test/db/transactions/0-0.txn/node._1b.0
    A    /tmp/test/db/transactions/0-0.txn/node._1d.0
    A    /tmp/test/db/transactions/0-0.txn/node._1e.0
    A    /tmp/test/db/transactions/0-0.txn/next-ids
    A    /tmp/test/db/transactions/0-0.txn/node._b.0
    A    /tmp/test/db/transactions/0-0.txn/node._11.0
    A    /tmp/test/db/transactions/0-0.txn/node._l.0.children
    A    /tmp/test/db/transactions/0-0.txn/node._d.0
    A    /tmp/test/db/transactions/0-0.txn/node._13.0
    A    /tmp/test/db/transactions/0-0.txn/node._f.0
    A    /tmp/test/db/transactions/0-0.txn/node._15.0
    A    /tmp/test/db/transactions/0-0.txn/node._0.0.children
    A    /tmp/test/db/transactions/0-0.txn/node._h.0
    A    /tmp/test/db/transactions/0-0.txn/node._17.0
    A    /tmp/test/db/transactions/0-0.txn/node._j.0
    A    /tmp/test/db/transactions/0-0.txn/node._19.0
    A    /tmp/test/db/transactions/0-0.txn/node._1d.0.children
    A    /tmp/test/db/transactions/0-0.txn/node._l.0
    A    /tmp/test/db/transactions/0-0.txn/node._v.0.children
    A    /tmp/test/db/transactions/0-0.txn/node._m.0
    A    /tmp/test/db/transactions/0-0.txn/node._o.0
    A    /tmp/test/db/transactions/0-0.txn/node._0.0
    A    /tmp/test/db/transactions/0-0.txn/node.0.0
    A    /tmp/test/db/transactions/0-0.txn/node._q.0
    A    /tmp/test/db/transactions/0-0.txn/node._2.0
    A    /tmp/test/db/transactions/0-0.txn/node._t.0
    A    /tmp/test/db/transactions/0-0.txn/node._5.0
    A    /tmp/test/db/transactions/0-0.txn/node._v.0
    A    /tmp/test/db/transactions/0-0.txn/node._w.0
    A    /tmp/test/db/transactions/0-0.txn/node._7.0
    A    /tmp/test/db/transactions/0-0.txn/node._y.0
    A    /tmp/test/db/transactions/0-0.txn/node._9.0
    A    /tmp/test/db/transactions/0-0.txn/props
    A    /tmp/test/db/transactions/0-0.txn/node._m.0.children
    A    /tmp/test/db/transactions/0-0.txn/node._o.0.children
    A    /tmp/test/db/transactions/0-0.txn/changes
    A    /tmp/test/db/transactions/0-0.txn/node.0.0.children
    A    /tmp/test/db/transactions/0-0.txn/node._w.0.children
    A    /tmp/test/db/txn-current
    A    /tmp/test/db/txn-protorevs
    A    /tmp/test/db/txn-protorevs/0-0.rev
    A    /tmp/test/db/txn-protorevs/0-0.rev-lock
    A    /tmp/test/db/rep-cache.db
    A    /tmp/test/format
    A    /tmp/test/README.txt
    A    /tmp/test/locks
    A    /tmp/test/locks/db.lock
    A    /tmp/test/locks/db-logs.lock
    A    /tmp/test/1.txt
    Checked out revision 2.
可以看到1.txt文件已经提交到svn仓库;


修改文件再次提交
echo "Hello world" >>1.txt


# salt operation svn.commit / /data/svndata/ '1.txt' mysql kbson kbsonlong
operation:
    Sending        data/svndata/1.txt
    Transmitting file data .
    Committed revision 3.
版本号改变为3


客户端更新/tmp/test,可以看到1.txt文件修改内容提交成功

# salt operation svn.update / /tmp/test/ mysql kbson kbsonlong
operation:
    U    /tmp/test/1.txt
    Updated to revision 3.
[root@operation ~]# cat /tmp/test/1.txt 
Hello world!
[root@operation ~]# 



客户端导出指定版本

# salt operation svn.export /  svn://192.168.62.110 /tmp/export/ mysql kbson kbsonlong 1
operation:
    A    /tmp/export
    A    /tmp/export/hooks
    A    /tmp/export/hooks/pre-revprop-change.tmpl
    A    /tmp/export/hooks/post-commit.tmpl
    A    /tmp/export/hooks/post-lock.tmpl
    A    /tmp/export/hooks/pre-commit.tmpl
    A    /tmp/export/hooks/pre-lock.tmpl
    A    /tmp/export/hooks/post-unlock.tmpl
    A    /tmp/export/hooks/pre-unlock.tmpl
    A    /tmp/export/hooks/post-revprop-change.tmpl
    A    /tmp/export/hooks/start-commit.tmpl
    A    /tmp/export/conf
    A    /tmp/export/conf/svnserve.conf
    A    /tmp/export/conf/passwd
    A    /tmp/export/conf/authz
    A    /tmp/export/db
    A    /tmp/export/db/revs
    A    /tmp/export/db/revs/0
    A    /tmp/export/db/revs/0/0
    A    /tmp/export/db/txn-current-lock
    A    /tmp/export/db/revprops
    A    /tmp/export/db/revprops/0
    A    /tmp/export/db/revprops/0/0
    A    /tmp/export/db/write-lock
    A    /tmp/export/db/current
    A    /tmp/export/db/fsfs.conf
    A    /tmp/export/db/min-unpacked-rev
    A    /tmp/export/db/uuid
    A    /tmp/export/db/fs-type
    A    /tmp/export/db/format
    A    /tmp/export/db/transactions
    A    /tmp/export/db/transactions/0-0.txn
    A    /tmp/export/db/transactions/0-0.txn/node._1b.0
    A    /tmp/export/db/transactions/0-0.txn/node._1d.0
    A    /tmp/export/db/transactions/0-0.txn/node._1e.0
    A    /tmp/export/db/transactions/0-0.txn/next-ids
    A    /tmp/export/db/transactions/0-0.txn/node._b.0
    A    /tmp/export/db/transactions/0-0.txn/node._11.0
    A    /tmp/export/db/transactions/0-0.txn/node._l.0.children
    A    /tmp/export/db/transactions/0-0.txn/node._d.0
    A    /tmp/export/db/transactions/0-0.txn/node._13.0
    A    /tmp/export/db/transactions/0-0.txn/node._f.0
    A    /tmp/export/db/transactions/0-0.txn/node._15.0
    A    /tmp/export/db/transactions/0-0.txn/node._0.0.children
    A    /tmp/export/db/transactions/0-0.txn/node._h.0
    A    /tmp/export/db/transactions/0-0.txn/node._17.0
    A    /tmp/export/db/transactions/0-0.txn/node._j.0
    A    /tmp/export/db/transactions/0-0.txn/node._19.0
    A    /tmp/export/db/transactions/0-0.txn/node._1d.0.children
    A    /tmp/export/db/transactions/0-0.txn/node._l.0
    A    /tmp/export/db/transactions/0-0.txn/node._v.0.children
    A    /tmp/export/db/transactions/0-0.txn/node._m.0
    A    /tmp/export/db/transactions/0-0.txn/node._o.0
    A    /tmp/export/db/transactions/0-0.txn/node._0.0
    A    /tmp/export/db/transactions/0-0.txn/node.0.0
    A    /tmp/export/db/transactions/0-0.txn/node._q.0
    A    /tmp/export/db/transactions/0-0.txn/node._2.0
    A    /tmp/export/db/transactions/0-0.txn/node._t.0
    A    /tmp/export/db/transactions/0-0.txn/node._5.0
    A    /tmp/export/db/transactions/0-0.txn/node._v.0
    A    /tmp/export/db/transactions/0-0.txn/node._w.0
    A    /tmp/export/db/transactions/0-0.txn/node._7.0
    A    /tmp/export/db/transactions/0-0.txn/node._y.0
    A    /tmp/export/db/transactions/0-0.txn/node._9.0
    A    /tmp/export/db/transactions/0-0.txn/props
    A    /tmp/export/db/transactions/0-0.txn/node._m.0.children
    A    /tmp/export/db/transactions/0-0.txn/node._o.0.children
    A    /tmp/export/db/transactions/0-0.txn/changes
    A    /tmp/export/db/transactions/0-0.txn/node.0.0.children
    A    /tmp/export/db/transactions/0-0.txn/node._w.0.children
    A    /tmp/export/db/txn-current
    A    /tmp/export/db/txn-protorevs
    A    /tmp/export/db/txn-protorevs/0-0.rev
    A    /tmp/export/db/txn-protorevs/0-0.rev-lock
    A    /tmp/export/db/rep-cache.db
    A    /tmp/export/format
    A    /tmp/export/README.txt
    A    /tmp/export/locks
    A    /tmp/export/locks/db.lock
    A    /tmp/export/locks/db-logs.lock
    Exported revision 1.
可以看到导出版本为 1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值