盐sls使用dnsutil.hosts_append无法正常工作

时间:2016-07-07 15:53:06

标签: salt

我需要从柱文件中读取主机条目并相应地更新/ 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:

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

盐' DS-110' dnsutil.hosts_append / etc / hosts 10.10.10.10 hostname

我需要通过sls文件更新/ etc / hosts文件。有人可以帮我这个。

我正在使用盐版本:盐2015.8.3(Beryllium)

1 个答案:

答案 0 :(得分:0)

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来管理主机文件,以避免这种情况。