Dynamic Group Var Name

Hello,

How come I cannot do the following? I get the following error when I run the play. Is there a better way to do this? Please note the group vars file has been added to the main yml file as a reference.

  • mysql_user: login_host={{ inventory_hostname }} login_port={{ database_port }} login_user={{ database_admin }} login_password={{ database_admin_pass }} name={{ item.value.username }} password={{ item.value.password }} priv={{ item.value.privileges }} host=“%” state=present with_dict: “rdsusers{{ env }}”

FAILED! => {“failed”: true, “msg”: “ERROR! with_dict expects a dict”}

Thanks

Maybe because your rdsusers{{ env }} is a list and not a dict?

Does with_items work in your case?

Johannes

I think you want this:

with_dict: “{{hostvars[inventory_hostname][‘rdsusers’ + env]}}”

Hello Brian,

Can you please help me figure out how to iterate over this registered variable? Please see my question as follows:

https://groups.google.com/forum/#!searchin/ansible-project/iterate%7Csort:relevance/ansible-project/C9fSSQGq8pM/Pcjng6yeDAAJ

Thanks
Chanaka