Dynamic Group Var Name

50 views
Skip to first unread message

Chanaka Samarajeewa

unread,
Apr 26, 2016, 5:22:28 PM4/26/16
to Ansible Project
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

Johannes Kastl

unread,
May 3, 2016, 3:21:27 AM5/3/16
to ansible...@googlegroups.com
On 26.04.16 23:22 Chanaka Samarajeewa wrote:

> with_dict: "rdsusers{{ env }}"
>
> FAILED! => {"failed": true, "msg": "ERROR! with_dict expects a dict"}

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

Does with_items work in your case?

Johannes

signature.asc

Brian Coca

unread,
May 3, 2016, 2:29:02 PM5/3/16
to ansible...@googlegroups.com
I think you want this:

 with_dict: "{{hostvars[inventory_hostname]['rdsusers' + env]}}"


----------
Brian Coca

Chanaka Samarajeewa

unread,
Dec 16, 2016, 1:43:22 PM12/16/16
to ansible...@googlegroups.com
Hello Brian,

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


Thanks
Chanaka

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/uQhZ6pXchWo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CACVha7f41TzvQcvwSjR5bQrJG40jjkSjrMdF-Uexf4in3--q2A%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages