salt pillar测试

使用salt pillar 通过pillar来参数化states
1.更改配置/etc/salt/master 配置,并重启salt-master:
pillar_roots:
  base:
    - /srv/pillar
2. /srv/pillar 目录结构
root@test04:/srv/pillar$ tree
.
├── test-web
│   └── init.sls
└── top.sls

1 directory, 2 files

root@test04:/srv/pillar$ more top.sls 
base:
  '*':
    - test-web

root@test04:/srv/pillar$ more test-web/init.sls 
test-web:
  con_file: ['application.properties',
              'memcached.properties',
              'log4j.xml']
查看pillar数据:
root@test04:/srv/pillar$ salt  'test01' pillar.data test-web
test01:
    ----------
    test-web:
        ----------
        con_file:
            - application.properties
            - memcached.properties
            - log4j.xml
3. 配置/srv/salt/ 下top.sls 文件
root@test04:/srv/salt$ ls
test.sls  top.sls
root@test04:/srv/salt$ more top.sls 
base:
  'test01':
    - test
root@test04:/srv/salt$ more test.sls 
{% for file in pillar['test-web']['con_file'] %}
{{ file }}:
  cmd.run:
    - names: 
      - cd /xxx/tomcat/webapps/test-web/WEB-INF/classes/ ; ls {{file}}
{% endfor %}

执行 root@test04:/srv/salt$ salt 'test01' state.highstate 
test01:
----------
          ID: application.properties
    Function: cmd.run
        Name: cd /xxx/tomcat/webapps/test-web/WEB-INF/classes/ ; ls application.properties
      Result: True
     Comment: Command "cd /xxx/tomcat/webapps/test-web/WEB-INF/classes/ ; ls application.properties" run
     Started: 10:44:33.554601
    Duration: 45.603 ms
     Changes:   
              ----------
              pid:
                  6060
              retcode:
                  0
              stderr:
                  
              stdout:
                  application.properties
----------
          ID: memcached.properties
    Function: cmd.run
        Name: cd /xxx/tomcat/webapps/test-web/WEB-INF/classes/ ; ls memcached.properties
      Result: True
     Comment: Command "cd /xxx/tomcat/webapps/test-web/WEB-INF/classes/ ; ls memcached.properties" run
     Started: 10:44:33.600894
    Duration: 37.785 ms
     Changes:   
              ----------
              pid:
                  6062
              retcode:
                  0
              stderr:
                  
              stdout:
                  memcached.properties
----------
          ID: log4j.xml
    Function: cmd.run
        Name: cd /xxx/tomcat/webapps/test-web/WEB-INF/classes/ ; ls log4j.xml
      Result: True
     Comment: Command "cd /xxx/tomcat/webapps/test-web/WEB-INF/classes/ ; ls log4j.xml" run
     Started: 10:44:33.639325
    Duration: 37.923 ms
     Changes:   
              ----------
              pid:
                  6064
              retcode:
                  0
              stderr:
                  
              stdout:
                  log4j.xml

Summary
------------
Succeeded: 3 (changed=3)
Failed:    0
------------
Total states run:     3


你可能感兴趣的:(salt pillar测试)