saltstack的探索-使用模版分发一个配置文件到minion

配置pillar:

[[email protected] salt]# cat /srv/pillar/top.sls    
base:
    ‘*‘:
        - data
[[email protected] salt]# cat /srv/pillar/data.sls 
a: 1
b: 2
c:
    c1: 1001
    c2: 2001
    c3: 3001

使用yaml模版来创建一个配置文件:

[[email protected] salt]# cat /srv/salt/top.sls 
base:
    ‘*‘:
        - servers
    ‘test230‘:
        - appconfig

模版文件路径:
[[email protected] salt]# cat /srv/salt/appconfig.sls 
/tmp/appconfig.conf:
    file.managed:
        - source: salt://files/appconfig.conf.yaml
        - template: jinja

模版文件内容:
[[email protected] salt]# cat files/appconfig.conf.yaml 
test hostname:  {{ grains[‘id‘] }}
get the value of a: {{ pillar[‘a‘] }}
get the value of b: {{ pillar[‘b‘] }}

{% if ‘c‘ in pillar %}
get the value of c:
{% for k,v in pillar.get(‘c‘, {}).items() %}
    {{ k }}: {{ v }}
{% endfor %}
{% endif %}

执行:
[[email protected] salt]# salt ‘test230‘ state.highstate
test230:
----------
          ID: dnsmasq
    Function: pkg.installed
      Result: True
     Comment: Package dnsmasq is already installed.
     Started: 15:44:55.301089
    Duration: 1084.57 ms
     Changes:   
----------
          ID: /tmp/appconfig.conf
    Function: file.managed
      Result: True
     Comment: File /tmp/appconfig.conf updated
     Started: 15:44:56.385793
    Duration: 12.932 ms
     Changes:   
              ----------
              diff:
                  New file
              mode:
                  0644

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

查看生成的squid.conf文件内容:
[[email protected] monitor_agent]# cat /tmp/appconfig.conf 
test hostname:  test230
get the value of a: 1
get the value of b: 2

get the value of c:

    c3: 3001

    c2: 2001

    c1: 1001
时间: 2024-08-30 04:39:08

saltstack的探索-使用模版分发一个配置文件到minion的相关文章

SaltStack远程分发hosts配置文件

############################################################** SaltStack远程分发hosts配置文件############################################################ [[email protected] dns]# mkdir -p /srv/salt/hosts/files [[email protected] dns]# cp /etc/hosts /srv/salt

SaltStack远程分发DNS配置文件

############################################################** SaltStack远程分发DNS配置文件############################################################ [[email protected] srv]# mkdir -p /srv/salt/dns/files [[email protected] srv]# cp /etc/resolv.conf /srv/sa

看看一个配置文件,了解ESB的编程模型

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/

vue打包之后生成一个配置文件修改接口

前言: 我们的vue代码打包上传到服务器之后, 要是数据接口 以后换了域名什么的,是不是需要重新去vue文件里修改接口. 能不能生成一个配置文件,里面可以配置域名或其它什么字段之类的,这样以后换了域名,只需打开记事本 修改一下域名即可. 教程: 第一步:安装generate-asset-webpack-plugin插件 npm install --save-dev generate-asset-webpack-plugin 第二步:配置webpack.prod.conf.js文件 //让打包的时

saltstack的探索-给zabbix客户端推送一个自定义的配置文件

目的:使用zabbix监控指定的内容,例如某个进程是否存在,因此我们推送一个自定义的zabbix配置到指定的客户端,然后重启zabbix-agent服务. 目录和脚本: [[email protected] zabbix]# ls agent.sls  bin  conf  sbin  template.sls [[email protected] zabbix]# cat conf/myapp_process.conf  UserParameter=myapp.process.get[*], 

vue-cli的webpack模版,相关配置文件dev-server.js与webpack.config.js配置解析

1.下载vue-cli [html] view plain copy npm install vue-cli -g vue-cli的使用与详细介绍,可以到github上获取https://github.com/vuejs/vue-cli 2.安装webpack项目模版 [html] view plain copy vue init <template-name> <project-name> 比如: [html] view plain copy vue init webpack m

关于Vim的一个配置文件

昨天晚上+今天早上怒赶了一份关于Vim的自动化配置的Shell脚本,之前在github上见过一个这么一个类似的脚本项目,然后又见到同校的有一位师兄也写过这么一个类似的脚本文件,然后我也抽分跟着写一份属于自己的Vim的配置脚本文件,这一份文件的配置很大程度上参考了以上的两份配置文件,当然也加上了不少属于自己的配置,总的一句话来说综合了上述两份的优势,去掉不适合自己的一些配置,添加上适合自己配置的一个结合体. 配置文件如下:(名字保存为ourvim.sh) #!/bin/bash cd echo "

saltstack的探索-salt指定目标和分组

一.探讨一下,如何针对指定的minion id来执行 先了解官网文档的targeting这一节的内容: Targeting Salt allows for minions to be targeted based on a wide range of criteria. The default targeting system uses globular expressions to match minions, hence if there are minions named larry1, 

Python 读写一个配置文件的实例分解 (一)

给出的配置文件:configuration.cfg frontend testserver         servername 10.5.7.9          IP 10.5.7.9         port 8080  backend Oracle         servername 10.5.7.11 IP 10.5.7.11 weight 20 maxconn 2000         servername 10.5.7.12 IP 10.5.7.12 weight 30 maxc