盐更改/etc/hosts,但仍然缓存旧的? [英] Salt changing /etc/hosts, but still caching old one?

查看:70
本文介绍了盐更改/etc/hosts,但仍然缓存旧的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

salt 缓存/etc/hosts 吗?我的情况是更改/etc/hosts 使 FQDN 指向外部 IP 地址而不是 127.0.0.1

Is salt caching /etc/hosts? I'm in a situation where I change /etc/hosts such that the FQDN points to the external IP address instead of 127.0.0.1

问题是在第一次运行时,fqdn_ipv4 保持为 127.0.0.1,我需要重新运行 salt '*' state.highstate 以获得正确的值.这会导致诸如这个之类的问题,这花费了我很多时间.

The problem is that in the first run, the fqdn_ipv4 stays 127.0.0.1 and I need to rerun salt '*' state.highstate to get the right values. This leads to problems like this, which cost me a lot of time.

salt 是否在执行前渲染所有内容(或缓存 DNS)?我该如何解决这个问题?

Is salt rendering everything before execution (or caches DNS)? How do I address this problem?

状态文件如下所示:

127.0.0.1:
  host.absent:
    - name:     {{ nodename }}
    - ip:          127.0.0.1

127.0.1.1:
  host.absent:
    - name:     {{ nodename }}
    - ip:          127.0.1.1

{% for minion, items in salt['mine.get']('environment:' + environment, 'grains.item', expr_form='grain')|dictsort %}

{{ minion }}:
  host.present:
    - ip:       {{ items['ip_addr'] }}
    - names:
      - {{ minion }}
      - {{ minion.split('.')[0] }}

{% endfor %}

使用 IP 的代码如下所示:

And the code that uses the IP looks like this:

{% set ipv4     = salt['config.get']('fqdn_ip4') -%}

# IP Address that Agent should listen on
listening_ip={{ ipv4[0] }}

推荐答案

Salt 正在缓存谷物的值.因此 salt['config.get']('fqdn_ip4') 将从脚本的开头检索值.

Salt is caching the values of grains. Therfore the salt['config.get']('fqdn_ip4') will retrieve the value from the beginning of the script.

在您的状态文件中使用以下内容来刷新谷物信息:

Use the following in your state file to refresh the grain information:

refreshgrains:
  module.run:
    - name: saltutil.sync_grains

Salt 将在执行之前呈现状态,因此您可能无法在状态文件本身中使用任何新的谷物信息.

Salt will render the state before executing it, so you might not be able to use any new grain information inside the state file itself.

但是您将能够在 Jinja 模板中为文件使用新的粒度值.我假设第二个代码片段来自 Salt 的 file.managed 使用的模板,所以你在这里应该是安全的.

But you will be able to use the new grain values in Jinja templates for files. I assume the second code snippet is from a template that is used by Salt's file.managed, so you should be safe here.

这篇关于盐更改/etc/hosts,但仍然缓存旧的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆