# How to use the same dictionary to loop over two tasks? is it possible using block?

**URL:** <https://forum.ansible.com/t/how-to-use-the-same-dictionary-to-loop-over-two-tasks-is-it-possible-using-block/27253>\
**Category:** Ansible Project\
**Created:** [April 12, 2018, 12:20am UTC](https://forum.ansible.com/t/how-to-use-the-same-dictionary-to-loop-over-two-tasks-is-it-possible-using-block/27253 "2018-04-12T00:20:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tchia04](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@Tchia04](https://forum.ansible.com/u/Tchia04)\
**Post date:** [April 12, 2018, 12:20am UTC](https://forum.ansible.com/t/how-to-use-the-same-dictionary-to-loop-over-two-tasks-is-it-possible-using-block/27253/1 "2018-04-12T00:20:03Z")

</div>

I.e.  
instead of doing this which does win\_iis\_website,win\_iis\_website,etc then win\_iis\_webbinding,win\_iis\_webbinding, etc

- name: Create IIS site  
win\_iis\_website:  
name: ‘{{ item.key }}’  
state: started  
application\_pool: ‘{{ item.value.application\_pool }}’  
physical\_path: ‘{{ item.value.physical\_path }}’  
with\_dict: “{{ sites }}”
- name: Bind Site  
win\_iis\_webbinding:  
name: ‘{{ item.key }}’  
protocol: https  
ip: ‘{{ ansible\_ip\_addresses[0] }}’  
port: ‘{{ item.value.http\_port }}’  
certificate\_hash: ‘{{ item.value.cert\_thumbprint }}’  
with\_dict: “{{ sites }}”

I would like to do this so that the win\_iis\_webbinding is called immediately after win\_iis\_website instead of calling win\_iis\_website,win\_iis\_website,etc then win\_iis\_webbinding, win\_iis\_webbinding, etc

- block:
- name: Create IIS site  
win\_iis\_website:  
name: ‘{{ item.key }}’  
state: started  
application\_pool: ‘{{ item.value.application\_pool }}’  
physical\_path: ‘{{ item.value.physical\_path }}’
- name: Bind Site  
win\_iis\_webbinding:  
name: ‘{{ item.key }}’  
protocol: https  
ip: ‘{{ ansible\_ip\_addresses[0] }}’  
port: ‘{{ item.value.http\_port }}’  
certificate\_hash: ‘{{ item.value.cert\_thumbprint }}’  
with\_dict: “{{ sites }}”  
tags: webapp

However I got this

ERROR! ‘with\_dict’ is not a valid attribute for a Block

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [April 12, 2018, 2:55pm UTC](https://forum.ansible.com/t/how-to-use-the-same-dictionary-to-loop-over-two-tasks-is-it-possible-using-block/27253/2 "2018-04-12T14:55:50Z")

</div>

block doesn't support loops.  
Too loop over several tasks you need to put the task in a file and use include\_task: and loop over that.
