I am trying to learn salt, and I want to use to to se advanced settings on ESXi hosts using the "salt-ext-modules-vmware" modules.
I have the following sls file:
{% for host in salt['vmware_esxi.list_hosts']() %}
{% if salt['vmware_esxi.get_advanced_config']('host_name={{ host }}','config_name=Net.BlockGuestBPDU' == 0) %}
set_advanced_option_{{host}}:
module.run:
- name: vmware_esxi.set_advanced_config
- host_name: {{ host }}
- config_name: Net.BlockGuestBPDU
- config_value: 1
{% endif %}
{% endfor %}
If I run the command to get a setting if work like it should.
Command: salt 'proxy-minion' vmware_esxi.get_advanced_config host_name=hostname.domain.com config_name=Net.BlockGuestBPDU
And if I skip the if part of the sls file it also works, but it will always set the values even when they are already set, so I decided to implement a if sentence to only set the value if it is not already correct.
But when I run the command to check the values I get an error, that I cannot figure out how to get rid of. Any help will be appreciated.
Command: salt 'proxy-minion' state.apply
Error:
proxy-minion:
Data failed to compile:
----------
Rendering SLS 'base:all_vmhosts_advanced_settings' failed: Problem running salt function in Jinja template: Datacenter 'host_name={{ host }}' was not found; line 2
---
{% for host in salt['vmware_esxi.list_hosts']() %}
{% if salt['vmware_esxi.get_advanced_config']('host_name={{ host }}','config_name=Net.BlockGuestBPDU' == 0) %} <======================
set_advanced_option_{{host}}:
module.run:
- name: vmware_esxi.set_advanced_config
- host_name: {{ host }}
- config_name: Net.BlockGuestBPDU
[...]
---
{{ }}expressions do not work when you're already in a Jinja context. Use the variable directly.Argument keywords are not string values.
You want the test to operate on the function result, not one of its arguments.
Alternatively, instead of using Jinja, you can use an
unlessargument.