Мой словарь выглядит так:
seed_job_additional_git_scms:
TestUrl:
credentials: "TestCredentials"
branch: "testBranch"
directory: "testDirectory"
TestUrl2:
credentials: "TestCredentials2"
branch: "testBranch2"
directory: "testDirectory2"
Теперь итерируя в обычном режиме с помощью модуля ansible debug
, я получаю именно то, что хочу:
- name: Print
debug:
msg: "Repo {{ item.key }} has credentials {{ item.value.credentials }}. Its used branch {{ item.value.branch }} and gets saved to directory {{ item.value.branch }}"
loop: "{{ lookup('dict', seed_job_additional_git_scms) }}"
TASK [copy : Print ] ************************************************************************************************************************************************************************************************************
ok: [localhost] => (item={'key': u'TestUrl', 'value': {u'directory': u'testDirectory', u'credentials': u'TestCredentials', u'branch': u'testBranch'}}) => {
"msg": "Repo TestUrl has credentials TestCredentials. Its used branch testBranch and gets saved to directory testBranch"
}
ok: [localhost] => (item={'key': u'TestUrl2', 'value': {u'directory': u'testDirectory2', u'credentials': u'TestCredentials2', u'branch': u'testBranch2'}}) => {
"msg": "Repo TestUrl2 has credentials TestCredentials2. Its used branch testBranch2 and gets saved to directory testBranch2"
Теперь я пытаюсь сделать то же самое, покупая в файле шаблона, используя Jinja.
То, что я пробовал, это:
{% for dict_item in seed_job_additional_git_scms %}
{% for key, value in dict_item.items() %}
<h1>URL: {{key}}</h1>
<h2>Credentials: {{ value.credentials }}</h2>
<h2>Branch: {{ value.branch }}</h2>
<h2>Direcotry: {{ value.directory }}</h2>
{% endfor %}
{% endfor %}
Но я получаю ошибку:
TASK [copy : Template required files.] *******************************************************************************************************************************************************************************************************
failed: [localhost] (item={u'dest': u'/tmp/config.xml', u'src': u'job.j2'}) => {"changed": false, "item": {"dest": "/tmp/config.xml", "src": "job.j2"}, "msg": "AnsibleUndefinedVariable: 'ansible.parsing.yaml.objects.AnsibleUnicode object' has no attribute 'items'"}
Что я здесь не так делаю?