Thanks vlado! What will happen if let’s say item2conf is not defined ? On Wed, 11 Dec 2019 at 9:47 PM, Vladimir Botka <[email protected]> wrote:
> Hi Rahul, > > On Wed, 11 Dec 2019 20:03:32 +0530 > Rahul Kumar <[email protected]> wrote: > > > Hi Ansible Gurus, > > How can I optimize below code ? below is the sufficient code to > understand > > the problem... > > > > - name: Application item1Conf provisioning > > include_tasks: resturlcall.yml > > with_items: > > - { name: '{{item1Conf}}', resource: 'item1' } > > when: item1Conf is defined > > > > - name: Application item2Conf provisioning > > include_tasks: resturlcall.yml > > with_items: > > - { name: '{{item2Conf}}', resource: 'item2' } > > when: item2Conf is defined > > > > - name: Application item3Conf provisioning > > include_tasks: resturlcall.yml > > with_items: > > - { name: '{{item3Conf}}', resource: 'item3' } > > when: item3Conf is defined > > Default filter is needed to loop all items in one task because *item* is > evaluated before *when*. Empty variable evaluates to False. For example > > - name: Application provisioning > include_tasks: resturlcall.yml > loop: > - {name: '{{ item1Conf|default() }}', resource: 'item1'} > - {name: '{{ item2Conf|default() }}', resource: 'item2'} > - {name: '{{ item3Conf|default() }}', resource: 'item3'} > when: item.name > > Cheers, > > -vlado > -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAGH8rEzmM2QzxTqkj7mG2YaUuAVZ2dwWfQRLcxs%2BZ-hEFObvgA%40mail.gmail.com.
