/srv/salt/file/managed.sls
/tmp/hyxc: file.managed: - source: - salt://files/hyxc - salt://files/hwg - makedirs: True # - replace: False - user: root - group: root - mode: 644 - backup: minion - template: jinja执行如下命令完成源文件管理
salt '10.0.10.100' state.sls file.managed
若文件之前存在,且源文件相对有更改,则管理后在/var/cache/salt/minion/file_backup/可看见该文件的备份文件
/srv/salt/file/append.sls
/tmp/hyxc: file.append: - text: | hyxc
执行如下命令在文件末尾添加一行
salt '10.0.10.100' state.sls file.append
/srv/salt/file/recurse.sls
/tmp/hwg: file.recurse: - source: salt://files/hwg - user: nobody - group: nobody - file_mode: 644 - dir_mode: 755 - include_empty: Ture # - clean: Ture # - exclude_pat: E@(hh) # - include_pat: E@(ss)
执行如下命令完成文件递归管理
salt '10.0.10.100' state.sls file.recurse
/srv/salt/file/directory.sls
/tmp/hwg: file.directory: - user: root - group: root - dir_mode: 755 - file_mode: 644 - makedirs: True - recurse: - user - group - mode
执行如下命令即可创建目录
salt '10.0.10.100' state.sls file.directory
/srv/salt/file/absent.sls
/tmp/hwg:
file.absent:
- name: /tmp/hwg
执行如下命令删除文件
salt '10.0.10.100' state.sls file.absent
或在命令行执行如下
salt '*' file.remove /tmp/hyxc
/srv/salt/file/comment.sls
/tmp/hyxc: file.comment: - regex: ^text 2 - backup : .bak - char: #
命令行执行如下命令完成注释
salt '10.0.10.100' state.sls file.comment
/srv/salt/file/rename.sls
/tmp/jim:
file.rename:
- source: /tmp/hwg
命令行执行如下命令实现重命名
salt '10.0.10.100' state.sls file.rename
/srv/salt/file/replace.sls
/tmp/hyxc: file.replace: - pattern: | jim - repl: | hyxc
命令行执行如下命令进行替换
salt '10.0.10.100' state.sls file.replace
或命令行直接执行如下
salt '*' file.replace /path/to/file pattern='=' repl=':'
/srv/salt/file/exists.sls
/tmp/hyxc:
file.exists:
- name: /tmp/hyxc
命令行执行如下命令检查
salt '10.0.10.100' state.sls file.exists
或在命令行直接执行如下命令
salt '10.0.10.100' file.file_exists /etc/passwd
更改文件属主属组
salt '*' file.chown /etc/passwd root root
更改文件属组
salt '*' file.chgrp /etc/passwd root