Well, In this case, I have a set of services, each of which needs to have some operations applied to them (the same operations across all services). The use case really is what you see in the abstract example; there are times when some of the services have not been enabled, and if they are enabled, I need to perform the task on them, if not, I don't. I've already got the service operations abstracted out to an ansible task, so instead of dynamically altering the list, I can simply "include" the task again if the service is enabled. Updating a list and using with_items one time simply felt much cleaner... if it could have been done.
On Saturday, December 14, 2013 7:20:15 AM UTC-8, Michael DeHaan wrote: > > There's no way to dynamically append to a list presently. > > Since you've shared an abstract example, it might be a good idea to > explain the use case and we can share some other ways to model it? > > > > > On Fri, Dec 13, 2013 at 11:38 PM, Ross Becker <[email protected]<javascript:> > > wrote: > >> So, I'm looking for a way to add items to a list conditionally. The >> point of the list is to be provided for a with_items clause. I know I can >> evaluate python in jinja expressions, but it seems that those changes may >> be localized to the expression where they are evaluated. >> >> Here's a general idea of what I'm attempting to do. I have tested this >> playbook, and the output at the end is "foo", "bar", "baz", with "harpo" >> and "groucho" nowhere to be found, and yes, I've verified that >> enable_harpo and enable_groucho evaluate to true. >> =================== >> - hosts: configurator >> user: root >> gather_facts: False >> >> vars: >> svc_list: [ "foo", "bar", "baz" ] >> >> tasks: >> - name: checkharpo >> debug: msg="Foo more {{ svc_list.append('harpo') }}" >> when: enable_harpo >> >> - name: checkgroucho >> debug: msg="Foo more {{ svc_list.append('groucho') }}" >> when: enable_groucho >> >> - name: listme >> debug: msg="Message for service $item" >> with_items: svc_list >> ================================== >> >> >> -- >> 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 [email protected] <javascript:>. >> To post to this group, send email to [email protected]<javascript:> >> . >> For more options, visit https://groups.google.com/groups/opt_out. >> > > > > -- > Michael DeHaan <[email protected] <javascript:>> > CTO, AnsibleWorks, Inc. > http://www.ansibleworks.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 [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
