http://blog.kukafei520.net/html/2014/942.html
/tmp/aaa.txt: file.managed
/tmp/salt_test: file.directory: - user: chen - group: chen - mode: 755 - makedirs: True
查询history 添加时间显示出来:
/etc/profile: file.append: - text: - export HISTTIMEFORMAT="%F %T `whoami` "
====================原文被谷歌和谐,备份下==================================================================
最近一直在使用saltstack,每次使用到file模块都还需要去查文档,今天在此记录,以便以后使用
文档:http://docs.saltstack.com/ref/states/all/salt.states.file.html
本文中用的top.sls
/srv/salt/top.sls test: 'minion1': - file
创建
1. 空文件
/srv/salt/test/file.sls /tmp/a.txt: file.managed
2. 根据模板文件生成文件
/srv/salt/test/file.sls /tmp/a.txt: file.managed: - source: salt://files/a.txt /srv/salt/test/files/a.txt just a test
3. 根据变量生成文件
/srv/salt/test/file.sls /tmp/a.txt: file.managed: - source: salt://files/a.txt - template: jinja /srv/salt/test/files/a.txt {{ pillar['os'] }}
4. 创建多个文件
/srv/salt/test/file.sls {% set create_files = ['/tmp/a', '/tmp/b', '/tmp/c'] %} {% for eachfile in create_files %} {{eachfile}}: file.managed: - source: salt://files/tmp - template: jinja {% endfor %}
删除
/srv/salt/test/file.sls /tmp/a.txt: file.absent
添加内容
/srv/salt/test/file.sls /tmp/a.txt: file.append: - text: - 'this is append line1' - 'this is append line2'
重命名
/srv/salt/test/file.sls /tmp/new: file.rename: - source: /tmp/old
目录
/srv/salt/test/file.sls /var/log/httpd: file.directory: - user: root - group: root - dir_mode: 755 - file_mode: 644 - recurse: - user - group - mode sed /srv/salt/test/file.sls /etc/yum.repos.d/epel.repo: file.sed: - before: 1 - after: 0 - limit: ^enabled=
软连
/srv/salt/test/file.sls /tmp/new: file.symlink: - target: /tmp/old
是否存在
/srv/salt/test/file.sls /tmp/new: file.exists
dd