Search code examples
salt-project

saltstack template with grains - bad replacement


i have created a saltstack template file where i want to replace a variable with the servers ipv4 address:

in my test.template file i have:

Address {{ grains['fqdn_ip4'] }}

in my init.sls i have:

/opt/test/test.conf:
  file.managed:
    - source: salt://test/test.template
    - template: jinja
    - user: root
    - group: root
    - mode: 0644

so the problem is, that the variable is replaced with the correct ip address but not in the correct format:

Address ['111.111.111.111']

instead of:

Address 111.111.111.111

so my question: how can i remove the [' and '] form the replacement?


Solution

  • Solution:

    Address {{ grains['fqdn_ip4'][0] }}
    

    Result:

    Address 111.111.111.111