使用Jinja模板中的Salt-ssh访问谷物

时间:2017-05-15 07:32:39

标签: salt salt-stack

我需要使用Jinja模板在我的配置文件中访问自定义谷物。这是我的档案。

[root@localhost salt]# cat my_config.conf
{{ grains['ip'] }}

[root@localhost salt]# cat test_jinja.sls
/root/my_config.conf:
  file.managed:
    - source: salt://my_config.conf
    - user: root
    - group: root
    - mode: '0644'
    - makedirs: True
    - force: True
    - template: jinja

[root@localhost salt]# salt-ssh 'my-ip' state.sls test_jinja
10.225.253.134:
----------
          ID: /root/test
    Function: file.managed
      Result: False
     Comment: Unable to manage file: Jinja variable 'dict object' has no attribute 'ip'
     Started: 12:57:49.301697
    Duration: 33.039 ms
     Changes:

[root@localhost salt]# cat /etc/salt/roster
my-ip:       # The id to reference the target system with
    host: xx.xx.xx.133       # The IP address or DNS name of the remote host
    user: root        # The user to log in as
    passwd: teledna      # The password to log in with
    grains:
      ip: 'xx.xx.xx.133'

如何使用salt-ssh ???

访问配置文件中的grain

2 个答案:

答案 0 :(得分:3)

这看起来像是盐中的一个小虫,来自名册的谷物没有被运到小兵身上,你可以试试这个PR吗?

https://github.com/saltstack/salt/pull/40775

答案 1 :(得分:0)

原因是没有' ip'粮食。 要列出所有谷物,请使用salt '*' grains.items