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

20 views
Skip to first unread message

Tony Chia

unread,
Apr 11, 2018, 8:20:03 PM4/11/18
to Ansible Project
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

Kai Stian Olstad

unread,
Apr 12, 2018, 10:56:09 AM4/12/18
to ansible...@googlegroups.com
On 12.04.2018 02:20, Tony Chia wrote:
> 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

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.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages