salt 一些state模块函数的使用方法记录

file模块

file.managed  下发文件

/tmp/test.txt:  ##执行ID
  file.managed:  ##使用的模块函数
    - name: /tmp/bbb.txt  ##目标,如果不写,会取ID做目标的值
    - source: salt://file/test.txt  ##源文件,这里用的是salt的file_roots目录
    - user: root  ##拥有者
    - group: root  ##拥有组
    - mode: 666  ##权限位

file.directory   建立目录

/home/cong/test:
  file.directory:
    - user: cong
    - group: cong
    - mode: 755
    - makedirs: True

file.symlink  建立软连接

/tmp/aaa.txt
  file.symlink:
    - target: /etc/passwd

file.recurse  下发整个目录

/tmp/test_dir:
  file.rescurse:
    - source: salt//file/zabbix
    - include_empty: True

pkg模块

pkg.installed 软件安装

soft_install:
  pkg.installed:
    - name: httpd

#可以指定版本或版本范围

soft_install:
  pkg.installed:
    - pkgs:
      - httpd: 2.4
      - php
      - mysql-server: '>= 5.6'

#安装指导来源

soft_install:
  pkg.installed:
    - pkgs:
      - httpd: salt://file/httpd/httpd.rpm
      - mysql-server: http://www.mysql.com/path/mysql-server.rpm
      - php: ftp://path/php.rpm
      - foo: /usr/local/src/foo.rpm

指定安装最新版的软件

[root@cong-33 test]# cat install.sls 
mypkgs:
  pkg.latest:
    - pkgs:
      - httpd
      - vim-enhanced
[root@cong-33 test]#

service 

redis:
  service.running:
    - enable: True
    - reload: True
    - watch:
      - pkg: redis

cron

date >/tmp/test.txt:
  cron.present:
    - user: root
    - minute: '*/5'

user模块

adduser:
  user.present:
    - name: cong
    - fullname: lycong
    - shell: /bin/bash
    - home: /home/cong
    - uid: 4000
    - gid: 4000
    - groups:
      - cong
      - root
      - games
原文地址:https://www.cnblogs.com/LYCong/p/7988164.html