In a task, I am trying to figure out how I can loop over the items of a
list that is defined as a host variable for each host in a specific
group.
On Monday, April 28, 2014 10:35:15 AM UTC-7, Ernest0x wrote:In a task, I am trying to figure out how I can loop over the items of a
list that is defined as a host variable for each host in a specific
group.
I'm not sure what you are trying to do here so I can't offer too much advice. It also depends on what you are planning on doing with those variables I suspect.
You might want to look at this http://docs.ansible.com/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts
Normally I only need to iterate over a list of variables for the current host. But there are examples of accessing variables for groups of hosts on that page.
--Adam
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/26c8f5ac-db7c-4171-8c7c-0f9605a212d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/535EADE1.40309%40yahoo.gr.
"In a task, I am trying to figure out how I can loop over the items of a
list that is defined as a host variable for each host in a specific
group."
If the variable is "listvar"
with_items: listvar
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgwx9Ne97ckJOmvJQb4rgCPQX3agQjC2AuQXdeJQAdwJ%2BQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/535F5E36.4020200%40yahoo.gr.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/535F5E36.4020200%40yahoo.gr.
" So, I am considering to teach "with_nested" lookup to understand expressions with "item[0]" in the second term as expressions that should be reevaluated to a list for each item in the first term"
Ansible is not meant to be a programming language, when syntax gets so complicated that it appears to become one, I feel a playbook is strongly going in the wrong direction.
It is usually useful to step back and think about the underlying use case, and there's a clean way to model it without trying to "program in YAML"
I find this problem mostly comes from users coming from Chef, but not always.
So, as such, I feel this is a bit of a slippery slope. Rather than initially discussing the patch, let's understand what's the real world thing you are trying to configure, at a high level, and we can likely offer up some suggestions.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgxb6f8UPCD1tFf7wDHN_yCDfLWGOwsLfZ%2BsJ2btTVFjSA%40mail.gmail.com.
On Apr 29, 2014 7:03 AM, "'Petros Moisiadis' via Ansible Project" <ansible...@googlegroups.com> wrote:
>
>
> My use case: I want a task to run for all network interfaces for each host in a specific group. Each host has a "network_interfaces" list variable.
> I cannot be convinced that this is something that one should not be able to describe in a playbook.
>
That is not really a use case but a description. What are you trying to do with these network interfaces? Add them to a list? Build a dhcp configuration file?
Adam
Adam
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAGvoTo3drZm_Xq6%3Dnk44OEXj7G5%2Bg2u2i3txhMd-1e10b%2BhkaA%40mail.gmail.com.
Ansible loops through your groups and hosts and executes tasks against them. Therefore there is no need to manage an outer loop, Ansible does it for you and is central to how Ansible works.
"Thus, have the task run for 5 times: for item1, item2, item3, item4 and item5."
This inner loop is as simple as with_items as already suggested.
Does that help or did I confuse you more?
Actually I think that he is trying to configure something for a group of hosts rather than configure something on a group of hosts. For example lets assume that you have a DHCP server and you want to configure static ip addresses for each of your servers. You could run through each host grabbing all of the MAC addresses and IP addresses from each server but you would only be configuring them on one server.
I am not saying that that is the case and I am curious as to what the case is, but that is an example of what I think we are being asked for here.
--
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/RQYOP_yR5Yk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/bb796dfb-cda9-49d4-97e7-a9c3def2febd%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAGvoTo0VHvmLmnPVqftWHrHVbuFXhD6b4soGyUf3mkz_uEXRfA%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAGvoTo0VHvmLmnPVqftWHrHVbuFXhD6b4soGyUf3mkz_uEXRfA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/53679218.5070104%40yahoo.gr.