20/11/2024

Ansible – 10 hata yönetimi

Bazen calistirdigimiz tasklar cesitli sebeplerle hataya düsebilirler.

- name: Package Installation
  hosts: nodes
  become: yes
  tasks:
    - name: Install wrong package
      yum:
        name: wrongpackage
        state: present
      ignore_errors: yes
      register: error_message

    - name: Display
      debug:  
        msg: "{{ error_message }}"

Eger fail olunca playbook calismasinin durmasini istiyorsak su task i ekleyebiliriz.

    - name: Fail if there is failed status
      fail:
        msg: "The state is failed"
      when: error_message.failed == True