{"id":1417,"date":"2024-06-15T23:25:15","date_gmt":"2024-06-15T23:25:15","guid":{"rendered":"http:\/\/shijuvarghese.com\/?p=1417"},"modified":"2025-05-23T19:03:37","modified_gmt":"2025-05-23T19:03:37","slug":"ansible-the-changed_when-parameter","status":"publish","type":"post","link":"http:\/\/shijuvarghese.com\/?p=1417","title":{"rendered":"Ansible: The changed_when parameter"},"content":{"rendered":"<p>By default, when a playbook is executed, in the display mode <em>stdout<\/em> 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\u00a0<em>task<\/em> made any changes in the managed node or not. It displays this information\u00a0as either OK, <strong>changed,\u00a0<\/strong>failed skipped or ignored, as the specific\u00a0<em>task<\/em> is executed. In addition, at the bottom, a summary too is listed providing the number of OK, changed or failed tasks.<\/p>\n<p>When a\u00a0<strong>changed_when<\/strong> parameter is used in a task block, this output get locked to certain value. If the parameter &#8220;<strong><em>changed_when: true<\/em><\/strong>&#8221; is used, the value of\u00a0<strong>OK\u00a0<\/strong>state will always be marked as false. Or is the parameter &#8220;<em><strong>changed_when: false<\/strong><\/em>&#8221;\u00a0is used, the value of\u00a0<strong>OK\u00a0<\/strong>state will always be marked as true, and\u00a0the value of\u00a0<em><strong>changed<\/strong><\/em> as false.<\/p>\n<p>An example of the task can be as follows:<br \/>\n=== ====<\/p>\n<p><em>tasks:<\/em><br \/>\n<em> &nbsp; &nbsp; &#8211; name: Task to create a crontab file with entry<\/em><br \/>\n<em> &nbsp; &nbsp; &nbsp; &nbsp; ansible.builtin.cron:<\/em><br \/>\n<em> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: Add a crontab file<\/em><br \/>\n<em> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cron_file: the-date-time<\/em><br \/>\n<em> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; minute: &#8220;10&#8221;<\/em><br \/>\n<em> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hour: &#8220;9-16&#8221;<\/em><br \/>\n<em> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; job: &#8220;ls \/var &gt;&gt; \/home\/user1\/the_date_time_cron_job&#8221;<\/em><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <em> state: absent<\/em><br \/>\n&nbsp; &nbsp; <em> changed_when: false<\/em><br \/>\n==== ==<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>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 <a class=\"mh-excerpt-more\" href=\"http:\/\/shijuvarghese.com\/?p=1417\" title=\"Ansible: The changed_when parameter\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":1792,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32,21],"tags":[],"class_list":["post-1417","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ansible","category-devops"],"_links":{"self":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/1417","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1417"}],"version-history":[{"count":5,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/1417\/revisions"}],"predecessor-version":[{"id":1423,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/1417\/revisions\/1423"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/media\/1792"}],"wp:attachment":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1417"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}