Reputation: 264
I am trying to read an array of dictionary present in my salt pillar file inside my state sls file, but unable to read.
root@xxxxxxx:/srv/salt# salt-master --version
salt-master 3003.3
I am having pillar file as below:
Pillar File:
common:
sysctl.net.core.netdev_max_backlog: 16384
sysctl.net.core.optmem_max: 25165824
sysctl.net.core.rmem_max: 33554432
sysctl.net.core.somaxconn: 16384
deploy2:
packages:
- repo_name: xxxxxxxx
tag: xxxxxx
path: /tmp/sp_repo_1
- repo_name: xxxxxx
tag: sxxxxxx
path: /tmp/sp_repo_2
My state file as below:
{% for package in salt.pillar.get('deploy2:packages') %}
print my data:
cmd.run:
- name: "echo {{ package.repo_name }}"
{% endfor %}
Error:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:
Data failed to compile:
----------
Rendering SLS 'base:test' failed: while constructing a mapping
in "<unicode string>", line 3, column 1
found conflicting ID 'print my data'
in "<unicode string>", line 9, column 1
Upvotes: 1
Views: 599
Reputation: 7340
The ID of the states being run in context of an execution should be unique.
As you are iterating over an array of dictionaries having two elements, it creates two state IDs as print my data
, which is not allowed. To avoid this, we need to use some element of the dict in the ID itself so that it is unique.
Example:
{% for package in salt.pillar.get('deploy2:packages') %}
print-my-{{ package.repo_name }}:
cmd.run:
- name: "echo {{ package.repo_name }}"
{% endfor %}
This will create 2 unique IDs - print-my-xxxxxxxx
and print-my-xxxxxx
. You could use package.tag
or any such key which has unique values.
Upvotes: 1