10-Day4-2-BlockRescueAlways
Day 4: Lab Exercise- Block, Rescue, and Always Constructs for Error Handling
Lab 2.1: Basic Use of Block and Rescue
- name: Block and Rescue Demo - Basic hosts: localhost become: yes tasks: - name: Demonstrate block and rescue block: - name: Attempt to create directory in /root/ file: path: /root/sample_directory state: directory rescue: - name: Log the error message debug: msg: "Failed to create directory in /root/, attempting in /tmp/." - name: Create directory in /tmp/ instead file: path: /tmp/sample_directory state: directory
ansible-playbook ~/day4/block_rescue_basic.yaml
Lab 2.2: Using Always for Cleanup Actions
Alternative Example for Lab 2.3: Comprehensive Example with Block, Rescue, and Always
Optional Challenge:
Lab 2.3: Comprehensive Example with Block, Rescue, and Always
Optional Lab: Nested Block and Rescue
Key Learning Points:
Last updated