Ansible: The changed_when parameter

Ansible_Logo

By default, when a playbook is executed, in the display mode stdout we will see various piece of information. IT provides us a the sections through which the execution is proceeding, displaying the name is the play and task, and information weather the task made any changes in the managed node or not. It displays this information as either OK, changed, failed skipped or ignored, as the specific task is executed. In addition, at the bottom, a summary too is listed providing the number of OK, changed or failed tasks.

When a changed_when parameter is used in a task block, this output get locked to certain value. If the parameter “changed_when: true” is used, the value of OK state will always be marked as false. Or is the parameter “changed_when: false” is used, the value of OK state will always be marked as true, and the value of changed as false.

An example of the task can be as follows:
=== ====

tasks:
    – name: Task to create a crontab file with entry
        ansible.builtin.cron:
            name: Add a crontab file
            cron_file: the-date-time
            minute: “10”
            hour: “9-16”
            job: “ls /var >> /home/user1/the_date_time_cron_job”
            state: absent
    changed_when: false
==== ==