首页 文章

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

提问于
浏览
1

我需要使用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

    这看起来像是盐中的一个错误,那里的名单中的谷物没有运到小兵身上,你能试试这个PR吗?

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

  • 3

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

相关问题