title: How to group set of tasks into a block in ansible playbook?
body: <p>I am creating a ansible playbook for configuring our build systems. Part of it I started of writing roles for installing java (open JDK and Oracle JDK)  for CentOS. Open JDK is available through YUM package manager so no issues in idempotency there. For oracle Java, I need to download, install, symlink it and clean up. In order to create idempotency I am looking for neater way of doing it, for example here is my code. Basically I am checking for a symlink to determine if java is installed or not and register a variable to use it in WHEN module later. What I am not liking is using <em>When</em> statement for all four steps in installing jdk. how can I group all the four steps (download, install, symlink and cleanup) into a block and make them all run based on one <em>when</em> statement?</p>
  
  <pre><code>- name: Check if Java 8 is instaled
    stat: path=~/java/oraclejdk8
    register: oraclejdk8_sym
  
  - name: Download Java 8
    command: "wget --no-cookies -O {{ jdk_download_path }}/{{ oraclejdk8.jdk_rpm_file }} --no-check-certificate --header 'Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie' {{ oraclejdk8.jdk_rpm_url }}"
    when: oraclejdk8_sym.stat.islnk is not defined
  
  - name: Install Java 8
    yum: name={{ java_archive }} state=present
    when: oraclejdk8_sym.stat.islnk is not defined
  
  - name: Symlink to ~/java/oraclejdk8
    file: path=~/java/ state=directory mode=0755
    command: "ln -s /usr/java/jdk{{ oraclejdk8.jdk_version  }} ~/java/oraclejdk8"
    when: oraclejdk8_sym.stat.islnk is not defined
  
  - name: Clean up
    file: state=absent path={{ jdk_download_path}}/{{ oraclejdk8.jdk_rpm_file }}
    when: oraclejdk8_sym.stat.islnk is not defined
  </code></pre>