{"id":79097,"date":"2026-11-17T02:03:39","date_gmt":"2026-11-17T02:03:39","guid":{"rendered":"http:\/\/bangla.sitestree.com\/?p=79097"},"modified":"2026-11-17T02:03:39","modified_gmt":"2026-11-17T02:03:39","slug":"linux-advanced-2-03-automation","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=79097","title":{"rendered":"Linux Advanced 2 03 \u2014 Repeatable Configuration with Ansible"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/bangla.sitestree.com\/?name=linux-course-index\">Linux course index<\/a> \u00b7 <a href=\"https:\/\/bangla.sitestree.com\/?cat=1993\">Linux Advanced 2 category<\/a> \u00b7 Lesson 3 of 7<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>AI disclosure<\/strong> \u2014 AI-generated content, posted as is. AI can make mistakes. This extension adds new material and links related posts from this site. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Learning goal<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Convert a small configuration task into an Ansible playbook and demonstrate idempotence.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Concepts and setup<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The archive often records administration as terminal history. That shows what someone typed but does not guarantee the final state on another host. Ansible describes a desired result. Idempotence means applying that same configuration to a system already at the desired state makes no further change. This lab needs Ansible and Python, uses localhost only, and never escalates privileges. Do not use diff output on files that contain secrets.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Write a config playbook and preview it<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>lab=$(mktemp -d)\ncd &quot;$lab&quot; || exit\ncat &gt; lab.yml &lt;&lt;'YAML'\n---\n- name: Maintain one lab settings file\n  hosts: localhost\n  connection: local\n  gather_facts: false\n  tasks:\n    - name: Install the intended settings\n      ansible.builtin.copy:\n        content: &quot;service=demo\\n&quot;\n        dest: &quot;{{ playbook_dir }}\/service.conf&quot;\n        mode: &quot;0644&quot;\nYAML\nansible-playbook -i localhost, lab.yml --syntax-check\nansible-playbook -i localhost, lab.yml --check --diff\ntest ! -e service.conf &amp;&amp; printf 'preview did not write\\n'<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Possible output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>playbook: lab.yml\n...\nchanged: [localhost]\npreview did not write<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The comma in localhost, makes it an inline inventory. This module can predict a file change without writing it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Apply the playbook twice<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>ansible-playbook -i localhost, lab.yml\nansible-playbook -i localhost, lab.yml\ncat service.conf\nstat -c '%a' service.conf<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Possible output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>... localhost : ok=1 changed=1 ...\n... localhost : ok=1 changed=0 ...\nservice=demo\n644<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first run changes the fixture. The next makes no change. If the playbook also manages a service, follow configuration verification with a health check.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Questions only<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Quick-check questions<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n\n<li>What does changed=0 mean on the repeated run?<\/li>\n\n\n<li>Why use a copy module instead of echo in a shell task?<\/li>\n\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Assessment questions<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n\n<li>How would you demonstrate correction of drift?<\/li>\n\n\n<li>Why can a clean check-mode run miss a production problem?<\/li>\n\n\n<li>Name two steps before extending the inventory beyond localhost.<\/li>\n\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Questions and answers<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Quick-check answers<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n\n<li><strong>What does changed=0 mean on the repeated run?<\/strong><br><strong>Answer<\/strong> \u2014 The module found that the resource already matches the declared state.<\/li>\n\n\n<li><strong>Why use a copy module instead of echo in a shell task?<\/strong><br><strong>Answer<\/strong> \u2014 The module compares state and can manage content and permissions repeatably.<\/li>\n\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Assessment answer key<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n\n<li><strong>How would you demonstrate correction of drift?<\/strong><br><strong>Answer<\/strong> \u2014 Deliberately change the lab file, preview and apply the playbook, check that the correct state came back, then confirm a repeated run shows changed=0.<\/li>\n\n\n<li><strong>Why can a clean check-mode run miss a production problem?<\/strong><br><strong>Answer<\/strong> \u2014 Some effects are not simulated, and actual target runtime conditions can differ.<\/li>\n\n\n<li><strong>Name two steps before extending the inventory beyond localhost.<\/strong><br><strong>Answer<\/strong> \u2014 Review and authorize targets, protect secrets, stage changes, and test rollback. Any two.<\/li>\n\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Related source articles on this site<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li><a href=\"https:\/\/bangla.sitestree.com\/?p=21831\">Some Ubuntu Linux Commands used in AWS platform #Unix\/Linux #RHCSA<\/a><\/li>\n\n\n<li><a href=\"https:\/\/bangla.sitestree.com\/?p=65730\">Topic 2: Example: Debug a Script #Linux\/Unix: Shell Programming \u2013 001<\/a><\/li>\n\n\n<li><a href=\"https:\/\/bangla.sitestree.com\/?p=67586\">Create your own yum repo in Centos\/Redhat #DevOps #RHCSA<\/a><\/li>\n\n\n<li><a href=\"https:\/\/bangla.sitestree.com\/?p=78691\">Q &amp; A:  Linux: Switch Users, Boot Process, File System<\/a><\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Technical references<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li><a href=\"https:\/\/docs.ansible.com\/projects\/ansible\/latest\/playbook_guide\/playbooks_checkmode.html\">Ansible check and diff modes<\/a><\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Continue the course<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Previous lesson 02 \u2014 Rootless Containers with Podman. Next lesson 04 \u2014 Performance Triage with vmstat and PSI.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/bangla.sitestree.com\/?name=linux-course-index\">Linux course index<\/a> \u00b7 <a href=\"https:\/\/bangla.sitestree.com\/?cat=1993\">Linux Advanced 2 category<\/a> \u00b7 Lesson 3 of 7<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Convert a small configuration task into an Ansible playbook and demonstrate idempotence.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1993],"tags":[],"class_list":["post-79097","post","type-post","status-publish","format-standard","hentry","category-linux-advanced-2","item-wrap"],"jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":79102,"url":"http:\/\/bangla.sitestree.com\/?p=79102","url_meta":{"origin":79097,"position":0},"title":"Linux Administration Course \u2014 Start Here and Lesson Index","author":"Sayed","date":"November 17, 2026","format":false,"excerpt":"A 33-lesson Linux course from shell fundamentals to server administration, performance, and a recovery capstone.","rel":"","context":"In &quot;Linux Basics&quot;","block_context":{"text":"Linux Basics","link":"http:\/\/bangla.sitestree.com\/?cat=1990"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":79096,"url":"http:\/\/bangla.sitestree.com\/?p=79096","url_meta":{"origin":79097,"position":1},"title":"Linux Advanced 2 02 \u2014 Rootless Containers with Podman","author":"Sayed","date":"November 17, 2026","format":false,"excerpt":"Serve a fixture with rootless Podman and verify that its port is published only on loopback.","rel":"","context":"In &quot;Linux Advanced 2&quot;","block_context":{"text":"Linux Advanced 2","link":"http:\/\/bangla.sitestree.com\/?cat=1993"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":79098,"url":"http:\/\/bangla.sitestree.com\/?p=79098","url_meta":{"origin":79097,"position":2},"title":"Linux Advanced 2 04 \u2014 Performance Triage with vmstat and PSI","author":"Sayed","date":"November 17, 2026","format":false,"excerpt":"Use related signals to decide whether to investigate CPU, memory, disk I\/O, or an application bottleneck.","rel":"","context":"In &quot;Linux Advanced 2&quot;","block_context":{"text":"Linux Advanced 2","link":"http:\/\/bangla.sitestree.com\/?cat=1993"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":14827,"url":"http:\/\/bangla.sitestree.com\/?p=14827","url_meta":{"origin":79097,"position":3},"title":"Web Control Panels : Cloud Server Management\/Control Panels","author":"Sayed","date":"June 24, 2019","format":false,"excerpt":"2019's Ultimate Guide to Web Panels: cPanel vs. Plesk vs. Webmin vs. Other Popular Hosting Management Tools https:\/\/www.hostingadvice.com\/blog\/cpanel-vs-plesk-vs-webpanel\/ --- How to enable\/disable PHP extensions in Plesk interface? https:\/\/support.plesk.com\/hc\/en-us\/articles\/115001377534-How-to-enable-disable-PHP-extensions-in-Plesk-interface- --- If the above does not work? or if you are not using Plesk How to Setup ionCube Loader on CentOS 7\u2026","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":79091,"url":"http:\/\/bangla.sitestree.com\/?p=79091","url_meta":{"origin":79097,"position":4},"title":"Linux Advanced 06 \u2014 DHCP Leases and a Kea Lab","author":"Sayed","date":"November 17, 2026","format":false,"excerpt":"Validate a Kea DHCPv4 pool and verify a lease issued to a VM on an isolated segment.","rel":"","context":"In &quot;Linux Advanced&quot;","block_context":{"text":"Linux Advanced","link":"http:\/\/bangla.sitestree.com\/?cat=1992"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":25045,"url":"http:\/\/bangla.sitestree.com\/?p=25045","url_meta":{"origin":79097,"position":5},"title":"Web Control Panels : Cloud Server Management\/Control Panels #Root","author":"Author-Check- Article-or-Video","date":"April 15, 2021","format":false,"excerpt":"2019's Ultimate Guide to Web Panels: cPanel vs. Plesk vs. Webmin vs. Other Popular Hosting Management Tools https:\/\/www.hostingadvice.com\/blog\/cpanel-vs-plesk-vs-webpanel\/ CentOS Control Panel http:\/\/centos-webpanel.com\/ --- How to enable\/disable PHP extensions in Plesk interface? https:\/\/support.plesk.com\/hc\/en-us\/articles\/115001377534-How-to-enable-disable-PHP-extensions-in-Plesk-interface- --- If the above does not work? or if you are not using Plesk How to Setup ionCube\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/79097","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=79097"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/79097\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=79097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=79097"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=79097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}