* add note about named tasks in blocks
Signed-off-by: Adam Miller <admiller@redhat.com>
* adds names to tasks within example block, removes 2nd example
* removes traces of bad rebase
@ -6,25 +6,27 @@ Blocks allow for logical grouping of tasks and in play error handling. Most of w
..code-block:: YAML
..code-block:: YAML
:emphasize-lines:3
:emphasize-lines:3
:caption:Block example
:caption:Block example with named tasks inside the block
tasks:
tasks:
- name: Install Apache
- name: Install, configure, and start Apache
block:
block:
- yum:
- name: install httpd and memcached
name: "{{ item }}"
yum:
state: installed
name: "{{ item }}"
loop:
state: installed
- httpd
loop:
- memcached
- httpd
- template:
- memcached
src: templates/src.j2
- name: apply the foo config template
dest: /etc/foo.conf
template:
- service:
src: templates/src.j2
name: bar
dest: /etc/foo.conf
state: started
- name: start service bar and enable it
enabled: True
service:
name: bar
state: started
enabled: True
when: ansible_facts['distribution'] == 'CentOS'
when: ansible_facts['distribution'] == 'CentOS'
become: true
become: true
become_user: root
become_user: root
@ -33,9 +35,7 @@ In the example above, each of the 3 tasks will be executed after appending the `
and evaluating it in the task's context. Also they inherit the privilege escalation directives enabling "become to root"
and evaluating it in the task's context. Also they inherit the privilege escalation directives enabling "become to root"
for all the enclosed tasks.
for all the enclosed tasks.
..versionadded:: 2.3
Names for tasks within blocks have been available since Ansible 2.3. We recommend using names in all tasks, within blocks or elsewhere, for better visibility into the tasks being executed when you run the playbook.
The ``name:`` keyword for ``block:`` was added in Ansible 2.3.