--- - name: Configuring repolist through module hosts: nodes tasks: - block: - name: Real Work yum_repository: baseurl: file:///mnt/AppStream description: "These is AppStream Repo" enabled: true gpgcheck: false name: AppStream reposdir: /etc/yum.repos.d/ state: absent file: AppStream - name: Real Work yum_repository: baseurl: file:///mnt/BaseOS description: "These is BaseOS Repo" enabled: true gpgcheck: false name: BaseOS reposdir: /etc/yum.repos.d/ state: absent file: BaseOS when: ansible_distribution == "RedHat" rescue: - name: If the block task fail then use standy method in rescue copy: src: /tmp/local.repo dest: /etc/yum.repos.d/ ... # Block and rescue demonstration when any task in the block mode get failed the below rescue mode get executed # Create the manual failure of the task mentioned in the block section ans see how ansible continues with rescue task.