ruk·si

⚙️ Ansible
Blocks

Updated at 2017-03-22 01:46

block is a logical grouping of tasks for error handling.

tasks:
  - block:

      - yum: name={{ item }} state=installed
        with_items:
          - httpd
          - memcached

      - template: src=templates/src.j2 dest=/etc/foo.conf

      - service: name=bar state=started enabled=True

    when: ansible_distribution == 'CentOS'
    become: true
    become_user: root
    rescue:
      - debug: msg='I caught an error'
      - command: /bin/false
      - debug: msg='I also never execute :-('
    always:
      - debug: msg="this always executes"

Sources