saltstack-7 pillar组件

1、定义pillar

编辑/srv/pillar/top.sls

base:
  '*':
    - apache

二级配置有两种方式:

  1. 直接新建apache.sls
  2. 新建文件夹,在文件夹里面添加init.sls

新建apache文件夹,在里面新建文件init.sls

pkgs:
{% if grains['os_family'] == 'Debian' %}
  apache: apache2
{% elif grains['os_family'] == 'RedHat' %}
  apache: httpd
{% elif grains['os'] == 'Arch' %}
  apache: apache
{% endif %}

根据操作心系统参数,获取到相应的安装包名称

# 同步pillar参数到客户机
salt '*' saltutil.refresh_pillar

2、利用pillar定义的参数,进行apache的安装

salt默认的入口为:/srv/salt/top.sls

base:
  '*':
    - apache
apache:
  pkg:
    - installed
    - name: {{pillar['pkgs']['apache']}}

  service.running:
    - name: {{pillar['pkgs']['apache']}}
    - require:
      - pkg: {{pillar['pkgs']['apache']}}
  • 利用pillar参数,配置安装包名字;
  • require参数,配置确保在apache安装成功后,才进行启动

 3、sate执行

salt '*' state.highstate

下面两图为已经安装和未按照httpd的执行结果对比:

 

原文地址:https://www.cnblogs.com/zxw-xxcsl/p/11477245.html