SaltStack - 托管文件每隔 运行 写入一次,如何仅在有更新时写入文件?
SaltStack - Managed file gets written on every run, how to only write the file if there are updates?
我在每个状态 运行 上写入我的托管文件时遇到了一些麻烦,即使文件中没有任何更新。奇怪的是,我似乎找不到任何关于通过 google 或盐文档阻止这种情况发生的信息。
我的状态分为 init.sls 部署包和 config.sls 配置包,默认和环境特定的配置值分为一个支柱。示例如下。
Config State Example:
{% from "amq/map.jinja" import amq with context %}
camelxml_conf:
file.managed:
- name: {{ amq.camelxml }}
- source: salt://amq/conf/camel.xml.tmpl
- template: jinja
- user: omapp
- group: omapp
- mkdirs: True
- recurse:
- user
- group
Pillar Example:
default_routes:
Route1:
from_uri: 'activemq:inputqueue1'
process_ref: 'myprocessor1'
to_uri: 'activemq:outputqueue1'
Route2:
from_uri: 'activemq:inputqueue2'
process_ref: 'myprocessor2'
to_uri: 'activemq:outputqueue2'
{% if 'qa' in grains['env'] %}
env_routes:
route1:
from_uri: 'activemq:inputqueue3'
process_ref: 'myprocessor3'
to_uri: 'activemq:outputqueue3'
{% endif %}
Camel.xml Template Example:
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<!-- routes common across all environments -->
{% for route, args in pillar.get('default_routes', {}).items() %}
<route>
<from uri="{{ args.from_uri }}"/>
<process ref="{{ args.process_ref }}"/>
<to uri="{{ args.to_uri }}"/>
</route>
{% endfor %}
<!-- routes unique to this environment -->
{% for env_route, args in pillar.get('env_routes', {}).items() %}
<route>
<from uri="{{ args.from_uri }}"/>
<process ref="{{ args.process_ref }}"/>
<to uri="{{ args.to_uri }}"/>
</route>
{% endfor %}
我在这里做错了什么吗?我不应该在我的支柱中动态设置值吗?我想这可能就是为什么在每个状态 运行 上写入一个新文件的原因,但我不确定。
如果您 运行 您的状态将 test=True 附加到命令,它将向您显示它将要进行的更改的差异。这可能会帮助您找出它认为有必要进行更改的原因
您可以使用 watch
或 onchange
必要条件,这有助于仅在有更改时应用更改。
我在每个状态 运行 上写入我的托管文件时遇到了一些麻烦,即使文件中没有任何更新。奇怪的是,我似乎找不到任何关于通过 google 或盐文档阻止这种情况发生的信息。
我的状态分为 init.sls 部署包和 config.sls 配置包,默认和环境特定的配置值分为一个支柱。示例如下。
Config State Example:
{% from "amq/map.jinja" import amq with context %}
camelxml_conf:
file.managed:
- name: {{ amq.camelxml }}
- source: salt://amq/conf/camel.xml.tmpl
- template: jinja
- user: omapp
- group: omapp
- mkdirs: True
- recurse:
- user
- group
Pillar Example:
default_routes:
Route1:
from_uri: 'activemq:inputqueue1'
process_ref: 'myprocessor1'
to_uri: 'activemq:outputqueue1'
Route2:
from_uri: 'activemq:inputqueue2'
process_ref: 'myprocessor2'
to_uri: 'activemq:outputqueue2'
{% if 'qa' in grains['env'] %}
env_routes:
route1:
from_uri: 'activemq:inputqueue3'
process_ref: 'myprocessor3'
to_uri: 'activemq:outputqueue3'
{% endif %}
Camel.xml Template Example:
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<!-- routes common across all environments -->
{% for route, args in pillar.get('default_routes', {}).items() %}
<route>
<from uri="{{ args.from_uri }}"/>
<process ref="{{ args.process_ref }}"/>
<to uri="{{ args.to_uri }}"/>
</route>
{% endfor %}
<!-- routes unique to this environment -->
{% for env_route, args in pillar.get('env_routes', {}).items() %}
<route>
<from uri="{{ args.from_uri }}"/>
<process ref="{{ args.process_ref }}"/>
<to uri="{{ args.to_uri }}"/>
</route>
{% endfor %}
我在这里做错了什么吗?我不应该在我的支柱中动态设置值吗?我想这可能就是为什么在每个状态 运行 上写入一个新文件的原因,但我不确定。
如果您 运行 您的状态将 test=True 附加到命令,它将向您显示它将要进行的更改的差异。这可能会帮助您找出它认为有必要进行更改的原因
您可以使用 watch
或 onchange
必要条件,这有助于仅在有更改时应用更改。