python - AttributeError when accessing groups in ansible jinja template -


i running ansible playbook following inventory structure:

[appservers] xy.example.com  [db_servers] abc.example.com 

in task of role, template command executed jinja templace having following code:

{% host in groups["appservers"] %} print host: {{ host }} {% endfor %} 

however, execution of task fails message:

fatal: [xy.example.com]: failed! => {"msg": "undefinederror: 'list object' has no attribute 'appservers'", "failed": true, "changed": false} 

from examples found, should possible, since groups["appservers"] should dict, can used iterated on in template explained here

do know wrong code or how can debug error?

if change template code

{% host in groups %} print host: {{ host }} {% endfor %} 

the resulting file contains

print host: appservers print host: print host: db_servers 

this question not contain enough information , should edited or deleted cannot reproduced simple amount of information.

it possible group missing during run of task trying render list.

as suggested in comment should try debug variable task before trying render template

- debug: msg: '{{ groups }}'

ansible capable of dynamically allocating hosts groups, therefore 1 intuition order of inventory creation not complete, or perhaps there bug in dynamic inventory script, or other reason group missing.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -