【问题标题】:salt sls to use dnsutil.hosts_append not working使用 dnsutil.hosts_append 的盐 sls 不起作用
【发布时间】:2016-07-12 17:53:31
【问题描述】:

我需要从支柱文件中读取主机条目并相应地更新 /etc/hosts 文件

这是我用来更新 /etc/hosts 文件的简单 sls 文件。

#/srv/salt/splunk_dep/hosts.sls

dnsutil:
  dnsutil.hosts-append:
    - hostsfile: '/etc/hosts'
    - ip_addr: '10.10.10.10'
    - entries: 'hostname'

当我执行 sls 文件时 salt Minion-name state.apply splunk_dep/hosts

出现以下错误

      ID: dnsutil
Function: dnsutil.hosts-append
  Result: False
 Comment: State 'dnsutil.hosts-append' was not found in SLS 'splunk_dep/hosts'
          Reason: 'dnsutil.hosts-append' is not available.
 Started:
Duration:
 Changes:

如果我通过命令行执行它的工作正常

salt 'DS-110' dnsutil.hosts_append /etc/hosts 10.10.10.10 主机名

我需要通过 sls 文件更新 /etc/hosts 文件。有人可以帮我解决这个问题吗?

我使用的是盐版本:salt 2015.8.3 (Beryllium)

【问题讨论】:

  • 您好 Bala,既然您确认 ahus1 答案有效,请接受它。

标签: salt


【解决方案1】:

dnsutil 是 Salt 模块,而不是 Salt 状态。因此,它可以从命令行使用,但不能直接通过 SLS 状态文件。

要从状态文件运行模块,您需要module.run。请注意,在这种情况下,您需要在 hosts_append 中添加下划线,而不是连字符。

dnsutil:
  module.run:
    - name: dnsutil.hosts_append
    - hostsfile: '/etc/hosts'
    - ip_addr: '10.10.10.10'
    - entries: 'hostname'

模块的一些注意事项:即使它们不会更改您的系统,它们也会在您的盐调用摘要中报告为“已更改”。请考虑使用file.blockreplace 来管理主机文件以避免这种情况。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-04
    • 2016-03-15
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-18
    • 1970-01-01
    相关资源
    最近更新 更多