Skip to contentমূল লেখায় যান

Topic 20 · DevOps & Cloudটপিক 20 · DevOps & Cloud

Ansible

This page covers Ansible: its inventory, its playbooks and modules, check mode, handlers, tests, ansible-lint, and Ansible Vault. The practice run applies two playbooks to your own machine. It needs no remote host and no cloud account. It comes after Terraform and Infrastructure as Code and before Monitoring and Observability.

60 min read60 মিনিটে পড়া যায় · 7 sections7টি সেকশন · 45 sources45টি সোর্স · updated Nov 2026আপডেট: Nov 2026

Run twice, change onceদুবার চালান, একবারই বদলায়

Run one playbook twice: the first run changes things and fires a handler, the second changes nothing. Then try check mode.একটা playbook দুবার চালান: প্রথম রানে জিনিস বদলায় আর handler চলে, দ্বিতীয় রানে কিছু বদলায় না। তারপর check mode দেখুন।

2 min2 মিনিট7 steps7টি ধাপ
  • Hostsহোস্ট1
  • Tasksটাস্ক2
  • Handlersহ্যান্ডলার1
control nodeকন্ট্রোল নোডinventoryইনভেন্টরিapp: localhostapp: localhostlocalhostlocalhostmanaged hostম্যানেজড হোস্টgroup appগ্রুপ appno out/ folder yetout/ এখনও নেই

You’ll learnআপনি শিখবেন

  • What an inventory and a play areinventory আর play কী
  • Why a second run changes nothingদ্বিতীয় রানে কেন কিছু বদলায় না
  • How a handler runs once, after a changeপরিবর্তনের পর handler কীভাবে একবার চলে
  • How check mode finds driftcheck mode কীভাবে drift ধরে

What it is

Ansible. Ansible provides open-source automation that reduces complexity and runs everywhere Source 1সোর্স 1. Ansible uses simple, human-readable scripts called playbooks to automate your tasks Source 1সোর্স 1. You declare the desired state of a local or remote system in your playbook Source 1সোর্স 1. Ansible ensures that the system remains in that state Source 1সোর্স 1. Some of its common use cases are to eliminate repetition and simplify workflows, to manage and maintain system configuration, to continuously deploy complex software, and to perform zero-downtime rolling updates Source 1সোর্স 1.

The design. Ansible is designed around an agent-less architecture Source 1সোর্স 1. Its playbooks use straightforward YAML syntax for code that reads like documentation Source 1সোর্স 1. Ansible is also decentralized, and it uses SSH with existing OS credentials to access remote machines Source 1সোর্স 1. Ansible does not change anything when the system is in the state that the playbook describes, even if the playbook runs many times Source 1সোর্স 1.

The parts. Ansible automates the management of remote systems and controls their desired state Source 2সোর্স 2. Most Ansible environments have three main components Source 2সোর্স 2. The control node is a system on which Ansible is installed Source 2সোর্স 2. You run Ansible commands such as ansible or ansible-inventory on a control node Source 2সোর্স 2. The inventory is a list of managed nodes that are logically organized Source 2সোর্স 2. A managed node is a remote system, or host, that Ansible controls Source 2সোর্স 2.

You install Ansible on a single host, which is the control node Source 5সোর্স 5. From the control node, Ansible can manage machines remotely with SSH, Powershell remoting, and numerous other transports, with no databases or daemons required Source 5সোর্স 5. The control node can be nearly any UNIX-like machine with Python installed Source 5সোর্স 5.

The packages. Ansible's community packages are distributed in two ways Source 5সোর্স 5. The ansible-core package is a minimalist language and runtime package that contains a set of built-in modules and plugins Source 5সোর্স 5. The ansible package is a much larger "batteries included" package Source 5সোর্স 5. It adds a community-curated selection of Ansible Collections Source 5সোর্স 5. The docs install the minimal package for the current user with python3 -m pip install --user ansible-core Source 5সোর্স 5.

সহজ English

Ansible. Ansible provides open-source automation that reduces complexity and runs everywhere Source 1সোর্স 1. Ansible uses simple, human-readable scripts called playbooks to automate your tasks Source 1সোর্স 1. You declare the desired state of a local or remote system in your playbook Source 1সোর্স 1. Ansible ensures that the system remains in that state Source 1সোর্স 1. Some of its common use cases are to eliminate repetition and simplify workflows, to manage and maintain system configuration, to continuously deploy complex software, and to perform zero-downtime rolling updates Source 1সোর্স 1.

The design. Ansible is designed around an agent-less architecture Source 1সোর্স 1. Its playbooks use straightforward YAML syntax for code that reads like documentation Source 1সোর্স 1. Ansible is also decentralized, and it uses SSH with existing OS credentials to access remote machines Source 1সোর্স 1. Ansible does not change anything when the system is in the state that the playbook describes, even if the playbook runs many times Source 1সোর্স 1.

The parts. Ansible automates the management of remote systems and controls their desired state Source 2সোর্স 2. Most Ansible environments have three main components Source 2সোর্স 2. The control node is a system on which Ansible is installed Source 2সোর্স 2. You run Ansible commands such as ansible or ansible-inventory on a control node Source 2সোর্স 2. The inventory is a list of managed nodes that are logically organized Source 2সোর্স 2. A managed node is a remote system, or host, that Ansible controls Source 2সোর্স 2.

You install Ansible on a single host, which is the control node Source 5সোর্স 5. From the control node, Ansible can manage machines remotely with SSH, Powershell remoting, and numerous other transports, with no databases or daemons required Source 5সোর্স 5. The control node can be nearly any UNIX-like machine with Python installed Source 5সোর্স 5.

The packages. Ansible's community packages are distributed in two ways Source 5সোর্স 5. The ansible-core package is a minimalist language and runtime package that contains a set of built-in modules and plugins Source 5সোর্স 5. The ansible package is a much larger "batteries included" package Source 5সোর্স 5. It adds a community-curated selection of Ansible Collections Source 5সোর্স 5. The docs install the minimal package for the current user with python3 -m pip install --user ansible-core Source 5সোর্স 5.

বাংলা ব্যাখ্যা

Ansible। Ansible এমন open-source automation দেয়, যা জটিলতা কমায় আর সব জায়গায় চলে Source 1সোর্স 1। Ansible সাধারণ, মানুষ-পাঠযোগ্য script ব্যবহার করে, যাদের নাম playbook, আপনার কাজ automate করতে Source 1সোর্স 1। আপনি আপনার playbook-এ একটা স্থানীয় বা দূরের system-এর কাঙ্ক্ষিত অবস্থা (desired state) ঘোষণা করেন Source 1সোর্স 1। Ansible নিশ্চিত করে যে system সেই অবস্থায় থাকে Source 1সোর্স 1। এর কিছু সাধারণ ব্যবহার হলো পুনরাবৃত্তি দূর করা আর workflow সরল করা, system configuration পরিচালনা ও রক্ষণাবেক্ষণ করা, জটিল software ধারাবাহিকভাবে deploy করা, আর zero-downtime rolling update করা Source 1সোর্স 1।

নকশা। Ansible তৈরি agent-less architecture-কে ঘিরে Source 1সোর্স 1। এর playbook এমন সরল YAML syntax ব্যবহার করে, যাতে code documentation-এর মতো পড়া যায় Source 1সোর্স 1। Ansible বিকেন্দ্রীকৃতও, আর দূরের মেশিনে ঢুকতে সে বিদ্যমান OS credential দিয়ে SSH ব্যবহার করে Source 1সোর্স 1। system যখন playbook-এর বর্ণিত অবস্থায় থাকে, তখন playbook বহুবার চললেও Ansible কিছুই বদলায় না Source 1সোর্স 1।

অংশগুলো। Ansible দূরের system-এর পরিচালনা automate করে আর তাদের কাঙ্ক্ষিত অবস্থা নিয়ন্ত্রণ করে Source 2সোর্স 2। বেশির ভাগ Ansible পরিবেশে তিনটা প্রধান অংশ থাকে Source 2সোর্স 2। control node হলো এমন একটা system, যাতে Ansible install করা আছে Source 2সোর্স 2। আপনি control node-এ ansible বা ansible-inventory-র মতো Ansible command চালান Source 2সোর্স 2। inventory হলো managed node-এর একটা তালিকা, যা যুক্তিসঙ্গতভাবে সাজানো Source 2সোর্স 2। managed node হলো একটা দূরের system বা host, যাকে Ansible নিয়ন্ত্রণ করে Source 2সোর্স 2।

আপনি Ansible install করেন একটাই host-এ, যা control node Source 5সোর্স 5। control node থেকে Ansible SSH, Powershell remoting আর আরও অনেক transport দিয়ে দূর থেকে machine পরিচালনা করতে পারে, কোনো database বা daemon ছাড়াই Source 5সোর্স 5। control node হতে পারে Python install করা প্রায় যেকোনো UNIX-এর মতো মেশিন Source 5সোর্স 5।

package-গুলো। Ansible-এর community package দুইভাবে বিতরণ হয় Source 5সোর্স 5। ansible-core package একটা ন্যূনতম language আর runtime package, যাতে কিছু built-in module আর plugin আছে Source 5সোর্স 5। ansible package অনেক বড়, "batteries included" package Source 5সোর্স 5। এটা community-র বাছাই করা একসেট Ansible Collection যোগ করে Source 5সোর্স 5। docs বর্তমান user-এর জন্য ন্যূনতম package install করে python3 -m pip install --user ansible-core দিয়ে Source 5সোর্স 5।

How it works

The inventory. Ansible automates tasks on managed nodes, or hosts, by using a list or group of lists known as inventory Source 6সোর্স 6. Your inventory defines the managed nodes you automate and the variables associated with those hosts Source 6সোর্স 6. You can also specify groups Source 6সোর্স 6. The most common formats are INI and YAML, because Ansible includes built-in support for them Source 6সোর্স 6. You can pass another inventory source at the command line with -i Source 6সোর্স 6. Even if you define no groups, Ansible creates two default groups, all and ungrouped Source 6সোর্স 6. The all group contains every host Source 6সোর্স 6. The ungrouped group contains all hosts that do not belong to any other group Source 6সোর্স 6.

To build an inventory file, you add a new [myhosts] group Source 3সোর্স 3. You specify the IP address or fully qualified domain name (FQDN) of each host system Source 3সোর্স 3. The docs check an inventory with ansible-inventory -i inventory.ini --list Source 3সোর্স 3, and they ping a group with ansible myhosts -m ping -i inventory.ini Source 3সোর্স 3. With an inventory file, Ansible can manage a large number of hosts with a single command Source 3সোর্স 3.

A host does not need a remote connection. The local connection plugin allows Ansible to execute tasks on the controller instead of on a remote host Source 7সোর্স 7. Most Ansible modules that run in a POSIX environment need a Python interpreter on the target host Source 8সোর্স 8. Unless you configure it, Ansible tries to discover one the first time that it runs a Python module for that host Source 8সোর্স 8. The ansible_python_interpreter variable specifies the target host Python path Source 6সোর্স 6. The default value auto searches the configurable list of common Python interpreter paths Source 8সোর্স 8. It issues a warning that future installation of another Python interpreter could alter the one chosen Source 8সোর্স 8. The value auto_silent does not issue warnings Source 8সোর্স 8.

Playbooks, plays, tasks, and modules. Playbooks are automation blueprints, in YAML format, that Ansible uses to deploy and configure managed nodes Source 4সোর্স 4. A playbook is a list of plays that define the order in which Ansible performs operations, from top to bottom, to achieve an overall goal Source 4সোর্স 4. A play is an ordered list of tasks that maps to managed nodes in an inventory Source 4সোর্স 4. A task is a reference to a single module that defines the operations that Ansible performs Source 4সোর্স 4. A module is a unit of code or binary that Ansible runs on managed nodes Source 4সোর্স 4. Each task calls an Ansible module Source 10সোর্স 10. You express playbooks in YAML with a minimum of syntax Source 10সোর্স 10.

A playbook runs in order from top to bottom Source 10সোর্স 10. At a minimum, each play defines the managed nodes to target, using a pattern, and at least one task to execute Source 10সোর্স 10. By default, Ansible executes each task in order, one at a time, against all machines that the host pattern matches Source 10সোর্স 10. For Ansible 2.10 and later, you should use the fully-qualified collection name (FQCN) in your playbooks Source 10সোর্স 10. The tips page says to use fully qualified collection names to avoid ambiguity in which collection to search for the correct module or plugin for each task Source 29সোর্স 29. The tips page also says to always name plays, tasks, and blocks Source 29সোর্স 29, and to always mention the state of a module Source 29সোর্স 29.

To run a playbook, use the ansible-playbook command Source 10সোর্স 10. When you run a playbook, Ansible returns the name lines of your plays and tasks Source 10সোর্স 10. It also returns whether each task has succeeded or failed on each machine, and whether each task has made a change on each machine Source 10সোর্স 10. At the bottom, it gives a summary of the nodes that were targeted and how they performed Source 10সোর্স 10. The ansible-playbook command can verify a playbook with --check, --diff, --list-hosts, --list-tasks, and --syntax-check Source 10সোর্স 10. --syntax-check performs a syntax check on the playbook, but does not execute it Source 20সোর্স 20. --list-tasks lists all tasks that would be executed Source 20সোর্স 20. --list-hosts outputs a list of matching hosts, and does not execute anything else Source 20সোর্স 20.

The modules of the tutorial. The file module sets attributes of files, directories, or symlinks and their targets Source 21সোর্স 21. With state: directory, the target is a directory, and if needed all intermediate subdirectories are created, using the supplied permissions Source 21সোর্স 21. Modes are octal numbers, and for consistent results, you should quote octal numbers so that Ansible receives a string Source 21সোর্স 21. The copy module copies a file or a directory structure from the local or remote machine to a location on the remote machine Source 22সোর্স 22. When you use content instead of src, it sets the contents of a file directly to the given value Source 22সোর্স 22. It works only when dest is a file, and it creates the file if it does not exist Source 22সোর্স 22. For the template module, templates are processed by the Jinja2 templating language Source 23সোর্স 23. Its src is the path of a Jinja2 formatted template on the Ansible controller Source 23সোর্স 23. Its dest is the location to render the template to on the remote machine Source 23সোর্স 23. The slurp module works like fetch, and it is used for fetching a base64-encoded blob containing the data in a remote file Source 24সোর্স 24. The assert module asserts that given expressions are true, with an optional custom message Source 25সোর্স 25. Its that option is a list of string expressions of the same form that you can pass to the when statement Source 25সোর্স 25.

Ansible modules normally return a data structure that you can register into a variable Source 18সোর্স 18. The key changed is a boolean indicating if the task had to make changes to the target or delegated host Source 18সোর্স 18. The key failed is a boolean that indicates if the task was failed or not Source 18সোর্স 18. The key diff holds information on differences between previous and current state Source 18সোর্স 18.

Desired state and idempotence. Most Ansible modules check whether the desired final state has already been achieved, and they exit without performing any actions if it has Source 10সোর্স 10. Modules that behave this way are idempotent Source 10সোর্স 10. An operation is idempotent if the result of performing it once is exactly the same as the result of performing it repeatedly without any intervening actions Source 19সোর্স 19. Not all playbooks and not all modules behave this way Source 10সোর্স 10.

The shell and command modules run arbitrary commands, and they do not naturally detect if a change has occurred Source 35সোর্স 35. With changed_when, you define when a task has changed a remote node Source 16সোর্স 16. That lets you determine, based on return codes or output, whether a change should be reported in the statistics and whether a handler should be triggered Source 16সোর্স 16. With failed_when, you define what failure means in each task Source 16সোর্স 16.

Variables, facts, and templates. Ansible uses variables to manage differences between systems Source 11সোর্স 11. You can define variables in your playbooks, in your inventory, in reusable files or roles, or at the command line Source 11সোর্স 11. You can also create a variable during a run by registering the return value of a task Source 11সোর্স 11. Ansible uses Jinja2 templating to enable dynamic expressions and access to variables and facts Source 12সোর্স 12. You can use templating with the template module Source 12সোর্স 12. Facts are things that are discovered about remote nodes Source 19সোর্স 19. Ansible discovers them when it runs plays, by executing the internal setup module on the remote nodes Source 19সোর্স 19. Fact gathering can be disabled to save time if it is not needed Source 19সোর্স 19.

Handlers. Sometimes you want a task to run only when a change is made on a machine Source 13সোর্স 13. Handlers are tasks that only run when notified Source 13সোর্স 13. A task uses the notify keyword to instruct one or more handlers to execute Source 13সোর্স 13. The keyword accepts a list of handler names that are notified on a task change Source 13সোর্স 13. Notifying the same handler multiple times results in executing the handler only once, regardless of how many tasks notify it Source 13সোর্স 13. Handlers run in the order of the handlers section, and not in the order of the notify list Source 13সোর্স 13. In the example of the docs, the handler restarts Apache after all tasks are completed in the play Source 13সোর্স 13. The meta: flush_handlers task triggers any handlers that have been notified at that point in the play Source 13সোর্স 13. The --force-handlers option runs handlers even if a task fails Source 20সোর্স 20.

Check mode and diff mode. Ansible has two modes that validate tasks: check mode and diff mode Source 15সোর্স 15. In check mode, Ansible runs without making any changes on remote systems Source 15সোর্স 15. Modules that support check mode report the changes they would have made Source 15সোর্স 15. Modules that do not support check mode report nothing and do nothing Source 15সোর্স 15. In diff mode, Ansible provides before-and-after comparisons Source 15সোর্স 15. Check mode is just a simulation Source 15সোর্স 15. It does not generate output for tasks that use conditionals based on registered variables Source 15সোর্স 15. The --diff option can be used alone or with --check Source 15সোর্স 15. Because --diff can reveal sensitive information, you can disable it for a task with diff: false Source 15সোর্স 15. To force a task to run in normal mode even when the playbook is called with --check, set check_mode: false Source 15সোর্স 15.

Errors and blocks. When Ansible receives a non-zero return code from a command or a failure from a module, by default it stops executing on that host and continues on other hosts Source 16সোর্স 16. You can use ignore_errors to continue despite the failure Source 16সোর্স 16. The directive only works when the task can run and returns a value of failed Source 16সোর্স 16. It does not make Ansible ignore undefined variable errors, connection failures, execution issues, or syntax errors Source 16সোর্স 16. Blocks create logical groups of tasks Source 17সোর্স 17. They also offer ways to handle task errors, similar to exception handling in many programming languages Source 17সোর্স 17. Rescue blocks specify tasks to run when an earlier task in a block fails Source 17সোর্স 17. Tasks in the always section run no matter what the task status of the previous block is Source 17সোর্স 17. Errors caused by invalid task definitions and unreachable hosts do not trigger the rescue or always sections Source 17সোর্স 17.

Roles. Roles let you automatically load related vars, files, tasks, handlers, and other Ansible artifacts based on a known file structure Source 14সোর্স 14. After you group your content into roles, you can easily reuse them and share them with other users Source 14সোর্স 14. The file tasks/main.yml of a role is a list of tasks that the role provides to the play for execution Source 14সোর্স 14.

Vault and project practices. Ansible vault provides a way to encrypt and manage sensitive data such as passwords Source 26সোর্স 26. You can encrypt two types of content with Ansible Vault: variables and files Source 27সোর্স 27. To encrypt an existing file, use the ansible-vault encrypt command Source 27সোর্স 27. To view the contents of an encrypted file without editing it, use the ansible-vault view command Source 27সোর্স 27. When you run a playbook that uses a vault password stored in a file, you specify the file within the --vault-password-file flag Source 44সোর্স 44. The tips page says that you should encrypt sensitive or secret variables with Ansible Vault Source 29সোর্স 29.

The tips page says to keep your playbooks, roles, inventory, and variables files in version control Source 29সোর্স 29. It says that you can keep production separate from development, test, and staging environments by using separate inventory files or directories Source 29সোর্স 29. If one inventory holds both production and development, the developers who use it would be able to access production secrets Source 29সোর্স 29.

Testing and linting. Ansible is designed to be a fail-fast and ordered system, so it is easy to embed testing directly in playbooks Source 28সোর্স 28. Ansible resources are models of desired state, so it should not be necessary to test that services are started or packages are installed Source 28সোর্স 28. The assert module makes it very easy to validate various kinds of truth Source 28সোর্স 28. If you need to test for the existence of files that your Ansible configuration does not set declaratively, the stat module is a great choice Source 28সোর্স 28. There is no need to check the return codes of commands, because Ansible checks them automatically Source 28সোর্স 28. Check mode can serve as a drift test: with --check, Ansible reports if it thinks it would have had to make any changes to bring the system into a desired state Source 28সোর্স 28. An integration test battery should be written by your QA team if you are a production webservice Source 28সোর্স 28. It would usually not be embedded into your playbooks Source 28সোর্স 28. It does make sense to include some basic health checks into your playbooks Source 28সোর্স 28.

Ansible Lint is a command-line tool for linting playbooks, roles and collections Source 31সোর্স 31. Its main goal is to promote proven practices, patterns and behaviors while avoiding common pitfalls that can easily lead to bugs or make code harder to maintain Source 31সোর্স 31. The playbooks page says that you can use it for detailed, Ansible-specific feedback before you execute a playbook Source 10সোর্স 10. Profiles gradually increase the strictness of the rules Source 32সোর্স 32. The min profile ensures that Ansible can load content Source 32সোর্স 32. The basic profile prevents common coding issues and enforces standard styles and formatting, and it extends the min profile Source 32সোর্স 32. The --profile option specifies which rules profile to be used Source 33সোর্স 33. The --strict option returns a non-zero exit code on warnings as well as errors Source 33সোর্স 33. The -f option sets the output format, which is one of brief, full, md, json, codeclimate, quiet, pep8, and sarif Source 33সোর্স 33. The --project-dir option is the location of project/repository, autodetected based on location of configuration file Source 33সোর্স 33. The --offline option disables the installation of requirements.yml and the refreshing of schemas Source 33সোর্স 33. The docs say that you should add the project-local .ansible and .cache folders to .gitignore Source 33সোর্স 33.

The rule name[play] says that all plays should be named Source 34সোর্স 34. The rule name[missing] says that all tasks should be named Source 34সোর্স 34. The rule name[casing] says that all names should start with an uppercase letter for languages that support it Source 34সোর্স 34. The rule no-changed-when checks that tasks return changes to results or conditions Source 35সোর্স 35. The rule risky-file-permissions is triggered by various modules that could end up creating new files on disk with permissions that might be too open, or unpredictable Source 36সোর্স 36.

Molecule is an Ansible testing framework designed for developing and testing Ansible collections, playbooks, and roles Source 37সোর্স 37. It leverages standard Ansible features including inventory, playbooks, and collections to provide flexible testing workflows Source 37সোর্স 37.

সহজ English

The inventory. Ansible automates tasks on managed nodes, or hosts, by using a list or group of lists known as inventory Source 6সোর্স 6. Your inventory defines the managed nodes you automate and the variables associated with those hosts Source 6সোর্স 6. You can also specify groups Source 6সোর্স 6. The most common formats are INI and YAML, because Ansible includes built-in support for them Source 6সোর্স 6. You can pass another inventory source at the command line with -i Source 6সোর্স 6. Even if you define no groups, Ansible creates two default groups, all and ungrouped Source 6সোর্স 6. The all group contains every host Source 6সোর্স 6. The ungrouped group contains all hosts that do not belong to any other group Source 6সোর্স 6.

To build an inventory file, you add a new [myhosts] group Source 3সোর্স 3. You specify the IP address or fully qualified domain name (FQDN) of each host system Source 3সোর্স 3. The docs check an inventory with ansible-inventory -i inventory.ini --list Source 3সোর্স 3, and they ping a group with ansible myhosts -m ping -i inventory.ini Source 3সোর্স 3. With an inventory file, Ansible can manage a large number of hosts with a single command Source 3সোর্স 3.

A host does not need a remote connection. The local connection plugin allows Ansible to execute tasks on the controller instead of on a remote host Source 7সোর্স 7. Most Ansible modules that run in a POSIX environment need a Python interpreter on the target host Source 8সোর্স 8. Unless you configure it, Ansible tries to discover one the first time that it runs a Python module for that host Source 8সোর্স 8. The ansible_python_interpreter variable specifies the target host Python path Source 6সোর্স 6. The default value auto searches the configurable list of common Python interpreter paths Source 8সোর্স 8. It issues a warning that future installation of another Python interpreter could alter the one chosen Source 8সোর্স 8. The value auto_silent does not issue warnings Source 8সোর্স 8.

Playbooks, plays, tasks, and modules. Playbooks are automation blueprints, in YAML format, that Ansible uses to deploy and configure managed nodes Source 4সোর্স 4. A playbook is a list of plays that define the order in which Ansible performs operations, from top to bottom, to achieve an overall goal Source 4সোর্স 4. A play is an ordered list of tasks that maps to managed nodes in an inventory Source 4সোর্স 4. A task is a reference to a single module that defines the operations that Ansible performs Source 4সোর্স 4. A module is a unit of code or binary that Ansible runs on managed nodes Source 4সোর্স 4. Each task calls an Ansible module Source 10সোর্স 10. You express playbooks in YAML with a minimum of syntax Source 10সোর্স 10.

A playbook runs in order from top to bottom Source 10সোর্স 10. At a minimum, each play defines the managed nodes to target, using a pattern, and at least one task to execute Source 10সোর্স 10. By default, Ansible executes each task in order, one at a time, against all machines that the host pattern matches Source 10সোর্স 10. For Ansible 2.10 and later, you should use the fully-qualified collection name (FQCN) in your playbooks Source 10সোর্স 10. The tips page says to use fully qualified collection names to avoid ambiguity in which collection to search for the correct module or plugin for each task Source 29সোর্স 29. The tips page also says to always name plays, tasks, and blocks Source 29সোর্স 29, and to always mention the state of a module Source 29সোর্স 29.

To run a playbook, use the ansible-playbook command Source 10সোর্স 10. When you run a playbook, Ansible returns the name lines of your plays and tasks Source 10সোর্স 10. It also returns whether each task has succeeded or failed on each machine, and whether each task has made a change on each machine Source 10সোর্স 10. At the bottom, it gives a summary of the nodes that were targeted and how they performed Source 10সোর্স 10. The ansible-playbook command can verify a playbook with --check, --diff, --list-hosts, --list-tasks, and --syntax-check Source 10সোর্স 10. --syntax-check performs a syntax check on the playbook, but does not execute it Source 20সোর্স 20. --list-tasks lists all tasks that would be executed Source 20সোর্স 20. --list-hosts outputs a list of matching hosts, and does not execute anything else Source 20সোর্স 20.

The modules of the tutorial. The file module sets attributes of files, directories, or symlinks and their targets Source 21সোর্স 21. With state: directory, the target is a directory, and if needed all intermediate subdirectories are created, using the supplied permissions Source 21সোর্স 21. Modes are octal numbers, and for consistent results, you should quote octal numbers so that Ansible receives a string Source 21সোর্স 21. The copy module copies a file or a directory structure from the local or remote machine to a location on the remote machine Source 22সোর্স 22. When you use content instead of src, it sets the contents of a file directly to the given value Source 22সোর্স 22. It works only when dest is a file, and it creates the file if it does not exist Source 22সোর্স 22. For the template module, templates are processed by the Jinja2 templating language Source 23সোর্স 23. Its src is the path of a Jinja2 formatted template on the Ansible controller Source 23সোর্স 23. Its dest is the location to render the template to on the remote machine Source 23সোর্স 23. The slurp module works like fetch, and it is used for fetching a base64-encoded blob containing the data in a remote file Source 24সোর্স 24. The assert module asserts that given expressions are true, with an optional custom message Source 25সোর্স 25. Its that option is a list of string expressions of the same form that you can pass to the when statement Source 25সোর্স 25.

Ansible modules normally return a data structure that you can register into a variable Source 18সোর্স 18. The key changed is a boolean indicating if the task had to make changes to the target or delegated host Source 18সোর্স 18. The key failed is a boolean that indicates if the task was failed or not Source 18সোর্স 18. The key diff holds information on differences between previous and current state Source 18সোর্স 18.

Desired state and idempotence. Most Ansible modules check whether the desired final state has already been achieved, and they exit without performing any actions if it has Source 10সোর্স 10. Modules that behave this way are idempotent Source 10সোর্স 10. An operation is idempotent if the result of performing it once is exactly the same as the result of performing it repeatedly without any intervening actions Source 19সোর্স 19. Not all playbooks and not all modules behave this way Source 10সোর্স 10.

The shell and command modules run arbitrary commands, and they do not naturally detect if a change has occurred Source 35সোর্স 35. With changed_when, you define when a task has changed a remote node Source 16সোর্স 16. That lets you determine, based on return codes or output, whether a change should be reported in the statistics and whether a handler should be triggered Source 16সোর্স 16. With failed_when, you define what failure means in each task Source 16সোর্স 16.

Variables, facts, and templates. Ansible uses variables to manage differences between systems Source 11সোর্স 11. You can define variables in your playbooks, in your inventory, in reusable files or roles, or at the command line Source 11সোর্স 11. You can also create a variable during a run by registering the return value of a task Source 11সোর্স 11. Ansible uses Jinja2 templating to enable dynamic expressions and access to variables and facts Source 12সোর্স 12. You can use templating with the template module Source 12সোর্স 12. Facts are things that are discovered about remote nodes Source 19সোর্স 19. Ansible discovers them when it runs plays, by executing the internal setup module on the remote nodes Source 19সোর্স 19. Fact gathering can be disabled to save time if it is not needed Source 19সোর্স 19.

Handlers. Sometimes you want a task to run only when a change is made on a machine Source 13সোর্স 13. Handlers are tasks that only run when notified Source 13সোর্স 13. A task uses the notify keyword to instruct one or more handlers to execute Source 13সোর্স 13. The keyword accepts a list of handler names that are notified on a task change Source 13সোর্স 13. Notifying the same handler multiple times results in executing the handler only once, regardless of how many tasks notify it Source 13সোর্স 13. Handlers run in the order of the handlers section, and not in the order of the notify list Source 13সোর্স 13. In the example of the docs, the handler restarts Apache after all tasks are completed in the play Source 13সোর্স 13. The meta: flush_handlers task triggers any handlers that have been notified at that point in the play Source 13সোর্স 13. The --force-handlers option runs handlers even if a task fails Source 20সোর্স 20.

Check mode and diff mode. Ansible has two modes that validate tasks: check mode and diff mode Source 15সোর্স 15. In check mode, Ansible runs without making any changes on remote systems Source 15সোর্স 15. Modules that support check mode report the changes they would have made Source 15সোর্স 15. Modules that do not support check mode report nothing and do nothing Source 15সোর্স 15. In diff mode, Ansible provides before-and-after comparisons Source 15সোর্স 15. Check mode is just a simulation Source 15সোর্স 15. It does not generate output for tasks that use conditionals based on registered variables Source 15সোর্স 15. The --diff option can be used alone or with --check Source 15সোর্স 15. Because --diff can reveal sensitive information, you can disable it for a task with diff: false Source 15সোর্স 15. To force a task to run in normal mode even when the playbook is called with --check, set check_mode: false Source 15সোর্স 15.

Errors and blocks. When Ansible receives a non-zero return code from a command or a failure from a module, by default it stops executing on that host and continues on other hosts Source 16সোর্স 16. You can use ignore_errors to continue despite the failure Source 16সোর্স 16. The directive only works when the task can run and returns a value of failed Source 16সোর্স 16. It does not make Ansible ignore undefined variable errors, connection failures, execution issues, or syntax errors Source 16সোর্স 16. Blocks create logical groups of tasks Source 17সোর্স 17. They also offer ways to handle task errors, similar to exception handling in many programming languages Source 17সোর্স 17. Rescue blocks specify tasks to run when an earlier task in a block fails Source 17সোর্স 17. Tasks in the always section run no matter what the task status of the previous block is Source 17সোর্স 17. Errors caused by invalid task definitions and unreachable hosts do not trigger the rescue or always sections Source 17সোর্স 17.

Roles. Roles let you automatically load related vars, files, tasks, handlers, and other Ansible artifacts based on a known file structure Source 14সোর্স 14. After you group your content into roles, you can easily reuse them and share them with other users Source 14সোর্স 14. The file tasks/main.yml of a role is a list of tasks that the role provides to the play for execution Source 14সোর্স 14.

Vault and project practices. Ansible vault provides a way to encrypt and manage sensitive data such as passwords Source 26সোর্স 26. You can encrypt two types of content with Ansible Vault: variables and files Source 27সোর্স 27. To encrypt an existing file, use the ansible-vault encrypt command Source 27সোর্স 27. To view the contents of an encrypted file without editing it, use the ansible-vault view command Source 27সোর্স 27. When you run a playbook that uses a vault password stored in a file, you specify the file within the --vault-password-file flag Source 44সোর্স 44. The tips page says that you should encrypt sensitive or secret variables with Ansible Vault Source 29সোর্স 29.

The tips page says to keep your playbooks, roles, inventory, and variables files in version control Source 29সোর্স 29. It says that you can keep production separate from development, test, and staging environments by using separate inventory files or directories Source 29সোর্স 29. If one inventory holds both production and development, the developers who use it would be able to access production secrets Source 29সোর্স 29.

Testing and linting. Ansible is designed to be a fail-fast and ordered system, so it is easy to embed testing directly in playbooks Source 28সোর্স 28. Ansible resources are models of desired state, so it should not be necessary to test that services are started or packages are installed Source 28সোর্স 28. The assert module makes it very easy to validate various kinds of truth Source 28সোর্স 28. If you need to test for the existence of files that your Ansible configuration does not set declaratively, the stat module is a great choice Source 28সোর্স 28. There is no need to check the return codes of commands, because Ansible checks them automatically Source 28সোর্স 28. Check mode can serve as a drift test: with --check, Ansible reports if it thinks it would have had to make any changes to bring the system into a desired state Source 28সোর্স 28. An integration test battery should be written by your QA team if you are a production webservice Source 28সোর্স 28. It would usually not be embedded into your playbooks Source 28সোর্স 28. It does make sense to include some basic health checks into your playbooks Source 28সোর্স 28.

Ansible Lint is a command-line tool for linting playbooks, roles and collections Source 31সোর্স 31. Its main goal is to promote proven practices, patterns and behaviors while avoiding common pitfalls that can easily lead to bugs or make code harder to maintain Source 31সোর্স 31. The playbooks page says that you can use it for detailed, Ansible-specific feedback before you execute a playbook Source 10সোর্স 10. Profiles gradually increase the strictness of the rules Source 32সোর্স 32. The min profile ensures that Ansible can load content Source 32সোর্স 32. The basic profile prevents common coding issues and enforces standard styles and formatting, and it extends the min profile Source 32সোর্স 32. The --profile option specifies which rules profile to be used Source 33সোর্স 33. The --strict option returns a non-zero exit code on warnings as well as errors Source 33সোর্স 33. The -f option sets the output format, which is one of brief, full, md, json, codeclimate, quiet, pep8, and sarif Source 33সোর্স 33. The --project-dir option is the location of project/repository, autodetected based on location of configuration file Source 33সোর্স 33. The --offline option disables the installation of requirements.yml and the refreshing of schemas Source 33সোর্স 33. The docs say that you should add the project-local .ansible and .cache folders to .gitignore Source 33সোর্স 33.

The rule name[play] says that all plays should be named Source 34সোর্স 34. The rule name[missing] says that all tasks should be named Source 34সোর্স 34. The rule name[casing] says that all names should start with an uppercase letter for languages that support it Source 34সোর্স 34. The rule no-changed-when checks that tasks return changes to results or conditions Source 35সোর্স 35. The rule risky-file-permissions is triggered by various modules that could end up creating new files on disk with permissions that might be too open, or unpredictable Source 36সোর্স 36.

Molecule is an Ansible testing framework designed for developing and testing Ansible collections, playbooks, and roles Source 37সোর্স 37. It leverages standard Ansible features including inventory, playbooks, and collections to provide flexible testing workflows Source 37সোর্স 37.

বাংলা ব্যাখ্যা

inventory। Ansible managed node বা host-এর ওপর কাজ automate করে inventory নামে পরিচিত একটা তালিকা বা তালিকার গুচ্ছ ব্যবহার করে Source 6সোর্স 6। আপনার inventory ঠিক করে আপনি কোন managed node automate করেন, আর সেই host-গুলোর সঙ্গে যুক্ত variable Source 6সোর্স 6। আপনি group-ও ঠিক করতে পারেন Source 6সোর্স 6। সবচেয়ে প্রচলিত format INI আর YAML, কারণ Ansible-এ এগুলোর জন্য built-in সমর্থন আছে Source 6সোর্স 6। আপনি command line-এ -i দিয়ে অন্য inventory source দিতে পারেন Source 6সোর্স 6। আপনি কোনো group না বানালেও Ansible দুটো default group বানায়, all আর ungrouped Source 6সোর্স 6। all group-এ প্রতিটা host আছে Source 6সোর্স 6। ungrouped group-এ আছে সেই সব host, যারা অন্য কোনো group-এর নয় Source 6সোর্স 6।

একটা inventory file বানাতে আপনি একটা নতুন [myhosts] group যোগ করেন Source 3সোর্স 3। আপনি প্রতিটা host system-এর IP address বা fully qualified domain name (FQDN) ঠিক করেন Source 3সোর্স 3। docs একটা inventory যাচাই করে ansible-inventory -i inventory.ini --list দিয়ে Source 3সোর্স 3, আর একটা group ping করে ansible myhosts -m ping -i inventory.ini দিয়ে Source 3সোর্স 3। একটা inventory file দিয়ে Ansible একটাই command-এ বহু host পরিচালনা করতে পারে Source 3সোর্স 3।

একটা host-এর জন্য দূরের connection লাগে না। local connection plugin Ansible-কে দূরের host-এর বদলে controller-এ task চালাতে দেয় Source 7সোর্স 7। POSIX পরিবেশে চলা বেশির ভাগ Ansible module-এর জন্য target host-এ একটা Python interpreter লাগে Source 8সোর্স 8। আপনি ঠিক না করলে Ansible সেই host-এর জন্য প্রথম Python module চালানোর সময় একটা খুঁজে নিতে চেষ্টা করে Source 8সোর্স 8। ansible_python_interpreter variable একটা target host-এর Python path ঠিক করে Source 6সোর্স 6। default মান auto সাধারণ Python interpreter path-এর কনফিগার করা যায় এমন তালিকায় খোঁজে Source 8সোর্স 8। সে একটা সতর্কবার্তা দেয় যে ভবিষ্যতে আরেকটা Python interpreter install হলে বেছে নেওয়াটা বদলে যেতে পারে Source 8সোর্স 8। auto_silent মান কোনো সতর্কবার্তা দেয় না Source 8সোর্স 8।

playbook, play, task আর module। playbook হলো YAML format-এর automation blueprint, যা Ansible managed node deploy ও configure করতে ব্যবহার করে Source 4সোর্স 4। একটা playbook হলো play-এর একটা তালিকা, যা ঠিক করে একটা সামগ্রিক লক্ষ্যে পৌঁছাতে Ansible উপর থেকে নিচে কোন ক্রমে কাজ করবে Source 4সোর্স 4। একটা play হলো task-এর একটা ক্রমানুসারে তালিকা, যা একটা inventory-র managed node-এর সঙ্গে মেলানো Source 4সোর্স 4। একটা task হলো একটা একক module-এর রেফারেন্স, যা ঠিক করে Ansible কী কী কাজ করবে Source 4সোর্স 4। একটা module হলো এক টুকরো code বা binary, যা Ansible managed node-এ চালায় Source 4সোর্স 4। প্রতিটা task একটা Ansible module ডাকে Source 10সোর্স 10। আপনি playbook লেখেন YAML-এ, ন্যূনতম syntax দিয়ে Source 10সোর্স 10।

একটা playbook উপর থেকে নিচে ক্রমানুসারে চলে Source 10সোর্স 10। ন্যূনতমভাবে প্রতিটা play ঠিক করে, একটা pattern দিয়ে কোন managed node লক্ষ্য, আর অন্তত একটা task Source 10সোর্স 10। by default Ansible প্রতিটা task ক্রমানুসারে, একবারে একটা করে, host pattern-এর সঙ্গে মেলা সব মেশিনে চালায় Source 10সোর্স 10। Ansible 2.10 আর তার পরে আপনার playbook-এ fully-qualified collection name (FQCN) ব্যবহার করা উচিত Source 10সোর্স 10। tips page বলে, প্রতিটা task-এর সঠিক module বা plugin কোন collection-এ খুঁজতে হবে সেই অস্পষ্টতা এড়াতে fully qualified collection name ব্যবহার করতে Source 29সোর্স 29। tips page আরও বলে, সবসময় play, task আর block-এর নাম দিতে Source 29সোর্স 29, আর একটা module-এর state উল্লেখ করতে Source 29সোর্স 29।

একটা playbook চালাতে ব্যবহার করুন ansible-playbook command Source 10সোর্স 10। একটা playbook চালালে Ansible আপনার play আর task-এর নামের লাইন ফেরত দেয় Source 10সোর্স 10। সে এও ফেরত দেয় প্রতিটা মেশিনে প্রতিটা task সফল হয়েছে না ব্যর্থ, আর প্রতিটা মেশিনে প্রতিটা task কোনো পরিবর্তন করেছে কি না Source 10সোর্স 10। শেষে সে দেয় কোন node লক্ষ্য ছিল আর সেগুলো কেমন করেছে, তার একটা সারাংশ Source 10সোর্স 10। ansible-playbook command একটা playbook যাচাই করতে পারে --check, --diff, --list-hosts, --list-tasks আর --syntax-check দিয়ে Source 10সোর্স 10। --syntax-check playbook-এর syntax যাচাই করে, কিন্তু সেটা চালায় না Source 20সোর্স 20। --list-tasks যে সব task চালানো হতো তার তালিকা দেয় Source 20সোর্স 20। --list-hosts মেলা host-এর তালিকা দেয়, আর আর কিছু চালায় না Source 20সোর্স 20।

টিউটোরিয়ালের module-গুলো। file module file, directory বা symlink আর তাদের লক্ষ্যের attribute ঠিক করে Source 21সোর্স 21। state: directory দিলে লক্ষ্যটা একটা directory, আর দরকার হলে মাঝের সব subdirectory দেওয়া permission দিয়ে তৈরি হয় Source 21সোর্স 21। mode হলো octal সংখ্যা, আর সঙ্গতিপূর্ণ ফলের জন্য সেগুলো quote করা উচিত Source 21সোর্স 21। copy module একটা file বা directory-র কাঠামো স্থানীয় বা দূরের মেশিন থেকে দূরের মেশিনের একটা জায়গায় কপি করে Source 22সোর্স 22। src-এর বদলে content ব্যবহার করলে এটা একটা file-এর content সরাসরি দেওয়া মানে বসায় Source 22সোর্স 22। এটা কাজ করে শুধু dest একটা file হলে, আর file না থাকলে সেটা তৈরি করে Source 22সোর্স 22। template module-এর ক্ষেত্রে template প্রক্রিয়া করা হয় Jinja2 templating language দিয়ে Source 23সোর্স 23। এর src হলো Ansible controller-এ থাকা একটা Jinja2 format-এর template-এর path Source 23সোর্স 23। এর dest হলো দূরের মেশিনে সেই জায়গা, যেখানে template render হবে Source 23সোর্স 23। slurp module fetch-এর মতো কাজ করে, আর একটা দূরের file-এর data ধরা base64-encoded blob আনে Source 24সোর্স 24। assert module যাচাই করে দেওয়া expression-গুলো সত্য কি না, সঙ্গে ঐচ্ছিক custom বার্তা Source 25সোর্স 25। এর that option হলো একই ধরনের string expression-এর একটা তালিকা, যা আপনি when statement-এ দিতে পারেন Source 25সোর্স 25।

Ansible module সাধারণত একটা data structure ফেরত দেয়, যা আপনি একটা variable-এ register করতে পারেন Source 18সোর্স 18। changed key একটা boolean, যা বলে task-টাকে লক্ষ্যে পরিবর্তন করতে হয়েছে কি না Source 18সোর্স 18। failed key একটা boolean, যা বলে task ব্যর্থ হয়েছে কি না Source 18সোর্স 18। diff key আগের আর বর্তমান state-এর পার্থক্যের তথ্য ধরে Source 18সোর্স 18।

কাঙ্ক্ষিত অবস্থা আর idempotence। বেশির ভাগ Ansible module যাচাই করে কাঙ্ক্ষিত চূড়ান্ত অবস্থা আগেই অর্জিত হয়েছে কি না, আর হয়ে থাকলে কোনো কাজ না করেই exit করে Source 10সোর্স 10। যে module এভাবে আচরণ করে, তারা idempotent Source 10সোর্স 10। একটা operation idempotent, যদি সেটা একবার করার ফল ঠিক তা-ই হয়, যা মাঝখানে কিছু না করে বারবার করলে হয় Source 19সোর্স 19। সব playbook আর সব module এভাবে আচরণ করে না Source 10সোর্স 10।

shell আর command module যেকোনো command চালায়, আর তারা স্বাভাবিকভাবে ধরতে পারে না কোনো পরিবর্তন হয়েছে কি না Source 35সোর্স 35। changed_when দিয়ে আপনি ঠিক করেন, কখন একটা task একটা দূরের node বদলেছে Source 16সোর্স 16। এটা আপনাকে return code বা output-এর ভিত্তিতে ঠিক করতে দেয়, পরিবর্তন statistic-এ জানানো উচিত কি না, আর handler চালু করা উচিত কি না Source 16সোর্স 16। failed_when দিয়ে আপনি ঠিক করেন প্রতিটা task-এ ব্যর্থতার মানে কী Source 16সোর্স 16।

variable, fact আর template। Ansible বিভিন্ন system-এর পার্থক্য সামলাতে variable ব্যবহার করে Source 11সোর্স 11। আপনি variable ঠিক করতে পারেন আপনার playbook-এ, inventory-তে, পুনর্ব্যবহারযোগ্য file বা role-এ, অথবা command line-এ Source 11সোর্স 11। আপনি একটা run-এর সময়ও variable বানাতে পারেন, একটা task-এর ফেরত দেওয়া মান একটা নতুন variable হিসেবে register করে Source 11সোর্স 11। Ansible গতিশীল expression আর variable ও fact-এ প্রবেশ সম্ভব করতে Jinja2 templating ব্যবহার করে Source 12সোর্স 12। আপনি template module দিয়ে templating ব্যবহার করতে পারেন Source 12সোর্স 12। fact হলো দূরের node সম্পর্কে আবিষ্কার করা জিনিস Source 19সোর্স 19। Ansible সেগুলো আবিষ্কার করে play চালানোর সময়, দূরের node-এ ভেতরের setup module চালিয়ে Source 19সোর্স 19। দরকার না হলে সময় বাঁচাতে fact সংগ্রহ বন্ধ করা যায় Source 19সোর্স 19।

handler। কখনও কখনও আপনি চান একটা task শুধু তখনই চলুক, যখন একটা মেশিনে কোনো পরিবর্তন হয় Source 13সোর্স 13। handler হলো এমন task, যা শুধু notify করা হলে চলে Source 13সোর্স 13। একটা task এক বা একাধিক handler চালাতে বলে notify keyword দিয়ে Source 13সোর্স 13। keyword-টা handler-এর নামের এমন একটা তালিকা নেয়, যাদের task বদলালে notify করা হয় Source 13সোর্স 13। একই handler বহুবার notify করলে সেটা একবারই চলে Source 13সোর্স 13। handler চলে handlers section-এর ক্রমে, notify তালিকার ক্রমে নয় Source 13সোর্স 13। docs-এর উদাহরণে handler Apache restart করে play-এর সব task শেষ হওয়ার পর Source 13সোর্স 13। meta: flush_handlers task play-এর সেই বিন্দুতে notify হয়ে থাকা সব handler চালু করে Source 13সোর্স 13। --force-handlers option কোনো task ব্যর্থ হলেও handler চালায় Source 20সোর্স 20।

check mode আর diff mode। Ansible-এ task যাচাইয়ের দুটো mode আছে: check mode আর diff mode Source 15সোর্স 15। check mode-এ Ansible দূরের system-এ কোনো পরিবর্তন না করে চলে Source 15সোর্স 15। যে module check mode সমর্থন করে, তারা জানায় তারা কোন পরিবর্তন করত Source 15সোর্স 15। যে module check mode সমর্থন করে না, তারা কিছু জানায় না আর কিছু করে না Source 15সোর্স 15। diff mode-এ Ansible আগে-পরের তুলনা দেয় Source 15সোর্স 15। check mode শুধু একটা simulation Source 15সোর্স 15। registered variable-ভিত্তিক conditional ব্যবহার করা task-এর জন্য এটা কোনো output দেয় না Source 15সোর্স 15। --diff option একা বা --check-এর সঙ্গে ব্যবহার করা যায় Source 15সোর্স 15। --diff সংবেদনশীল তথ্য প্রকাশ করতে পারে বলে আপনি একটা task-এর জন্য diff: false দিয়ে সেটা বন্ধ করতে পারেন Source 15সোর্স 15। playbook --check দিয়ে ডাকা হলেও একটা task-কে স্বাভাবিক mode-এ চালাতে check_mode: false দিন Source 15সোর্স 15।

error আর block। Ansible কোনো command থেকে শূন্য নয় এমন return code বা কোনো module থেকে ব্যর্থতা পেলে by default সেই host-এ চালানো বন্ধ করে দেয়, আর অন্য host-এ চালিয়ে যায় Source 16সোর্স 16। ব্যর্থতা সত্ত্বেও চালিয়ে যেতে আপনি ignore_errors ব্যবহার করতে পারেন Source 16সোর্স 16। এই directive কাজ করে শুধু যখন task চলতে পারে আর failed মান ফেরত দেয় Source 16সোর্স 16। এটা undefined variable error, connection ব্যর্থতা, execution সমস্যা বা syntax error উপেক্ষা করায় না Source 16সোর্স 16। block task-কে যুক্তিসঙ্গত দলে ভাগ করে Source 17সোর্স 17। এগুলো task-এর error সামলানোর উপায়ও দেয়, যা অনেক programming language-এর exception handling-এর মতো Source 17সোর্স 17। rescue block ঠিক করে, একটা block-এর আগের কোনো task ব্যর্থ হলে কোন task চলবে Source 17সোর্স 17। always section-এর task চলে, আগের block-এর task-এর অবস্থা যা-ই হোক Source 17সোর্স 17। অবৈধ task সংজ্ঞা আর অগম্য host-এর কারণে হওয়া error rescue বা always section চালু করে না Source 17সোর্স 17।

role। role আপনাকে একটা পরিচিত file কাঠামোর ভিত্তিতে সম্পর্কিত vars, file, task, handler আর অন্য Ansible জিনিস স্বয়ংক্রিয়ভাবে load করতে দেয় Source 14সোর্স 14। আপনি content role-এ ভাগ করে নিলে সহজেই সেগুলো পুনর্ব্যবহার করতে আর অন্য ব্যবহারকারীদের সঙ্গে ভাগ করতে পারেন Source 14সোর্স 14। একটা role-এর tasks/main.yml file হলো task-এর একটা তালিকা, যা role play-কে চালানোর জন্য দেয় Source 14সোর্স 14।

Vault আর project-এর রীতি। Ansible vault পাসওয়ার্ডের মতো সংবেদনশীল data encrypt ও পরিচালনা করার একটা উপায় দেয় Source 26সোর্স 26। আপনি Ansible Vault দিয়ে দুই ধরনের content encrypt করতে পারেন: variable আর file Source 27সোর্স 27। একটা বিদ্যমান file encrypt করতে ব্যবহার করুন ansible-vault encrypt command Source 27সোর্স 27। একটা encrypted file edit না করে তার content দেখতে ব্যবহার করুন ansible-vault view command Source 27সোর্স 27। একটা file-এ রাখা vault password ব্যবহার করে এমন একটা playbook চালানোর সময় আপনি --vault-password-file flag-এ file-টা দেন Source 44সোর্স 44। tips page বলে, সংবেদনশীল বা গোপন variable Ansible Vault দিয়ে encrypt করা উচিত Source 29সোর্স 29।

tips page বলে, আপনার playbook, role, inventory আর variable file version control-এ রাখতে Source 29সোর্স 29। এটা বলে, আপনি আলাদা inventory file বা directory ব্যবহার করে production-কে development, test আর staging পরিবেশ থেকে আলাদা রাখতে পারেন Source 29সোর্স 29। একটা inventory-তে production আর development দুটোই থাকলে সেটা যারা ব্যবহার করেন সেই developer-রা production-এর secret-এ প্রবেশ করতে পারতেন Source 29সোর্স 29।

test আর lint। Ansible তৈরি fail-fast আর ক্রমানুসারে চলা system হিসেবে, তাই playbook-এর ভেতরেই সরাসরি test বসানো সহজ Source 28সোর্স 28। Ansible resource হলো কাঙ্ক্ষিত অবস্থার মডেল, তাই service চালু আছে বা package install করা আছে কি না test করার দরকার হওয়া উচিত নয় Source 28সোর্স 28। assert module নানা ধরনের সত্যতা যাচাই করা খুব সহজ করে Source 28সোর্স 28। আপনার Ansible configuration যে file-এর অস্তিত্ব ঘোষণামূলকভাবে ঠিক করে না, তা test করার দরকার হলে stat module দারুণ পছন্দ Source 28সোর্স 28। command-এর return code যাচাই করার দরকার নেই, কারণ Ansible সেগুলো আপনা থেকেই যাচাই করে Source 28সোর্স 28। check mode একটা drift test হিসেবে কাজ করতে পারে: --check দিলে Ansible জানায়, তার ধারণা অনুযায়ী system-কে কাঙ্ক্ষিত অবস্থায় আনতে তাকে কোনো পরিবর্তন করতে হতো কি না Source 28সোর্স 28। আপনি production webservice হলে একটা integration test battery আপনার QA team-এর লেখা উচিত Source 28সোর্স 28। সেটা সাধারণত আপনার playbook-এর ভেতরে বসানো হয় না Source 28সোর্স 28। playbook-এ কিছু মৌলিক health check রাখা অর্থবহ Source 28সোর্স 28।

Ansible Lint হলো playbook, role আর collection lint করার একটা command-line tool Source 31সোর্স 31। এর মূল লক্ষ্য প্রমাণিত অভ্যাস, pattern আর আচরণ উৎসাহিত করা, আর এমন সাধারণ ফাঁদ এড়ানো, যা সহজেই bug ঘটাতে বা code রক্ষণাবেক্ষণ কঠিন করতে পারে Source 31সোর্স 31। playbook page বলে, একটা playbook চালানোর আগে আপনি এটা দিয়ে বিস্তারিত, Ansible-নির্দিষ্ট মতামত পেতে পারেন Source 10সোর্স 10। profile নিয়মের কঠোরতা ধাপে ধাপে বাড়ায় Source 32সোর্স 32। min profile নিশ্চিত করে যে Ansible content load করতে পারে Source 32সোর্স 32। basic profile সাধারণ coding সমস্যা ঠেকায় আর মান ধরনের style ও formatting চাপায়, আর এটা min profile-কে বাড়ায় Source 32সোর্স 32। --profile option ঠিক করে কোন rules profile ব্যবহার করা হবে Source 33সোর্স 33। --strict option warning আর error দুটোতেই শূন্য নয় এমন exit code ফেরত দেয় Source 33সোর্স 33। -f option output format ঠিক করে, যা brief, full, md, json, codeclimate, quiet, pep8 আর sarif-এর একটা Source 33সোর্স 33। --project-dir option হলো project বা repository-র অবস্থান, যা configuration file-এর অবস্থানের ভিত্তিতে স্বয়ংক্রিয়ভাবে ধরা হয় Source 33সোর্স 33। --offline option requirements.yml-এর installation আর schema refresh বন্ধ করে Source 33সোর্স 33। docs বলে, project-স্থানীয় .ansible আর .cache folder .gitignore-এ যোগ করা উচিত Source 33সোর্স 33।

name[play] rule বলে সব play-এর নাম থাকা উচিত Source 34সোর্স 34। name[missing] rule বলে সব task-এর নাম থাকা উচিত Source 34সোর্স 34। name[casing] rule বলে যেসব ভাষা এটা সমর্থন করে, সেগুলোর জন্য সব নাম বড় হাতের অক্ষর দিয়ে শুরু হওয়া উচিত Source 34সোর্স 34। no-changed-when rule যাচাই করে task ফলাফল বা condition দিয়ে পরিবর্তন জানায় কি না Source 35সোর্স 35। risky-file-permissions rule চালু হয় এমন নানা module-এ, যা এমন permission সহ নতুন file বানাতে পারে, যা বেশি খোলা বা অনির্ভরযোগ্য হতে পারে Source 36সোর্স 36।

Molecule হলো একটা Ansible testing framework, যা Ansible collection, playbook আর role তৈরি ও test করার জন্য বানানো Source 37সোর্স 37। এটা নমনীয় testing workflow দিতে inventory, playbook আর collection-এর মতো স্ট্যান্ডার্ড Ansible বৈশিষ্ট্য কাজে লাগায় Source 37সোর্স 37।

Try it

The tutorial ran steps 1 to 8 on 2026-11-19 at 16:05 (+06) on Linux 7.0.0-43-generic, with ansible-core 2.22.0, ansible-lint 26.11.0, Python 3.14.4, and bash 5.3.9. The output on this page is from the tutorial's run. Each step ran in its own shell, in a copy of the practice folder, with a new, empty HOME. The page shows the folder of the run as /work, and the virtual environment of the tools as /venv. The runner set one variable whose name starts with ANSIBLE. It is ANSIBLE_REMOTE_TEMP, an environment variable of the setting remote_tmp, which is the temporary directory to use on targets when executing tasks Source 9সোর্স 9. It points to a folder inside the run folder. After the steps, the empty home folder held one file, ~/.cache/ansible-lint/latest.json. It is a JSON file of 3686 bytes. Its keys include tag_name, with the value v26.11.0, and html_url, with the address of a release page of ansible-lint on GitHub. No page that the tutorial read describes this file. The tutorial found no new entry in the real home folder.

All eight steps use one host, localhost, with the local connection. They need no remote host, no SSH, and no cloud account. The two playbooks write only into a folder named out next to them. Steps 6, 7, and 8 write four more files into the practice folder: bad-check.yml, lint-bad.yml, vault-pass.txt, and secrets.yml. The option --offline of ansible-lint disables the installation of requirements.yml and schema refreshing Source 33সোর্স 33. The tutorial did not use it, so step 7 may have used the network. The echo lines in the steps print the exit status of the command before them. They are the tutorial's own addition. The tutorial did not run roles, blocks, rescue, changed_when, or Molecule. The page describes them from the docs only.

The choices that no source gives are the tutorial's own: the file names, the names inside the files, the folder out, the made-up values qa, http://localhost:8080, and http://localhost:9090, the hand edit of step 5, the wrong test of step 6, the file lint-bad.yml of step 7, and the made-up passwords of step 8.

Install the tools. The docs install the minimal package for the current user with python3 -m pip install --user ansible-core Source 5সোর্স 5. The tutorial made a virtual environment of its own with Python 3.14.4, and it installed the two packages in it with pip. That is the tutorial's own choice, so that nothing lands in the system Python. On 2026-11-19 at 14:55, the install script of the tutorial asked the PyPI JSON API for the latest versions. It got ansible-core 2.22.0 and ansible-lint 26.11.0.

The script downloaded the wheel of ansible-core first. It compared the SHA-256 of the file, which starts with 8285d4cc, with the value that the PyPI JSON API lists for that file, and the two values were the same. The check has limits. The list comes from the same host as the file, and the tutorial did not check a signature. ansible-lint and the dependencies of both packages were installed by pip from PyPI over HTTPS, without hash checking.

1. Check the versions. Run:

ansible --version
ansible-lint --version

Output of the tutorial's run:

ansible [core 2.22.0]
  config file = None
  configured module search path = ['/work/home/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /venv/lib/python3.14/site-packages/ansible
  ansible collection location = /work/home/.ansible/collections:/usr/share/ansible/collections
  executable location = /venv/bin/ansible
  python version = 3.14.4 (main, Aug 20 2026, 10:41:58) [GCC 15.2.0] (/venv/bin/python3)
  jinja version = 3.1.6
  pyyaml version = 6.0.3 (with libyaml v0.2.5)
ansible-lint 26.11.0 using ansible-core:2.22.0 ansible-compat:26.11.0 ruamel-yaml:0.19.1
  • ansible --version printed the version of the package ansible-core, [core 2.22.0], and the paths that the run used. The folder of the run holds no ansible.cfg file, and the output says config file = None. The paths of the modules and the collections start with /work/home/.ansible, which is in the empty home folder of the run. The setting ANSIBLE_HOME is the default root path for Ansible config files on the controller Source 30সোর্স 30.
  • ansible-lint --version printed ansible-lint 26.11.0, and it also printed the version of ansible-core that it used, 2.22.0, and the versions of two other packages.

2. Write an inventory, and look at it. Save this as inventory.yml:

all:
  children:
    app:
      hosts:
        localhost:
          ansible_connection: local

The file defines one group, app, with one host, localhost. YAML is one of the most common inventory formats Source 6সোর্স 6. The variable ansible_connection specifies the connection type to the host, and it can be the name of any Ansible connection plugin Source 6সোর্স 6. The value local names the local connection plugin, which executes tasks on the controller instead of on a remote host Source 7সোর্স 7.

Run:

ansible-inventory -i inventory.yml --graph
ansible-inventory -i inventory.yml --list
ansible app -i inventory.yml -m ansible.builtin.ping

Output of the tutorial's run:

@all:
  |--@ungrouped:
  |--@app:
  |  |--localhost
{
    "_meta": {
        "hostvars": {
            "localhost": {
                "ansible_connection": "local"
            }
        },
        "profile": "inventory_legacy"
    },
    "all": {
        "children": [
            "ungrouped",
            "app"
        ]
    },
    "app": {
        "hosts": [
            "localhost"
        ]
    }
}
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
localhost | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/venv/bin/python3.14"
    },
    "changed": false,
    "ping": "pong"
}
  • ansible-inventory --graph printed a tree of the inventory. The --graph option creates an inventory graph, and a pattern that you supply must be a valid group name Source 38সোর্স 38. The group @all holds the groups @ungrouped and @app, and localhost is under @app. The tutorial defined no group ungrouped, and Ansible still created it. It creates the two default groups all and ungrouped, even if you define no groups Source 6সোর্স 6.
  • ansible-inventory --list printed the same inventory as JSON. The --list option outputs all hosts info, and it works as an inventory script Source 38সোর্স 38. The variable ansible_connection of localhost is under _meta and hostvars. The block _meta also has a key profile with the value inventory_legacy. No page that the tutorial read describes that key.
  • ansible app -i inventory.yml -m ansible.builtin.ping is an ad hoc command. An ad hoc command uses the /usr/bin/ansible command-line tool to automate a single task on one or more managed nodes Source 42সোর্স 42. It looks like ansible [pattern] -m [module] -a "[module options]" Source 42সোর্স 42. Here app is the pattern, and ansible.builtin.ping is the module. The ping module is a trivial test module that always returns pong on successful contact Source 39সোর্স 39. It is useful from /usr/bin/ansible to verify the ability to log in, and that a usable Python is configured Source 39সোর্স 39. The output has SUCCESS, "changed": false, and "ping": "pong".
  • The output also has a warning about the Python interpreter. Unless configured otherwise, Ansible attempts to discover a suitable Python interpreter on each target host the first time that a Python module is executed for that host Source 8সোর্স 8. The default setting auto issues a warning that a future installation of another Python interpreter could alter the one chosen Source 8সোর্স 8. In the run, discovered_interpreter_python is /venv/bin/python3.14. The tutorial did not change the setting, so the warning is in the output. It appears again in the first task of steps 3 to 6.

3. Write a playbook, and run it twice. Save this as site.yml:

- name: Write the settings of the test environment
  hosts: app
  gather_facts: false
  vars:
    env_name: qa
    base_url: http://localhost:8080
    out_dir: "{{ playbook_dir }}/out"
  tasks:
    - name: Create the output folder
      ansible.builtin.file:
        path: "{{ out_dir }}"
        state: directory
        mode: "0755"

    - name: Write the settings file
      ansible.builtin.template:
        src: settings.env.j2
        dest: "{{ out_dir }}/{{ env_name }}.env"
        mode: "0644"
      notify: Record the change

  handlers:
    - name: Record the change
      ansible.builtin.copy:
        content: "settings changed\n"
        dest: "{{ out_dir }}/changed.log"
        mode: "0644"

Save this as settings.env.j2, in a folder named templates, next to site.yml:

env={{ env_name }}
base_url={{ base_url }}

The play has two tasks and one handler:

  • hosts: app makes the play target the group app. The keyword hosts is a list of groups, hosts, or host patterns that translate into the targets of the play Source 45সোর্স 45.
  • The section vars holds three variables for the play Source 45সোর্স 45. The variable playbook_dir is the path to the directory of the current playbook Source 43সোর্স 43. So the playbook writes into a folder out next to itself.
  • The keyword gather_facts is a boolean that controls if the play will automatically run the setup task to gather facts for the hosts Source 45সোর্স 45. The tutorial sets gather_facts: false, because the playbook uses no facts. The output has no Gathering Facts task.
  • The file task creates the folder out. With state: directory, the target is a directory, and Ansible creates any missing parent folders Source 21সোর্স 21. The mode is "0755", in quotes, because you should quote octal numbers so that Ansible receives a string Source 21সোর্স 21.
  • The template task renders templates/settings.env.j2 into out/qa.env. The src is the path of a Jinja2 formatted template on the controller Source 23সোর্স 23, and dest is the location to render it to on the remote machine Source 23সোর্স 23. The template holds two Jinja2 expressions, {{ env_name }} and {{ base_url }}. Ansible uses Jinja2 templating to enable dynamic expressions and access to variables and facts Source 12সোর্স 12. In the layout of a role, the folder templates/ holds files for use with the template resource, and templates end in .j2 Source 14সোর্স 14. The tutorial uses the same names next to a playbook that is not a role, and the run shows that Ansible found the file.
  • notify: Record the change names the handler. The keyword notify is a list of handlers to notify when the task returns a changed=True status Source 45সোর্স 45. The handlers section holds tasks that do not run normally, only when notified after each section of tasks is complete Source 45সোর্স 45. The handler writes the text settings changed into out/changed.log with the copy module. When you use content instead of src, it sets the contents of a file directly to the given value Source 22সোর্স 22.
  • Every play, task, and handler has a name, and every module has its full name, ansible.builtin.<module>. The tips page says to always name plays, tasks, and blocks Source 29সোর্স 29, and to use fully qualified collection names Source 29সোর্স 29.

Run:

ansible-playbook -i inventory.yml site.yml --syntax-check
echo "syntax-check exit status: $?"
ansible-playbook -i inventory.yml site.yml --list-tasks
ansible-playbook -i inventory.yml site.yml
echo "run 1 exit status: $?"
cat out/qa.env out/changed.log
ansible-playbook -i inventory.yml site.yml
echo "run 2 exit status: $?"

Output of the tutorial's run:


playbook: site.yml
syntax-check exit status: 0

playbook: site.yml

  play #1 (app): Write the settings of the test environment	TAGS: []
    tasks:
      Create the output folder	TAGS: []
      Write the settings file	TAGS: []

PLAY [Write the settings of the test environment] ******************************

TASK [Create the output folder] ************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
changed: [localhost]

TASK [Write the settings file] *************************************************
changed: [localhost]

RUNNING HANDLER [Record the change] ********************************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

run 1 exit status: 0
env=qa
base_url=http://localhost:8080
settings changed

PLAY [Write the settings of the test environment] ******************************

TASK [Create the output folder] ************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [Write the settings file] *************************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

run 2 exit status: 0
  • --syntax-check printed playbook: site.yml, and the exit status was 0. The option performs a syntax check on the playbook, but does not execute it Source 20সোর্স 20.
  • --list-tasks printed the play and its two tasks, and it did not list the handler. The option lists all tasks that would be executed Source 20সোর্স 20.
  • The first run printed one block for each task, and each said changed. Then it printed RUNNING HANDLER [Record the change], and that said changed too. The recap says ok=3 and changed=3, and the exit status was 0. cat printed the rendered file, env=qa and base_url=http://localhost:8080, and then the log, settings changed.
  • The second run printed ok for both tasks, and it ran no handler. The recap says ok=2 and changed=0. When the system is in the state that the playbook describes, Ansible does not change anything, even if the playbook runs many times Source 1সোর্স 1. Handlers are notified when a task returns a changed=True status Source 45সোর্স 45. No task returned that status in the second run, so no handler ran.
  • The warning about the Python interpreter appears in the first task of each of the two runs, and not in --syntax-check or --list-tasks.

4. Look at a change before you make it. Run:

ansible-playbook -i inventory.yml site.yml -e base_url=http://localhost:9090 --check --diff
echo "check exit status: $?"
cat out/qa.env

Output of the tutorial's run:


PLAY [Write the settings of the test environment] ******************************

TASK [Create the output folder] ************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [Write the settings file] *************************************************
--- before: /work/out/qa.env
+++ after: /work/home/.ansible/tmp/ansible-local-7792835_4w5e4s/tmp3_5cofrv/settings.env.j2
@@ -1,2 +1,2 @@
 env=qa
-base_url=http://localhost:8080
+base_url=http://localhost:9090

changed: [localhost]

RUNNING HANDLER [Record the change] ********************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

check exit status: 0
env=qa
base_url=http://localhost:8080
  • The option -e sets additional variables as key=value Source 20সোর্স 20. Extra vars, for example -e "user=my_user", always win precedence Source 11সোর্স 11. So base_url was http://localhost:9090 in this run, and not the value of the play.
  • --check runs the playbook without making any changes on remote systems, and --diff provides before-and-after comparisons Source 15সোর্স 15. Diff mode is most common in modules that manipulate files, such as the template module Source 15সোর্স 15. In the output, only the template task has a diff: -base_url=http://localhost:8080 and +base_url=http://localhost:9090. That task said changed, and the recap says changed=1.
  • The path after +++ after: is under .ansible/tmp in the empty home folder of the run, and parts of its name change in each run. The setting DEFAULT_LOCAL_TMP is the temporary directory for Ansible to use on the controller Source 30সোর্স 30. No page that the tutorial read describes this line of the diff.
  • After the check, cat out/qa.env still printed base_url=http://localhost:8080. The check did not change the file. In check mode, Ansible runs without making any changes on remote systems Source 15সোর্স 15.
  • The handler ran, because the template task reported a change, and it printed ok. The file changed.log already held settings changed, and most modules exit without performing any actions if the desired state has been achieved Source 10সোর্স 10. The exit status of the check was 0, although it reported a change.

5. Find drift. Run:

printf 'env=changed-by-hand\n' > out/qa.env
ansible-playbook -i inventory.yml site.yml --check --diff
echo "check exit status: $?"
if ansible-playbook -i inventory.yml site.yml --check | grep -q 'changed=[1-9]'; then echo "drift found"; fi
cat out/qa.env
ansible-playbook -i inventory.yml site.yml
cat out/qa.env

Output of the tutorial's run:


PLAY [Write the settings of the test environment] ******************************

TASK [Create the output folder] ************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [Write the settings file] *************************************************
--- before: /work/out/qa.env
+++ after: /work/home/.ansible/tmp/ansible-local-7795049hhg3uy7/tmpf84rpgq4/settings.env.j2
@@ -1 +1,2 @@
-env=changed-by-hand
+env=qa
+base_url=http://localhost:8080

changed: [localhost]

RUNNING HANDLER [Record the change] ********************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

check exit status: 0
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
drift found
env=changed-by-hand

PLAY [Write the settings of the test environment] ******************************

TASK [Create the output folder] ************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [Write the settings file] *************************************************
changed: [localhost]

RUNNING HANDLER [Record the change] ********************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

env=qa
base_url=http://localhost:8080
  • The first line changes the file by hand, so that out/qa.env holds only env=changed-by-hand. It is the tutorial's own way to make the file differ from the playbook.
  • --check --diff printed a diff: -env=changed-by-hand, +env=qa, and +base_url=http://localhost:8080. The template task said changed, and the recap says changed=1. The exit status of the check was 0 again, so the exit status does not tell you if there is a difference.
  • The grep is the tutorial's own test. It looks for changed= with a count above 0 in the recap of a check run, and the echo printed drift found. The tests page says that, with --check, Ansible reports if it thinks that it would have had to make any changes to bring the system into a desired state Source 28সোর্স 28. The section of that page about this is named Check Mode As A Drift Test Source 28সোর্স 28.
  • After the check, cat still printed env=changed-by-hand. The check did not repair the file.
  • The real run repaired it. The template task said changed, the handler ran and said ok, and the recap says ok=3 and changed=1. cat printed env=qa and base_url=http://localhost:8080 again. The handler ran because a task notified it, and its own copy task had nothing to change.

6. Write a test with assert. Save this as check.yml:

- name: Check the settings file
  hosts: app
  gather_facts: false
  vars:
    out_dir: "{{ playbook_dir }}/out"
  tasks:
    - name: Read the settings file
      ansible.builtin.slurp:
        src: "{{ out_dir }}/qa.env"
      register: settings

    - name: Look at the settings file
      ansible.builtin.stat:
        path: "{{ out_dir }}/qa.env"
      register: settings_stat

    - name: Check that the file holds the settings of the qa environment
      ansible.builtin.assert:
        that:
          - "'env=qa' in (settings.content | b64decode)"
          - "'base_url=http://localhost:8080' in (settings.content | b64decode)"
          - settings_stat.stat.mode == '0644'
        success_msg: The settings are what the test expects.
        fail_msg: The settings are not what the test expects.

The playbook changes nothing. It has three tasks:

  • The slurp task reads out/qa.env. The module is used for fetching a base64-encoded blob containing the data in a remote file Source 24সোর্স 24. The keyword register is the name of the variable that will contain the task status and the module return data Source 45সোর্স 45. So settings holds the result of the slurp task.
  • The stat task registers the status of the file in settings_stat. The module retrieves facts for a file, similar to the Linux/Unix stat command Source 40সোর্স 40. Its return value mode holds the Unix permissions of the file in octal representation as a string Source 40সোর্স 40. So the test compares it with the string '0644'.
  • The assert task has three expressions in that. The option that is a list of string expressions of the same form that can be passed to the when statement Source 25সোর্স 25. The example of the slurp module uses the expression {{ mounts['content'] | b64decode }} to decode the content Source 24সোর্স 24. The first two expressions of the test do the same with settings.content, and check that the text holds env=qa and base_url=http://localhost:8080. The third checks the mode. The option success_msg is the customized message used for a successful assertion, and fail_msg is the customized message used for a failing assertion Source 25সোর্স 25.

Run:

ansible-playbook -i inventory.yml check.yml
echo "check.yml exit status: $?"
sed -e "s/'env=qa' in/'env=prod' in/" -e 's/of the qa environment/of the production environment/' check.yml > bad-check.yml
ansible-playbook -i inventory.yml bad-check.yml
echo "bad-check.yml exit status: $?"

Output of the tutorial's run:


PLAY [Check the settings file] *************************************************

TASK [Read the settings file] **************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [Look at the settings file] ***********************************************
ok: [localhost]

TASK [Check that the file holds the settings of the qa environment] ************
ok: [localhost] => {
    "changed": false,
    "msg": "The settings are what the test expects."
}

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

check.yml exit status: 0

PLAY [Check the settings file] *************************************************

TASK [Read the settings file] **************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [Look at the settings file] ***********************************************
ok: [localhost]

TASK [Check that the file holds the settings of the production environment] ****
[ERROR]: Task failed: Action failed: The settings are not what the test expects.
Origin: /work/bad-check.yml:17:7

15       register: settings_stat
16
17     - name: Check that the file holds the settings of the production environment
         ^ column 7

fatal: [localhost]: FAILED! => {
    "assertion": "'env=prod' in (settings.content | b64decode)",
    "changed": false,
    "evaluated_to": false,
    "msg": "The settings are not what the test expects."
}

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

bad-check.yml exit status: 2
  • The first run printed ok for all three tasks. The assert task printed its success_msg, The settings are what the test expects., and the exit status was 0.
  • The sed command made bad-check.yml, a copy that expects env=prod. In that run, the assert task failed. The output has fatal: [localhost]: FAILED!, the expression that failed, "evaluated_to": false, and the fail_msg. The recap says failed=1, and the exit status was 2. When a module fails, Ansible by default stops executing on that host Source 16সোর্স 16. The failed task was the last task of the play. No page that the tutorial read lists the exit statuses of ansible-playbook.
  • The failure begins with [ERROR]: Task failed: Action failed:, and the line Origin: gives the file, the line, and the column of the task, /work/bad-check.yml:17:7. No page that the tutorial read describes this format.

7. Lint the playbooks. Run:

export ANSIBLE_DEPRECATION_WARNINGS=false
ansible-lint --project-dir . site.yml check.yml
echo "lint exit status: $?"
cat > lint-bad.yml <<'YAML'
- hosts: app
  tasks:
    - ansible.builtin.command: echo hello
    - name: write a file
      ansible.builtin.copy:
        content: hello
        dest: out/lint-bad-example.txt
YAML
ansible-lint --project-dir . lint-bad.yml
echo "lint exit status: $?"

Output of the tutorial's run:


Passed: 0 failure(s), 0 warning(s) in 2 files processed of 2 encountered. Last profile that met the validation criteria was 'production'.
lint exit status: 0
WARNING  Listing 5 violation(s) that are fatal
Read documentation for instructions on how to ignore specific rule violations.

# Rule Violation Summary

  1 name profile:basic tags:idiom
  1 name profile:basic tags:idiom
  1 name profile:basic tags:idiom
  1 risky-file-permissions profile:basic tags:unpredictability
  1 no-changed-when profile:basic tags:command-shell,idempotency

Failed: 5 failure(s), 0 warning(s) in 1 files processed of 1 encountered. Last profile that met the validation criteria was 'min'.
name[play]: All plays should be named.
lint-bad.yml:1:3

name[missing]: All tasks should be named.
lint-bad.yml:3 Task/Handler: command echo hello

no-changed-when: Commands should not change things if nothing needs doing.
lint-bad.yml:3 Task/Handler: command echo hello

name[casing]: All names should start with an uppercase letter.
lint-bad.yml:4:13 Task/Handler: write a file

risky-file-permissions: File permissions unset or incorrect.
lint-bad.yml:4 Task/Handler: write a file

lint exit status: 2
  • The first command lints site.yml and check.yml. The option --project-dir is the location of project/repository Source 33সোর্স 33. The result is Passed: 0 failure(s), 0 warning(s), the last profile that the files met is production, and the exit status was 0. Profiles gradually increase the strictness of the rules as your Ansible content lifecycle matures Source 32সোর্স 32. The option --profile takes one of min, basic, moderate, safety, shared, and production Source 33সোর্স 33. The production profile ensures that content meets requirements for inclusion in Ansible Automation Platform (AAP) as validated or certified content Source 32সোর্স 32.
  • The first line of this step, export ANSIBLE_DEPRECATION_WARNINGS=false, is the tutorial's own choice. Without it, the same command printed two deprecation warnings before the result. They say that the callbacks oneline and tree have been deprecated, and that the feature will be removed from ansible-core version 2.23. Both say Origin: <unknown>. The files and the environment of the tutorial set no callback, and no page that the tutorial read says why ansible-lint printed them. The setting DEPRECATION_WARNINGS is a toggle to control the showing of deprecation warnings Source 30সোর্স 30, and its environment variable is ANSIBLE_DEPRECATION_WARNINGS Source 30সোর্স 30. This is the output of the tutorial's run for the same command, without that line:
[WARNING]: Deprecation warnings can be disabled by setting `deprecation_warnings=False` in ansible.cfg.
[DEPRECATION WARNING]: oneline has been deprecated. Use another callback plugin, or vendor and/or move the oneline callback to a collection. This feature will be removed from ansible-core version 2.23.
Origin: <unknown>

oneline

[DEPRECATION WARNING]: tree has been deprecated. Use another callback plugin, or vendor and/or move the tree callback to a collection. This feature will be removed from ansible-core version 2.23.
Origin: <unknown>

tree


Passed: 0 failure(s), 0 warning(s) in 2 files processed of 2 encountered. Last profile that met the validation criteria was 'production'.
lint exit status: 0
  • The second command lints lint-bad.yml, a file that the tutorial wrote on purpose and did not run. It has a play without a name, a task without a name that runs ansible.builtin.command, and a copy task without a mode, whose name starts with a lowercase letter. ansible-lint reported five violations, and the exit status was 2.
  • The rule name checks the names: name[play] says that all plays should be named, name[missing] that all tasks should be named, and name[casing] that all names should start with an uppercase letter for languages that support it Source 34সোর্স 34. The rule no-changed-when checks that tasks return changes to results or conditions Source 35সোর্স 35. The rule risky-file-permissions is triggered by various modules that could end up creating new files on disk with permissions that might be too open, or unpredictable Source 36সোর্স 36. The summary lists name three times, once for each of its violations.
  • The summary shows profile:basic for all five violations, and the last profile that the file met is min. The min profile ensures that Ansible can load content Source 32সোর্স 32. The basic profile prevents common coding issues and enforces standard styles and formatting Source 32সোর্স 32.
  • ansible-lint creates caches with installed roles and collections under the runtime cache directory, which is typically {project}/.ansible when it is not offline Source 33সোর্স 33. It does not clean the cache by itself Source 33সোর্স 33. The tutorial's run left one file in the empty home folder, which the intro of this section describes.

8. Encrypt a secret with Vault. Run:

printf 'made-up-vault-password\n' > vault-pass.txt
printf 'db_password: made-up-db-password\n' > secrets.yml
ansible-vault encrypt secrets.yml --vault-password-file vault-pass.txt
head -n 2 secrets.yml
grep -c 'made-up-db-password' secrets.yml
ansible-vault view secrets.yml --vault-password-file vault-pass.txt

Output of the tutorial's run:

$ANSIBLE_VAULT;1.1;AES256
31353436626163303837616632383237326136666565343433393465366663346538633966316231
0
db_password: made-up-db-password

The password and the secret of this step are made up for the tutorial.

  • ansible-vault is an encryption/decryption utility for Ansible data files Source 41সোর্স 41. The first two lines write the password file, vault-pass.txt, and the data file, secrets.yml. To store a vault password in a file, you enter the password as a string on a single line in the file Source 44সোর্স 44. The docs also say to make sure that the permissions on the file are appropriate, and not to add password files to source control Source 44সোর্স 44. The tutorial did not change the permissions of its file, which lives only in the temporary folder of the run.
  • To encrypt an existing file, you use the ansible-vault encrypt command Source 27সোর্স 27. The option --vault-password-file takes a vault password file Source 41সোর্স 41. The command printed nothing in this run.
  • head -n 2 secrets.yml printed the header line, $ANSIBLE_VAULT;1.1;AES256, and a line of hex digits. The docs show an example of encrypted content with the header $ANSIBLE_VAULT;1.1;AES256 Source 27সোর্স 27.
  • grep -c printed 0, so no line of the encrypted file holds the text made-up-db-password.
  • ansible-vault view printed db_password: made-up-db-password. To view the contents of an encrypted file without editing it, you can use the ansible-vault view command Source 27সোর্স 27. Ansible Vault can encrypt two types of content, variables and files Source 27সোর্স 27. This step encrypted a file.

সহজ English

The tutorial ran steps 1 to 8 on 2026-11-19 at 16:05 (+06) on Linux 7.0.0-43-generic, with ansible-core 2.22.0, ansible-lint 26.11.0, Python 3.14.4, and bash 5.3.9. The output on this page is from the tutorial's run. Each step ran in its own shell, in a copy of the practice folder, with a new, empty HOME. The page shows the folder of the run as /work, and the virtual environment of the tools as /venv. The runner set one variable whose name starts with ANSIBLE. It is ANSIBLE_REMOTE_TEMP, an environment variable of the setting remote_tmp, which is the temporary directory to use on targets when executing tasks Source 9সোর্স 9. It points to a folder inside the run folder. After the steps, the empty home folder held one file, ~/.cache/ansible-lint/latest.json. It is a JSON file of 3686 bytes. Its keys include tag_name, with the value v26.11.0, and html_url, with the address of a release page of ansible-lint on GitHub. No page that the tutorial read describes this file. The tutorial found no new entry in the real home folder.

All eight steps use one host, localhost, with the local connection. They need no remote host, no SSH, and no cloud account. The two playbooks write only into a folder named out next to them. Steps 6, 7, and 8 write four more files into the practice folder: bad-check.yml, lint-bad.yml, vault-pass.txt, and secrets.yml. The option --offline of ansible-lint disables the installation of requirements.yml and schema refreshing Source 33সোর্স 33. The tutorial did not use it, so step 7 may have used the network. The echo lines in the steps print the exit status of the command before them. They are the tutorial's own addition. The tutorial did not run roles, blocks, rescue, changed_when, or Molecule. The page describes them from the docs only.

The choices that no source gives are the tutorial's own: the file names, the names inside the files, the folder out, the made-up values qa, http://localhost:8080, and http://localhost:9090, the hand edit of step 5, the wrong test of step 6, the file lint-bad.yml of step 7, and the made-up passwords of step 8.

Install the tools. The docs install the minimal package for the current user with python3 -m pip install --user ansible-core Source 5সোর্স 5. The tutorial made a virtual environment of its own with Python 3.14.4, and it installed the two packages in it with pip. That is the tutorial's own choice, so that nothing lands in the system Python. On 2026-11-19 at 14:55, the install script of the tutorial asked the PyPI JSON API for the latest versions. It got ansible-core 2.22.0 and ansible-lint 26.11.0.

The script downloaded the wheel of ansible-core first. It compared the SHA-256 of the file, which starts with 8285d4cc, with the value that the PyPI JSON API lists for that file, and the two values were the same. The check has limits. The list comes from the same host as the file, and the tutorial did not check a signature. ansible-lint and the dependencies of both packages were installed by pip from PyPI over HTTPS, without hash checking.

1. Check the versions. Run:

ansible --version
ansible-lint --version

Output of the tutorial's run:

ansible [core 2.22.0]
  config file = None
  configured module search path = ['/work/home/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /venv/lib/python3.14/site-packages/ansible
  ansible collection location = /work/home/.ansible/collections:/usr/share/ansible/collections
  executable location = /venv/bin/ansible
  python version = 3.14.4 (main, Aug 20 2026, 10:41:58) [GCC 15.2.0] (/venv/bin/python3)
  jinja version = 3.1.6
  pyyaml version = 6.0.3 (with libyaml v0.2.5)
ansible-lint 26.11.0 using ansible-core:2.22.0 ansible-compat:26.11.0 ruamel-yaml:0.19.1
  • ansible --version printed the version of the package ansible-core, [core 2.22.0], and the paths that the run used. The folder of the run holds no ansible.cfg file, and the output says config file = None. The paths of the modules and the collections start with /work/home/.ansible, which is in the empty home folder of the run. The setting ANSIBLE_HOME is the default root path for Ansible config files on the controller Source 30সোর্স 30.
  • ansible-lint --version printed ansible-lint 26.11.0, and it also printed the version of ansible-core that it used, 2.22.0, and the versions of two other packages.

2. Write an inventory, and look at it. Save this as inventory.yml:

all:
  children:
    app:
      hosts:
        localhost:
          ansible_connection: local

The file defines one group, app, with one host, localhost. YAML is one of the most common inventory formats Source 6সোর্স 6. The variable ansible_connection specifies the connection type to the host, and it can be the name of any Ansible connection plugin Source 6সোর্স 6. The value local names the local connection plugin, which executes tasks on the controller instead of on a remote host Source 7সোর্স 7.

Run:

ansible-inventory -i inventory.yml --graph
ansible-inventory -i inventory.yml --list
ansible app -i inventory.yml -m ansible.builtin.ping

Output of the tutorial's run:

@all:
  |--@ungrouped:
  |--@app:
  |  |--localhost
{
    "_meta": {
        "hostvars": {
            "localhost": {
                "ansible_connection": "local"
            }
        },
        "profile": "inventory_legacy"
    },
    "all": {
        "children": [
            "ungrouped",
            "app"
        ]
    },
    "app": {
        "hosts": [
            "localhost"
        ]
    }
}
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
localhost | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/venv/bin/python3.14"
    },
    "changed": false,
    "ping": "pong"
}
  • ansible-inventory --graph printed a tree of the inventory. The --graph option creates an inventory graph, and a pattern that you supply must be a valid group name Source 38সোর্স 38. The group @all holds the groups @ungrouped and @app, and localhost is under @app. The tutorial defined no group ungrouped, and Ansible still created it. It creates the two default groups all and ungrouped, even if you define no groups Source 6সোর্স 6.
  • ansible-inventory --list printed the same inventory as JSON. The --list option outputs all hosts info, and it works as an inventory script Source 38সোর্স 38. The variable ansible_connection of localhost is under _meta and hostvars. The block _meta also has a key profile with the value inventory_legacy. No page that the tutorial read describes that key.
  • ansible app -i inventory.yml -m ansible.builtin.ping is an ad hoc command. An ad hoc command uses the /usr/bin/ansible command-line tool to automate a single task on one or more managed nodes Source 42সোর্স 42. It looks like ansible [pattern] -m [module] -a "[module options]" Source 42সোর্স 42. Here app is the pattern, and ansible.builtin.ping is the module. The ping module is a trivial test module that always returns pong on successful contact Source 39সোর্স 39. It is useful from /usr/bin/ansible to verify the ability to log in, and that a usable Python is configured Source 39সোর্স 39. The output has SUCCESS, "changed": false, and "ping": "pong".
  • The output also has a warning about the Python interpreter. Unless configured otherwise, Ansible attempts to discover a suitable Python interpreter on each target host the first time that a Python module is executed for that host Source 8সোর্স 8. The default setting auto issues a warning that a future installation of another Python interpreter could alter the one chosen Source 8সোর্স 8. In the run, discovered_interpreter_python is /venv/bin/python3.14. The tutorial did not change the setting, so the warning is in the output. It appears again in the first task of steps 3 to 6.

3. Write a playbook, and run it twice. Save this as site.yml:

- name: Write the settings of the test environment
  hosts: app
  gather_facts: false
  vars:
    env_name: qa
    base_url: http://localhost:8080
    out_dir: "{{ playbook_dir }}/out"
  tasks:
    - name: Create the output folder
      ansible.builtin.file:
        path: "{{ out_dir }}"
        state: directory
        mode: "0755"

    - name: Write the settings file
      ansible.builtin.template:
        src: settings.env.j2
        dest: "{{ out_dir }}/{{ env_name }}.env"
        mode: "0644"
      notify: Record the change

  handlers:
    - name: Record the change
      ansible.builtin.copy:
        content: "settings changed\n"
        dest: "{{ out_dir }}/changed.log"
        mode: "0644"

Save this as settings.env.j2, in a folder named templates, next to site.yml:

env={{ env_name }}
base_url={{ base_url }}

The play has two tasks and one handler:

  • hosts: app makes the play target the group app. The keyword hosts is a list of groups, hosts, or host patterns that translate into the targets of the play Source 45সোর্স 45.
  • The section vars holds three variables for the play Source 45সোর্স 45. The variable playbook_dir is the path to the directory of the current playbook Source 43সোর্স 43. So the playbook writes into a folder out next to itself.
  • The keyword gather_facts is a boolean that controls if the play will automatically run the setup task to gather facts for the hosts Source 45সোর্স 45. The tutorial sets gather_facts: false, because the playbook uses no facts. The output has no Gathering Facts task.
  • The file task creates the folder out. With state: directory, the target is a directory, and Ansible creates any missing parent folders Source 21সোর্স 21. The mode is "0755", in quotes, because you should quote octal numbers so that Ansible receives a string Source 21সোর্স 21.
  • The template task renders templates/settings.env.j2 into out/qa.env. The src is the path of a Jinja2 formatted template on the controller Source 23সোর্স 23, and dest is the location to render it to on the remote machine Source 23সোর্স 23. The template holds two Jinja2 expressions, {{ env_name }} and {{ base_url }}. Ansible uses Jinja2 templating to enable dynamic expressions and access to variables and facts Source 12সোর্স 12. In the layout of a role, the folder templates/ holds files for use with the template resource, and templates end in .j2 Source 14সোর্স 14. The tutorial uses the same names next to a playbook that is not a role, and the run shows that Ansible found the file.
  • notify: Record the change names the handler. The keyword notify is a list of handlers to notify when the task returns a changed=True status Source 45সোর্স 45. The handlers section holds tasks that do not run normally, only when notified after each section of tasks is complete Source 45সোর্স 45. The handler writes the text settings changed into out/changed.log with the copy module. When you use content instead of src, it sets the contents of a file directly to the given value Source 22সোর্স 22.
  • Every play, task, and handler has a name, and every module has its full name, ansible.builtin.<module>. The tips page says to always name plays, tasks, and blocks Source 29সোর্স 29, and to use fully qualified collection names Source 29সোর্স 29.

Run:

ansible-playbook -i inventory.yml site.yml --syntax-check
echo "syntax-check exit status: $?"
ansible-playbook -i inventory.yml site.yml --list-tasks
ansible-playbook -i inventory.yml site.yml
echo "run 1 exit status: $?"
cat out/qa.env out/changed.log
ansible-playbook -i inventory.yml site.yml
echo "run 2 exit status: $?"

Output of the tutorial's run:


playbook: site.yml
syntax-check exit status: 0

playbook: site.yml

  play #1 (app): Write the settings of the test environment	TAGS: []
    tasks:
      Create the output folder	TAGS: []
      Write the settings file	TAGS: []

PLAY [Write the settings of the test environment] ******************************

TASK [Create the output folder] ************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
changed: [localhost]

TASK [Write the settings file] *************************************************
changed: [localhost]

RUNNING HANDLER [Record the change] ********************************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

run 1 exit status: 0
env=qa
base_url=http://localhost:8080
settings changed

PLAY [Write the settings of the test environment] ******************************

TASK [Create the output folder] ************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [Write the settings file] *************************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

run 2 exit status: 0
  • --syntax-check printed playbook: site.yml, and the exit status was 0. The option performs a syntax check on the playbook, but does not execute it Source 20সোর্স 20.
  • --list-tasks printed the play and its two tasks, and it did not list the handler. The option lists all tasks that would be executed Source 20সোর্স 20.
  • The first run printed one block for each task, and each said changed. Then it printed RUNNING HANDLER [Record the change], and that said changed too. The recap says ok=3 and changed=3, and the exit status was 0. cat printed the rendered file, env=qa and base_url=http://localhost:8080, and then the log, settings changed.
  • The second run printed ok for both tasks, and it ran no handler. The recap says ok=2 and changed=0. When the system is in the state that the playbook describes, Ansible does not change anything, even if the playbook runs many times Source 1সোর্স 1. Handlers are notified when a task returns a changed=True status Source 45সোর্স 45. No task returned that status in the second run, so no handler ran.
  • The warning about the Python interpreter appears in the first task of each of the two runs, and not in --syntax-check or --list-tasks.

4. Look at a change before you make it. Run:

ansible-playbook -i inventory.yml site.yml -e base_url=http://localhost:9090 --check --diff
echo "check exit status: $?"
cat out/qa.env

Output of the tutorial's run:


PLAY [Write the settings of the test environment] ******************************

TASK [Create the output folder] ************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [Write the settings file] *************************************************
--- before: /work/out/qa.env
+++ after: /work/home/.ansible/tmp/ansible-local-7792835_4w5e4s/tmp3_5cofrv/settings.env.j2
@@ -1,2 +1,2 @@
 env=qa
-base_url=http://localhost:8080
+base_url=http://localhost:9090

changed: [localhost]

RUNNING HANDLER [Record the change] ********************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

check exit status: 0
env=qa
base_url=http://localhost:8080
  • The option -e sets additional variables as key=value Source 20সোর্স 20. Extra vars, for example -e "user=my_user", always win precedence Source 11সোর্স 11. So base_url was http://localhost:9090 in this run, and not the value of the play.
  • --check runs the playbook without making any changes on remote systems, and --diff provides before-and-after comparisons Source 15সোর্স 15. Diff mode is most common in modules that manipulate files, such as the template module Source 15সোর্স 15. In the output, only the template task has a diff: -base_url=http://localhost:8080 and +base_url=http://localhost:9090. That task said changed, and the recap says changed=1.
  • The path after +++ after: is under .ansible/tmp in the empty home folder of the run, and parts of its name change in each run. The setting DEFAULT_LOCAL_TMP is the temporary directory for Ansible to use on the controller Source 30সোর্স 30. No page that the tutorial read describes this line of the diff.
  • After the check, cat out/qa.env still printed base_url=http://localhost:8080. The check did not change the file. In check mode, Ansible runs without making any changes on remote systems Source 15সোর্স 15.
  • The handler ran, because the template task reported a change, and it printed ok. The file changed.log already held settings changed, and most modules exit without performing any actions if the desired state has been achieved Source 10সোর্স 10. The exit status of the check was 0, although it reported a change.

5. Find drift. Run:

printf 'env=changed-by-hand\n' > out/qa.env
ansible-playbook -i inventory.yml site.yml --check --diff
echo "check exit status: $?"
if ansible-playbook -i inventory.yml site.yml --check | grep -q 'changed=[1-9]'; then echo "drift found"; fi
cat out/qa.env
ansible-playbook -i inventory.yml site.yml
cat out/qa.env

Output of the tutorial's run:


PLAY [Write the settings of the test environment] ******************************

TASK [Create the output folder] ************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [Write the settings file] *************************************************
--- before: /work/out/qa.env
+++ after: /work/home/.ansible/tmp/ansible-local-7795049hhg3uy7/tmpf84rpgq4/settings.env.j2
@@ -1 +1,2 @@
-env=changed-by-hand
+env=qa
+base_url=http://localhost:8080

changed: [localhost]

RUNNING HANDLER [Record the change] ********************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

check exit status: 0
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
drift found
env=changed-by-hand

PLAY [Write the settings of the test environment] ******************************

TASK [Create the output folder] ************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [Write the settings file] *************************************************
changed: [localhost]

RUNNING HANDLER [Record the change] ********************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

env=qa
base_url=http://localhost:8080
  • The first line changes the file by hand, so that out/qa.env holds only env=changed-by-hand. It is the tutorial's own way to make the file differ from the playbook.
  • --check --diff printed a diff: -env=changed-by-hand, +env=qa, and +base_url=http://localhost:8080. The template task said changed, and the recap says changed=1. The exit status of the check was 0 again, so the exit status does not tell you if there is a difference.
  • The grep is the tutorial's own test. It looks for changed= with a count above 0 in the recap of a check run, and the echo printed drift found. The tests page says that, with --check, Ansible reports if it thinks that it would have had to make any changes to bring the system into a desired state Source 28সোর্স 28. The section of that page about this is named Check Mode As A Drift Test Source 28সোর্স 28.
  • After the check, cat still printed env=changed-by-hand. The check did not repair the file.
  • The real run repaired it. The template task said changed, the handler ran and said ok, and the recap says ok=3 and changed=1. cat printed env=qa and base_url=http://localhost:8080 again. The handler ran because a task notified it, and its own copy task had nothing to change.

6. Write a test with assert. Save this as check.yml:

- name: Check the settings file
  hosts: app
  gather_facts: false
  vars:
    out_dir: "{{ playbook_dir }}/out"
  tasks:
    - name: Read the settings file
      ansible.builtin.slurp:
        src: "{{ out_dir }}/qa.env"
      register: settings

    - name: Look at the settings file
      ansible.builtin.stat:
        path: "{{ out_dir }}/qa.env"
      register: settings_stat

    - name: Check that the file holds the settings of the qa environment
      ansible.builtin.assert:
        that:
          - "'env=qa' in (settings.content | b64decode)"
          - "'base_url=http://localhost:8080' in (settings.content | b64decode)"
          - settings_stat.stat.mode == '0644'
        success_msg: The settings are what the test expects.
        fail_msg: The settings are not what the test expects.

The playbook changes nothing. It has three tasks:

  • The slurp task reads out/qa.env. The module is used for fetching a base64-encoded blob containing the data in a remote file Source 24সোর্স 24. The keyword register is the name of the variable that will contain the task status and the module return data Source 45সোর্স 45. So settings holds the result of the slurp task.
  • The stat task registers the status of the file in settings_stat. The module retrieves facts for a file, similar to the Linux/Unix stat command Source 40সোর্স 40. Its return value mode holds the Unix permissions of the file in octal representation as a string Source 40সোর্স 40. So the test compares it with the string '0644'.
  • The assert task has three expressions in that. The option that is a list of string expressions of the same form that can be passed to the when statement Source 25সোর্স 25. The example of the slurp module uses the expression {{ mounts['content'] | b64decode }} to decode the content Source 24সোর্স 24. The first two expressions of the test do the same with settings.content, and check that the text holds env=qa and base_url=http://localhost:8080. The third checks the mode. The option success_msg is the customized message used for a successful assertion, and fail_msg is the customized message used for a failing assertion Source 25সোর্স 25.

Run:

ansible-playbook -i inventory.yml check.yml
echo "check.yml exit status: $?"
sed -e "s/'env=qa' in/'env=prod' in/" -e 's/of the qa environment/of the production environment/' check.yml > bad-check.yml
ansible-playbook -i inventory.yml bad-check.yml
echo "bad-check.yml exit status: $?"

Output of the tutorial's run:


PLAY [Check the settings file] *************************************************

TASK [Read the settings file] **************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [Look at the settings file] ***********************************************
ok: [localhost]

TASK [Check that the file holds the settings of the qa environment] ************
ok: [localhost] => {
    "changed": false,
    "msg": "The settings are what the test expects."
}

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

check.yml exit status: 0

PLAY [Check the settings file] *************************************************

TASK [Read the settings file] **************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [Look at the settings file] ***********************************************
ok: [localhost]

TASK [Check that the file holds the settings of the production environment] ****
[ERROR]: Task failed: Action failed: The settings are not what the test expects.
Origin: /work/bad-check.yml:17:7

15       register: settings_stat
16
17     - name: Check that the file holds the settings of the production environment
         ^ column 7

fatal: [localhost]: FAILED! => {
    "assertion": "'env=prod' in (settings.content | b64decode)",
    "changed": false,
    "evaluated_to": false,
    "msg": "The settings are not what the test expects."
}

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

bad-check.yml exit status: 2
  • The first run printed ok for all three tasks. The assert task printed its success_msg, The settings are what the test expects., and the exit status was 0.
  • The sed command made bad-check.yml, a copy that expects env=prod. In that run, the assert task failed. The output has fatal: [localhost]: FAILED!, the expression that failed, "evaluated_to": false, and the fail_msg. The recap says failed=1, and the exit status was 2. When a module fails, Ansible by default stops executing on that host Source 16সোর্স 16. The failed task was the last task of the play. No page that the tutorial read lists the exit statuses of ansible-playbook.
  • The failure begins with [ERROR]: Task failed: Action failed:, and the line Origin: gives the file, the line, and the column of the task, /work/bad-check.yml:17:7. No page that the tutorial read describes this format.

7. Lint the playbooks. Run:

export ANSIBLE_DEPRECATION_WARNINGS=false
ansible-lint --project-dir . site.yml check.yml
echo "lint exit status: $?"
cat > lint-bad.yml <<'YAML'
- hosts: app
  tasks:
    - ansible.builtin.command: echo hello
    - name: write a file
      ansible.builtin.copy:
        content: hello
        dest: out/lint-bad-example.txt
YAML
ansible-lint --project-dir . lint-bad.yml
echo "lint exit status: $?"

Output of the tutorial's run:


Passed: 0 failure(s), 0 warning(s) in 2 files processed of 2 encountered. Last profile that met the validation criteria was 'production'.
lint exit status: 0
WARNING  Listing 5 violation(s) that are fatal
Read documentation for instructions on how to ignore specific rule violations.

# Rule Violation Summary

  1 name profile:basic tags:idiom
  1 name profile:basic tags:idiom
  1 name profile:basic tags:idiom
  1 risky-file-permissions profile:basic tags:unpredictability
  1 no-changed-when profile:basic tags:command-shell,idempotency

Failed: 5 failure(s), 0 warning(s) in 1 files processed of 1 encountered. Last profile that met the validation criteria was 'min'.
name[play]: All plays should be named.
lint-bad.yml:1:3

name[missing]: All tasks should be named.
lint-bad.yml:3 Task/Handler: command echo hello

no-changed-when: Commands should not change things if nothing needs doing.
lint-bad.yml:3 Task/Handler: command echo hello

name[casing]: All names should start with an uppercase letter.
lint-bad.yml:4:13 Task/Handler: write a file

risky-file-permissions: File permissions unset or incorrect.
lint-bad.yml:4 Task/Handler: write a file

lint exit status: 2
  • The first command lints site.yml and check.yml. The option --project-dir is the location of project/repository Source 33সোর্স 33. The result is Passed: 0 failure(s), 0 warning(s), the last profile that the files met is production, and the exit status was 0. Profiles gradually increase the strictness of the rules as your Ansible content lifecycle matures Source 32সোর্স 32. The option --profile takes one of min, basic, moderate, safety, shared, and production Source 33সোর্স 33. The production profile ensures that content meets requirements for inclusion in Ansible Automation Platform (AAP) as validated or certified content Source 32সোর্স 32.
  • The first line of this step, export ANSIBLE_DEPRECATION_WARNINGS=false, is the tutorial's own choice. Without it, the same command printed two deprecation warnings before the result. They say that the callbacks oneline and tree have been deprecated, and that the feature will be removed from ansible-core version 2.23. Both say Origin: <unknown>. The files and the environment of the tutorial set no callback, and no page that the tutorial read says why ansible-lint printed them. The setting DEPRECATION_WARNINGS is a toggle to control the showing of deprecation warnings Source 30সোর্স 30, and its environment variable is ANSIBLE_DEPRECATION_WARNINGS Source 30সোর্স 30. This is the output of the tutorial's run for the same command, without that line:
[WARNING]: Deprecation warnings can be disabled by setting `deprecation_warnings=False` in ansible.cfg.
[DEPRECATION WARNING]: oneline has been deprecated. Use another callback plugin, or vendor and/or move the oneline callback to a collection. This feature will be removed from ansible-core version 2.23.
Origin: <unknown>

oneline

[DEPRECATION WARNING]: tree has been deprecated. Use another callback plugin, or vendor and/or move the tree callback to a collection. This feature will be removed from ansible-core version 2.23.
Origin: <unknown>

tree


Passed: 0 failure(s), 0 warning(s) in 2 files processed of 2 encountered. Last profile that met the validation criteria was 'production'.
lint exit status: 0
  • The second command lints lint-bad.yml, a file that the tutorial wrote on purpose and did not run. It has a play without a name, a task without a name that runs ansible.builtin.command, and a copy task without a mode, whose name starts with a lowercase letter. ansible-lint reported five violations, and the exit status was 2.
  • The rule name checks the names: name[play] says that all plays should be named, name[missing] that all tasks should be named, and name[casing] that all names should start with an uppercase letter for languages that support it Source 34সোর্স 34. The rule no-changed-when checks that tasks return changes to results or conditions Source 35সোর্স 35. The rule risky-file-permissions is triggered by various modules that could end up creating new files on disk with permissions that might be too open, or unpredictable Source 36সোর্স 36. The summary lists name three times, once for each of its violations.
  • The summary shows profile:basic for all five violations, and the last profile that the file met is min. The min profile ensures that Ansible can load content Source 32সোর্স 32. The basic profile prevents common coding issues and enforces standard styles and formatting Source 32সোর্স 32.
  • ansible-lint creates caches with installed roles and collections under the runtime cache directory, which is typically {project}/.ansible when it is not offline Source 33সোর্স 33. It does not clean the cache by itself Source 33সোর্স 33. The tutorial's run left one file in the empty home folder, which the intro of this section describes.

8. Encrypt a secret with Vault. Run:

printf 'made-up-vault-password\n' > vault-pass.txt
printf 'db_password: made-up-db-password\n' > secrets.yml
ansible-vault encrypt secrets.yml --vault-password-file vault-pass.txt
head -n 2 secrets.yml
grep -c 'made-up-db-password' secrets.yml
ansible-vault view secrets.yml --vault-password-file vault-pass.txt

Output of the tutorial's run:

$ANSIBLE_VAULT;1.1;AES256
31353436626163303837616632383237326136666565343433393465366663346538633966316231
0
db_password: made-up-db-password

The password and the secret of this step are made up for the tutorial.

  • ansible-vault is an encryption/decryption utility for Ansible data files Source 41সোর্স 41. The first two lines write the password file, vault-pass.txt, and the data file, secrets.yml. To store a vault password in a file, you enter the password as a string on a single line in the file Source 44সোর্স 44. The docs also say to make sure that the permissions on the file are appropriate, and not to add password files to source control Source 44সোর্স 44. The tutorial did not change the permissions of its file, which lives only in the temporary folder of the run.
  • To encrypt an existing file, you use the ansible-vault encrypt command Source 27সোর্স 27. The option --vault-password-file takes a vault password file Source 41সোর্স 41. The command printed nothing in this run.
  • head -n 2 secrets.yml printed the header line, $ANSIBLE_VAULT;1.1;AES256, and a line of hex digits. The docs show an example of encrypted content with the header $ANSIBLE_VAULT;1.1;AES256 Source 27সোর্স 27.
  • grep -c printed 0, so no line of the encrypted file holds the text made-up-db-password.
  • ansible-vault view printed db_password: made-up-db-password. To view the contents of an encrypted file without editing it, you can use the ansible-vault view command Source 27সোর্স 27. Ansible Vault can encrypt two types of content, variables and files Source 27সোর্স 27. This step encrypted a file.

বাংলা ব্যাখ্যা

টিউটোরিয়াল ১ থেকে ৮ নম্বর ধাপ চালিয়েছে 2026-11-19 তারিখে 16:05-এ (+06), Linux 7.0.0-43-generic-এ, ansible-core 2.22.0, ansible-lint 26.11.0, Python 3.14.4 আর bash 5.3.9 দিয়ে। এই page-এর output টিউটোরিয়ালের run থেকে নেওয়া। প্রতিটা ধাপ চলেছে নিজের shell-এ, practice folder-এর একটা কপিতে, একটা নতুন, খালি HOME দিয়ে। page-এ run-এর folder দেখানো হয়েছে /work নামে, আর tool-গুলোর virtual environment /venv নামে। runner ANSIBLE দিয়ে শুরু হওয়া নামের একটা variable সেট করেছে। সেটা ANSIBLE_REMOTE_TEMP, যা remote_tmp setting-এর একটা environment variable, আর সেই setting হলো target-এ task চালানোর সময় ব্যবহারের অস্থায়ী directory Source 9সোর্স 9। সেটা run-এর folder-এর ভেতরের একটা folder-কে দেখায়। ধাপগুলোর পর খালি home folder-এ একটাই file ছিল, ~/.cache/ansible-lint/latest.json। এটা 3686 byte-এর একটা JSON file। এর key-গুলোর মধ্যে আছে tag_name, মান v26.11.0, আর html_url, যার মান GitHub-এ ansible-lint-এর একটা release page-এর ঠিকানা। টিউটোরিয়াল যে page-গুলো পড়েছে, তার কোনোটাই এই file বর্ণনা করে না। টিউটোরিয়াল আসল home folder-এ কোনো নতুন entry পায়নি।

আটটা ধাপই একটা host ব্যবহার করে, localhost, local connection দিয়ে। সেগুলোর কোনো দূরের host, SSH বা cloud account লাগে না। দুটো playbook শুধু তাদের পাশের out নামের একটা folder-এ লেখে। ৬, ৭ আর ৮ নম্বর ধাপ practice folder-এ আরও চারটা file লেখে: bad-check.yml, lint-bad.yml, vault-pass.txt আর secrets.yml। ansible-lint-এর --offline option requirements.yml-এর installation আর schema refresh বন্ধ করে Source 33সোর্স 33। টিউটোরিয়াল সেটা ব্যবহার করেনি, তাই ৭ নম্বর ধাপ network ব্যবহার করে থাকতে পারে। ধাপগুলোর echo লাইন তার আগের command-এর exit status ছাপে। সেগুলো টিউটোরিয়ালের নিজের সংযোজন। টিউটোরিয়াল role, block, rescue, changed_when বা Molecule চালায়নি। page সেগুলো শুধু docs থেকে বর্ণনা করেছে।

যে সিদ্ধান্ত কোনো source দেয় না, সেগুলো টিউটোরিয়ালের নিজের: file-গুলোর নাম, file-এর ভেতরের নাম, out folder, বানানো মান qa, http://localhost:8080 আর http://localhost:9090, ৫ নম্বর ধাপের হাতে করা edit, ৬ নম্বর ধাপের ভুল test, ৭ নম্বর ধাপের lint-bad.yml file, আর ৮ নম্বর ধাপের বানানো password।

tool-গুলো install করুন। docs বর্তমান user-এর জন্য ন্যূনতম package install করে python3 -m pip install --user ansible-core দিয়ে Source 5সোর্স 5। টিউটোরিয়াল Python 3.14.4 দিয়ে নিজের একটা virtual environment বানিয়েছে, আর pip দিয়ে তাতে দুটো package install করেছে। এটা টিউটোরিয়ালের নিজের সিদ্ধান্ত, যাতে system Python-এ কিছু না পড়ে। 2026-11-19 তারিখে 14:55-এ টিউটোরিয়ালের install script PyPI JSON API-কে সর্বশেষ version জিজ্ঞেস করেছে। সে পেয়েছে ansible-core 2.22.0 আর ansible-lint 26.11.0।

script আগে ansible-core-এর wheel download করেছে। সে file-টার SHA-256 (যা 8285d4cc দিয়ে শুরু) মিলিয়েছে সেই মানের সঙ্গে, যা PyPI JSON API সেই file-এর জন্য তালিকাভুক্ত করে, আর দুটো মান এক ছিল। এই যাচাইয়ের সীমা আছে। তালিকাটা আসে file-এর একই host থেকে, আর টিউটোরিয়াল কোনো signature যাচাই করেনি। ansible-lint আর দুটো package-এর dependency pip দিয়ে PyPI থেকে HTTPS-এ install হয়েছে, hash যাচাই ছাড়া।

১. version দেখুন। চালান:

ansible --version
ansible-lint --version

টিউটোরিয়ালের run-এর output:

ansible [core 2.22.0]
  config file = None
  configured module search path = ['/work/home/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /venv/lib/python3.14/site-packages/ansible
  ansible collection location = /work/home/.ansible/collections:/usr/share/ansible/collections
  executable location = /venv/bin/ansible
  python version = 3.14.4 (main, Aug 20 2026, 10:41:58) [GCC 15.2.0] (/venv/bin/python3)
  jinja version = 3.1.6
  pyyaml version = 6.0.3 (with libyaml v0.2.5)
ansible-lint 26.11.0 using ansible-core:2.22.0 ansible-compat:26.11.0 ruamel-yaml:0.19.1
  • ansible --version ansible-core package-এর version ছেপেছে, [core 2.22.0], আর run যে path-গুলো ব্যবহার করেছে। run-এর folder-এ কোনো ansible.cfg file নেই, আর output বলে config file = None। module আর collection-এর path শুরু হয় /work/home/.ansible দিয়ে, যা run-এর খালি home folder-এ। ANSIBLE_HOME setting হলো controller-এ Ansible config file-এর default root path Source 30সোর্স 30।
  • ansible-lint --version ছেপেছে ansible-lint 26.11.0, আর সেটা যে ansible-core version ব্যবহার করেছে তা-ও ছেপেছে, 2.22.0, সঙ্গে আরও দুটো package-এর version।

২. একটা inventory লিখুন, আর সেটা দেখুন। এটা inventory.yml নামে save করুন:

all:
  children:
    app:
      hosts:
        localhost:
          ansible_connection: local

file-টা একটা group, app, ঠিক করে, তাতে একটা host, localhost। YAML হলো সবচেয়ে প্রচলিত inventory format-গুলোর একটা Source 6সোর্স 6। ansible_connection variable host-এর connection-এর ধরন ঠিক করে, আর সেটা যেকোনো Ansible connection plugin-এর নাম হতে পারে Source 6সোর্স 6। local মান local connection plugin-কে বোঝায়, যা দূরের host-এর বদলে controller-এ task চালায় Source 7সোর্স 7।

চালান:

ansible-inventory -i inventory.yml --graph
ansible-inventory -i inventory.yml --list
ansible app -i inventory.yml -m ansible.builtin.ping

টিউটোরিয়ালের run-এর output:

@all:
  |--@ungrouped:
  |--@app:
  |  |--localhost
{
    "_meta": {
        "hostvars": {
            "localhost": {
                "ansible_connection": "local"
            }
        },
        "profile": "inventory_legacy"
    },
    "all": {
        "children": [
            "ungrouped",
            "app"
        ]
    },
    "app": {
        "hosts": [
            "localhost"
        ]
    }
}
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
localhost | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/venv/bin/python3.14"
    },
    "changed": false,
    "ping": "pong"
}
  • ansible-inventory --graph inventory-র একটা গাছ ছেপেছে। --graph option একটা inventory graph বানায়, আর আপনার দেওয়া pattern একটা বৈধ group-এর নাম হতে হবে Source 38সোর্স 38। @all group-এ আছে @ungrouped আর @app group, আর localhost আছে @app-এর নিচে। টিউটোরিয়াল ungrouped নামে কোনো group ঠিক করেনি, তবু Ansible সেটা বানিয়েছে। আপনি কোনো group না বানালেও Ansible দুটো default group বানায়, all আর ungrouped Source 6সোর্স 6।
  • ansible-inventory --list একই inventory JSON হিসেবে ছেপেছে। --list option সব host-এর তথ্য দেয়, আর এটা একটা inventory script-এর মতো কাজ করে Source 38সোর্স 38। localhost-এর ansible_connection variable আছে _meta আর hostvars-এর নিচে। _meta block-এ profile নামে একটা key-ও আছে, মান inventory_legacy। টিউটোরিয়াল যে page-গুলো পড়েছে, তার কোনোটাই এই key বর্ণনা করে না।
  • ansible app -i inventory.yml -m ansible.builtin.ping একটা ad hoc command। একটা ad hoc command /usr/bin/ansible command-line tool ব্যবহার করে এক বা একাধিক managed node-এ একটা একক task automate করতে Source 42সোর্স 42। এটা দেখতে ansible [pattern] -m [module] -a "[module options]"-এর মতো Source 42সোর্স 42। এখানে app হলো pattern, আর ansible.builtin.ping হলো module। ping module একটা তুচ্ছ test module, যা সফল যোগাযোগে সবসময় pong ফেরত দেয় Source 39সোর্স 39। login করার ক্ষমতা আর একটা ব্যবহারযোগ্য Python ঠিক করা আছে কি না যাচাই করতে এটা /usr/bin/ansible থেকে কাজে লাগে Source 39সোর্স 39। output-এ আছে SUCCESS, "changed": false আর "ping": "pong"।
  • output-এ Python interpreter নিয়ে একটা সতর্কবার্তাও আছে। আপনি অন্যভাবে ঠিক না করলে Ansible প্রতিটা target host-এ প্রথমবার সেই host-এর জন্য একটা Python module চালানোর সময় একটা উপযুক্ত Python interpreter খুঁজে নিতে চেষ্টা করে Source 8সোর্স 8। default setting auto একটা সতর্কবার্তা দেয় যে ভবিষ্যতে আরেকটা Python interpreter install হলে বেছে নেওয়াটা বদলে যেতে পারে Source 8সোর্স 8। run-এ discovered_interpreter_python হলো /venv/bin/python3.14। টিউটোরিয়াল setting বদলায়নি, তাই সতর্কবার্তাটা output-এ আছে। ৩ থেকে ৬ নম্বর ধাপের প্রথম task-এ সেটা আবার দেখা দেয়।

৩. একটা playbook লিখুন, আর দুবার চালান। এটা site.yml নামে save করুন:

- name: Write the settings of the test environment
  hosts: app
  gather_facts: false
  vars:
    env_name: qa
    base_url: http://localhost:8080
    out_dir: "{{ playbook_dir }}/out"
  tasks:
    - name: Create the output folder
      ansible.builtin.file:
        path: "{{ out_dir }}"
        state: directory
        mode: "0755"

    - name: Write the settings file
      ansible.builtin.template:
        src: settings.env.j2
        dest: "{{ out_dir }}/{{ env_name }}.env"
        mode: "0644"
      notify: Record the change

  handlers:
    - name: Record the change
      ansible.builtin.copy:
        content: "settings changed\n"
        dest: "{{ out_dir }}/changed.log"
        mode: "0644"

এটা settings.env.j2 নামে save করুন, site.yml-এর পাশে templates নামের একটা folder-এ:

env={{ env_name }}
base_url={{ base_url }}

play-তে দুটো task আর একটা handler আছে:

  • hosts: app play-কে app group লক্ষ্য করায়। hosts keyword হলো group, host বা host pattern-এর একটা তালিকা, যা play-এর লক্ষ্যে পরিণত হয় Source 45সোর্স 45।
  • vars section play-র জন্য তিনটা variable ধরে Source 45সোর্স 45। playbook_dir variable হলো বর্তমান playbook-এর directory-র path Source 43সোর্স 43। তাই playbook তার পাশের out নামের একটা folder-এ লেখে।
  • gather_facts keyword একটা boolean, যা ঠিক করে play আপনা থেকে hosts-এর fact সংগ্রহ করতে setup task চালাবে কি না Source 45সোর্স 45। টিউটোরিয়াল gather_facts: false দিয়েছে, কারণ playbook কোনো fact ব্যবহার করে না। output-এ কোনো Gathering Facts task নেই।
  • file task out folder বানায়। state: directory দিলে লক্ষ্যটা একটা directory, আর Ansible যেকোনো অনুপস্থিত parent folder বানায় Source 21সোর্স 21। mode "0755", quote-সহ, কারণ octal সংখ্যা quote করা উচিত, যাতে Ansible একটা string পায় Source 21সোর্স 21।
  • template task templates/settings.env.j2-কে render করে out/qa.env-এ। src হলো controller-এ থাকা একটা Jinja2 format-এর template-এর path Source 23সোর্স 23, আর dest হলো যেখানে সেটা render হবে সেই জায়গা Source 23সোর্স 23। template-এ দুটো Jinja2 expression আছে, {{ env_name }} আর {{ base_url }}। Ansible গতিশীল expression আর variable ও fact-এ প্রবেশ সম্ভব করতে Jinja2 templating ব্যবহার করে Source 12সোর্স 12। একটা role-এর কাঠামোয় templates/ folder template resource-এর জন্য file ধরে, আর template-এর নাম .j2 দিয়ে শেষ হয় Source 14সোর্স 14। টিউটোরিয়াল একই নাম ব্যবহার করেছে এমন একটা playbook-এর পাশে, যা role নয়, আর run দেখায় Ansible file-টা পেয়েছে।
  • notify: Record the change handler-এর নাম দেয়। notify keyword হলো সেই handler-এর তালিকা, যাদের task changed=True status ফেরত দিলে notify করা হয় Source 45সোর্স 45। handlers section-এ এমন task থাকে, যা স্বাভাবিকভাবে চলে না, চলে শুধু task-এর প্রতিটা section শেষ হওয়ার পর notify করা হলে Source 45সোর্স 45। handler copy module দিয়ে out/changed.log-এ settings changed লেখে। src-এর বদলে content ব্যবহার করলে এটা একটা file-এর content সরাসরি দেওয়া মানে বসায় Source 22সোর্স 22।
  • প্রতিটা play, task আর handler-এর একটা নাম আছে, আর প্রতিটা module-এর পুরো নাম আছে, ansible.builtin.<module>। tips page বলে সবসময় play, task আর block-এর নাম দিতে Source 29সোর্স 29, আর fully qualified collection name ব্যবহার করতে Source 29সোর্স 29।

চালান:

ansible-playbook -i inventory.yml site.yml --syntax-check
echo "syntax-check exit status: $?"
ansible-playbook -i inventory.yml site.yml --list-tasks
ansible-playbook -i inventory.yml site.yml
echo "run 1 exit status: $?"
cat out/qa.env out/changed.log
ansible-playbook -i inventory.yml site.yml
echo "run 2 exit status: $?"

টিউটোরিয়ালের run-এর output:


playbook: site.yml
syntax-check exit status: 0

playbook: site.yml

  play #1 (app): Write the settings of the test environment	TAGS: []
    tasks:
      Create the output folder	TAGS: []
      Write the settings file	TAGS: []

PLAY [Write the settings of the test environment] ******************************

TASK [Create the output folder] ************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
changed: [localhost]

TASK [Write the settings file] *************************************************
changed: [localhost]

RUNNING HANDLER [Record the change] ********************************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

run 1 exit status: 0
env=qa
base_url=http://localhost:8080
settings changed

PLAY [Write the settings of the test environment] ******************************

TASK [Create the output folder] ************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [Write the settings file] *************************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

run 2 exit status: 0
  • --syntax-check ছেপেছে playbook: site.yml, আর exit status ছিল ০। option-টা playbook-এর syntax যাচাই করে, কিন্তু সেটা চালায় না Source 20সোর্স 20।
  • --list-tasks play আর তার দুটো task ছেপেছে, আর handler তালিকাভুক্ত করেনি। option-টা যে সব task চালানো হতো তার তালিকা দেয় Source 20সোর্স 20।
  • প্রথম run প্রতিটা task-এর জন্য একটা করে block ছেপেছে, আর প্রতিটাতে changed ছিল। তারপর ছেপেছে RUNNING HANDLER [Record the change], আর সেটাতেও changed ছিল। সারাংশে ok=3 আর changed=3, আর exit status ছিল ০। cat ছেপেছে render করা file, env=qa আর base_url=http://localhost:8080, তারপর log, settings changed।
  • দ্বিতীয় run দুটো task-এর জন্যই ok ছেপেছে, আর কোনো handler চালায়নি। সারাংশে ok=2 আর changed=0। system যখন playbook-এর বর্ণিত অবস্থায় থাকে, তখন playbook বহুবার চললেও Ansible কিছুই বদলায় না Source 1সোর্স 1। task changed=True status ফেরত দিলে handler-কে notify করা হয় Source 45সোর্স 45। দ্বিতীয় run-এ কোনো task সেই status ফেরত দেয়নি, তাই কোনো handler চলেনি।
  • Python interpreter নিয়ে সতর্কবার্তা দুটো run-এরই প্রথম task-এ আছে, আর --syntax-check বা --list-tasks-এ নেই।

৪. পরিবর্তন করার আগে সেটা দেখুন। চালান:

ansible-playbook -i inventory.yml site.yml -e base_url=http://localhost:9090 --check --diff
echo "check exit status: $?"
cat out/qa.env

টিউটোরিয়ালের run-এর output:


PLAY [Write the settings of the test environment] ******************************

TASK [Create the output folder] ************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [Write the settings file] *************************************************
--- before: /work/out/qa.env
+++ after: /work/home/.ansible/tmp/ansible-local-7792835_4w5e4s/tmp3_5cofrv/settings.env.j2
@@ -1,2 +1,2 @@
 env=qa
-base_url=http://localhost:8080
+base_url=http://localhost:9090

changed: [localhost]

RUNNING HANDLER [Record the change] ********************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

check exit status: 0
env=qa
base_url=http://localhost:8080
  • -e option key=value আকারে বাড়তি variable সেট করে Source 20সোর্স 20। extra vars সবসময় অন্য variable-এর ওপর precedence-এ জেতে Source 11সোর্স 11। তাই এই run-এ base_url ছিল http://localhost:9090, play-র মান নয়।
  • --check দূরের system-এ কোনো পরিবর্তন না করে playbook চালায়, আর --diff আগে-পরের তুলনা দেয় Source 15সোর্স 15। diff mode সবচেয়ে বেশি দেখা যায় file নিয়ে কাজ করা module-এ, যেমন template module Source 15সোর্স 15। output-এ শুধু template task-এর একটা diff আছে: -base_url=http://localhost:8080 আর +base_url=http://localhost:9090। সেই task বলেছে changed, আর সারাংশে changed=1।
  • +++ after:-এর পরের path run-এর খালি home folder-এর .ansible/tmp-এর নিচে, আর তার নামের কিছু অংশ প্রতিটা run-এ বদলায়। DEFAULT_LOCAL_TMP setting হলো controller-এ Ansible-এর ব্যবহারের অস্থায়ী directory Source 30সোর্স 30। টিউটোরিয়াল যে page-গুলো পড়েছে, তার কোনোটাই diff-এর এই লাইন বর্ণনা করে না।
  • check-এর পর cat out/qa.env তখনও ছেপেছে base_url=http://localhost:8080। check file বদলায়নি। check mode-এ Ansible দূরের system-এ কোনো পরিবর্তন না করে চলে Source 15সোর্স 15।
  • handler চলেছে, কারণ template task পরিবর্তন জানিয়েছে, আর সেটা ছেপেছে ok। changed.log file-এ আগে থেকেই settings changed ছিল, আর বেশির ভাগ module কাঙ্ক্ষিত অবস্থা অর্জিত হয়ে থাকলে কোনো কাজ না করেই exit করে Source 10সোর্স 10। check-এর exit status ছিল ০, যদিও সেটা একটা পরিবর্তন জানিয়েছে।

৫. drift খুঁজুন। চালান:

printf 'env=changed-by-hand\n' > out/qa.env
ansible-playbook -i inventory.yml site.yml --check --diff
echo "check exit status: $?"
if ansible-playbook -i inventory.yml site.yml --check | grep -q 'changed=[1-9]'; then echo "drift found"; fi
cat out/qa.env
ansible-playbook -i inventory.yml site.yml
cat out/qa.env

টিউটোরিয়ালের run-এর output:


PLAY [Write the settings of the test environment] ******************************

TASK [Create the output folder] ************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [Write the settings file] *************************************************
--- before: /work/out/qa.env
+++ after: /work/home/.ansible/tmp/ansible-local-7795049hhg3uy7/tmpf84rpgq4/settings.env.j2
@@ -1 +1,2 @@
-env=changed-by-hand
+env=qa
+base_url=http://localhost:8080

changed: [localhost]

RUNNING HANDLER [Record the change] ********************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

check exit status: 0
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
drift found
env=changed-by-hand

PLAY [Write the settings of the test environment] ******************************

TASK [Create the output folder] ************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [Write the settings file] *************************************************
changed: [localhost]

RUNNING HANDLER [Record the change] ********************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

env=qa
base_url=http://localhost:8080
  • প্রথম লাইন file-টা হাতে বদলায়, যাতে out/qa.env-এ থাকে শুধু env=changed-by-hand। file-টা playbook থেকে আলাদা করার এটা টিউটোরিয়ালের নিজের উপায়।
  • --check --diff একটা diff ছেপেছে: -env=changed-by-hand, +env=qa আর +base_url=http://localhost:8080। template task বলেছে changed, আর সারাংশে changed=1। check-এর exit status আবারও ছিল ০, তাই exit status বলে না কোনো পার্থক্য আছে কি না।
  • grep হলো টিউটোরিয়ালের নিজের test। সে একটা check run-এর সারাংশে ০-র বেশি সংখ্যা সহ changed= খোঁজে, আর echo ছেপেছে drift found। tests page বলে, --check দিলে system-কে কাঙ্ক্ষিত অবস্থায় আনতে Ansible-কে কোনো পরিবর্তন করতে হতো বলে সে মনে করলে সেটা জানায় Source 28সোর্স 28। সেই page-এর এ নিয়ে section-টার নাম Check Mode As A Drift Test Source 28সোর্স 28।
  • check-এর পর cat তখনও ছেপেছে env=changed-by-hand। check file মেরামত করেনি।
  • আসল run মেরামত করেছে। template task বলেছে changed, handler চলে বলেছে ok, আর সারাংশে ok=3 ও changed=1। cat আবার ছেপেছে env=qa আর base_url=http://localhost:8080। handler চলেছে কারণ একটা task তাকে notify করেছে, আর তার নিজের copy task-এর বদলানোর কিছু ছিল না।

৬. assert দিয়ে একটা test লিখুন। এটা check.yml নামে save করুন:

- name: Check the settings file
  hosts: app
  gather_facts: false
  vars:
    out_dir: "{{ playbook_dir }}/out"
  tasks:
    - name: Read the settings file
      ansible.builtin.slurp:
        src: "{{ out_dir }}/qa.env"
      register: settings

    - name: Look at the settings file
      ansible.builtin.stat:
        path: "{{ out_dir }}/qa.env"
      register: settings_stat

    - name: Check that the file holds the settings of the qa environment
      ansible.builtin.assert:
        that:
          - "'env=qa' in (settings.content | b64decode)"
          - "'base_url=http://localhost:8080' in (settings.content | b64decode)"
          - settings_stat.stat.mode == '0644'
        success_msg: The settings are what the test expects.
        fail_msg: The settings are not what the test expects.

playbook কিছুই বদলায় না। এতে তিনটা task আছে:

  • slurp task out/qa.env পড়ে। module একটা দূরের file-এর data ধরা base64-encoded blob আনতে ব্যবহার করা হয় Source 24সোর্স 24। register keyword হলো সেই variable-এর নাম, যাতে task-এর status আর module-এর ফেরত দেওয়া data থাকবে Source 45সোর্স 45। তাই settings-এ slurp task-এর ফল আছে।
  • stat task file-এর status settings_stat-এ register করে। module একটা file-এর facts আনে, Linux/Unix-এর stat command-এর মতো Source 40সোর্স 40। এর mode ফেরত-মান file-এর Unix permission ধরে, octal রূপে একটা string হিসেবে Source 40সোর্স 40। তাই test সেটাকে '0644' string-এর সঙ্গে মেলায়।
  • assert task-এর that-এ তিনটা expression আছে। that option হলো একই ধরনের string expression-এর একটা তালিকা, যা when statement-এ দেওয়া যায় Source 25সোর্স 25। slurp module-এর উদাহরণ content decode করতে {{ mounts['content'] | b64decode }} expression ব্যবহার করে Source 24সোর্স 24। test-এর প্রথম দুটো expression settings.content-এর সঙ্গে একই কাজ করে, আর যাচাই করে text-এ env=qa আর base_url=http://localhost:8080 আছে। তৃতীয়টা mode যাচাই করে। success_msg option হলো সফল assertion-এর বার্তা, আর fail_msg হলো ব্যর্থ assertion-এর বার্তা Source 25সোর্স 25।

চালান:

ansible-playbook -i inventory.yml check.yml
echo "check.yml exit status: $?"
sed -e "s/'env=qa' in/'env=prod' in/" -e 's/of the qa environment/of the production environment/' check.yml > bad-check.yml
ansible-playbook -i inventory.yml bad-check.yml
echo "bad-check.yml exit status: $?"

টিউটোরিয়ালের run-এর output:


PLAY [Check the settings file] *************************************************

TASK [Read the settings file] **************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [Look at the settings file] ***********************************************
ok: [localhost]

TASK [Check that the file holds the settings of the qa environment] ************
ok: [localhost] => {
    "changed": false,
    "msg": "The settings are what the test expects."
}

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

check.yml exit status: 0

PLAY [Check the settings file] *************************************************

TASK [Read the settings file] **************************************************
[WARNING]: Host 'localhost' is using the discovered Python interpreter at '/venv/bin/python3.14', but future installation of another Python interpreter could cause a different interpreter to be discovered. See https://docs.ansible.com/ansible-core/2.22/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [Look at the settings file] ***********************************************
ok: [localhost]

TASK [Check that the file holds the settings of the production environment] ****
[ERROR]: Task failed: Action failed: The settings are not what the test expects.
Origin: /work/bad-check.yml:17:7

15       register: settings_stat
16
17     - name: Check that the file holds the settings of the production environment
         ^ column 7

fatal: [localhost]: FAILED! => {
    "assertion": "'env=prod' in (settings.content | b64decode)",
    "changed": false,
    "evaluated_to": false,
    "msg": "The settings are not what the test expects."
}

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

bad-check.yml exit status: 2
  • প্রথম run তিনটা task-এর জন্যই ok ছেপেছে। assert task তার success_msg, The settings are what the test expects., ছেপেছে, আর exit status ছিল ০।
  • sed command bad-check.yml বানিয়েছে, একটা কপি যা env=prod আশা করে। সেই run-এ assert task ব্যর্থ হয়েছে। output-এ আছে fatal: [localhost]: FAILED!, যে expression ব্যর্থ হয়েছে সেটা, "evaluated_to": false আর fail_msg। সারাংশে failed=1, আর exit status ছিল ২। কোনো module ব্যর্থ হলে Ansible by default সেই host-এ চালানো বন্ধ করে Source 16সোর্স 16। ব্যর্থ task-টা ছিল play-এর শেষ task। টিউটোরিয়াল যে page-গুলো পড়েছে, তার কোনোটাই ansible-playbook-এর exit status তালিকাভুক্ত করে না।
  • ব্যর্থতা শুরু হয় [ERROR]: Task failed: Action failed: দিয়ে, আর Origin: লাইন task-এর file, লাইন ও column দেয়, /work/bad-check.yml:17:7। টিউটোরিয়াল যে page-গুলো পড়েছে, তার কোনোটাই এই format বর্ণনা করে না।

৭. playbook-গুলো lint করুন। চালান:

export ANSIBLE_DEPRECATION_WARNINGS=false
ansible-lint --project-dir . site.yml check.yml
echo "lint exit status: $?"
cat > lint-bad.yml <<'YAML'
- hosts: app
  tasks:
    - ansible.builtin.command: echo hello
    - name: write a file
      ansible.builtin.copy:
        content: hello
        dest: out/lint-bad-example.txt
YAML
ansible-lint --project-dir . lint-bad.yml
echo "lint exit status: $?"

টিউটোরিয়ালের run-এর output:


Passed: 0 failure(s), 0 warning(s) in 2 files processed of 2 encountered. Last profile that met the validation criteria was 'production'.
lint exit status: 0
WARNING  Listing 5 violation(s) that are fatal
Read documentation for instructions on how to ignore specific rule violations.

# Rule Violation Summary

  1 name profile:basic tags:idiom
  1 name profile:basic tags:idiom
  1 name profile:basic tags:idiom
  1 risky-file-permissions profile:basic tags:unpredictability
  1 no-changed-when profile:basic tags:command-shell,idempotency

Failed: 5 failure(s), 0 warning(s) in 1 files processed of 1 encountered. Last profile that met the validation criteria was 'min'.
name[play]: All plays should be named.
lint-bad.yml:1:3

name[missing]: All tasks should be named.
lint-bad.yml:3 Task/Handler: command echo hello

no-changed-when: Commands should not change things if nothing needs doing.
lint-bad.yml:3 Task/Handler: command echo hello

name[casing]: All names should start with an uppercase letter.
lint-bad.yml:4:13 Task/Handler: write a file

risky-file-permissions: File permissions unset or incorrect.
lint-bad.yml:4 Task/Handler: write a file

lint exit status: 2
  • প্রথম command site.yml আর check.yml lint করে। --project-dir option হলো project বা repository-র অবস্থান Source 33সোর্স 33। ফল Passed: 0 failure(s), 0 warning(s), file দুটো যে শেষ profile পূরণ করেছে সেটা production, আর exit status ছিল ০। profile নিয়মের কঠোরতা ধাপে ধাপে বাড়ায়, যেমন যেমন আপনার Ansible content-এর জীবনচক্র পরিণত হয় Source 32সোর্স 32। --profile option নেয় min, basic, moderate, safety, shared আর production-এর একটা Source 33সোর্স 33। production profile নিশ্চিত করে যে content Ansible Automation Platform (AAP)-এ validated বা certified content হিসেবে অন্তর্ভুক্ত হওয়ার শর্ত পূরণ করে Source 32সোর্স 32।
  • এই ধাপের প্রথম লাইন, export ANSIBLE_DEPRECATION_WARNINGS=false, টিউটোরিয়ালের নিজের সিদ্ধান্ত। এটা ছাড়া একই command ফলের আগে দুটো deprecation সতর্কবার্তা ছেপেছিল। সেগুলো বলে oneline আর tree callback deprecated হয়েছে, আর ফিচারটা ansible-core version 2.23 থেকে সরানো হবে। দুটোতেই লেখা Origin: <unknown>। টিউটোরিয়ালের file আর environment কোনো callback সেট করে না, আর টিউটোরিয়াল যে page-গুলো পড়েছে তার কোনোটাই বলে না ansible-lint সেগুলো কেন ছেপেছে। DEPRECATION_WARNINGS setting হলো deprecation সতর্কবার্তা দেখানো নিয়ন্ত্রণের একটা toggle Source 30সোর্স 30, আর এর environment variable হলো ANSIBLE_DEPRECATION_WARNINGS Source 30সোর্স 30। ওই লাইন ছাড়া একই command-এর জন্য টিউটোরিয়ালের run-এর output এই:
[WARNING]: Deprecation warnings can be disabled by setting `deprecation_warnings=False` in ansible.cfg.
[DEPRECATION WARNING]: oneline has been deprecated. Use another callback plugin, or vendor and/or move the oneline callback to a collection. This feature will be removed from ansible-core version 2.23.
Origin: <unknown>

oneline

[DEPRECATION WARNING]: tree has been deprecated. Use another callback plugin, or vendor and/or move the tree callback to a collection. This feature will be removed from ansible-core version 2.23.
Origin: <unknown>

tree


Passed: 0 failure(s), 0 warning(s) in 2 files processed of 2 encountered. Last profile that met the validation criteria was 'production'.
lint exit status: 0
  • দ্বিতীয় command lint-bad.yml lint করে, এমন একটা file, যা টিউটোরিয়াল ইচ্ছে করে লিখেছে আর চালায়নি। এতে আছে নামহীন একটা play, ansible.builtin.command চালানো নামহীন একটা task, আর mode ছাড়া একটা copy task, যার নাম ছোট হাতের অক্ষর দিয়ে শুরু। ansible-lint পাঁচটা লঙ্ঘন জানিয়েছে, আর exit status ছিল ২।
  • name rule নামগুলো যাচাই করে: name[play] বলে সব play-এর নাম থাকা উচিত, name[missing] বলে সব task-এর নাম থাকা উচিত, আর name[casing] বলে যেসব ভাষা এটা সমর্থন করে, সেগুলোর জন্য সব নাম বড় হাতের অক্ষর দিয়ে শুরু হওয়া উচিত Source 34সোর্স 34। no-changed-when rule যাচাই করে task ফলাফল বা condition দিয়ে পরিবর্তন জানায় কি না Source 35সোর্স 35। risky-file-permissions rule চালু হয় এমন নানা module-এ, যা এমন permission সহ নতুন file বানাতে পারে, যা বেশি খোলা বা অনির্ভরযোগ্য হতে পারে Source 36সোর্স 36। সারাংশ name তিনবার তালিকাভুক্ত করেছে, তার প্রতিটা লঙ্ঘনের জন্য একবার করে।
  • সারাংশ পাঁচটা লঙ্ঘনের সবগুলোর জন্য profile:basic দেখায়, আর file-টা যে শেষ profile পূরণ করেছে সেটা min। min profile নিশ্চিত করে যে Ansible content load করতে পারে Source 32সোর্স 32। basic profile সাধারণ coding সমস্যা ঠেকায় আর মান ধরনের style ও formatting চাপায় Source 32সোর্স 32।
  • ansible-lint ইনস্টল করা role ও collection সহ cache বানায় runtime cache directory-র নিচে, যা offline না হলে সাধারণত {project}/.ansible Source 33সোর্স 33। সে নিজে থেকে cache পরিষ্কার করে না Source 33সোর্স 33। টিউটোরিয়ালের run খালি home folder-এ একটা file রেখে গেছে, যা এই section-এর শুরুর অংশে বর্ণিত।

৮. Vault দিয়ে একটা secret encrypt করুন। চালান:

printf 'made-up-vault-password\n' > vault-pass.txt
printf 'db_password: made-up-db-password\n' > secrets.yml
ansible-vault encrypt secrets.yml --vault-password-file vault-pass.txt
head -n 2 secrets.yml
grep -c 'made-up-db-password' secrets.yml
ansible-vault view secrets.yml --vault-password-file vault-pass.txt

টিউটোরিয়ালের run-এর output:

$ANSIBLE_VAULT;1.1;AES256
31353436626163303837616632383237326136666565343433393465366663346538633966316231
0
db_password: made-up-db-password

এই ধাপের password আর secret টিউটোরিয়ালের জন্য বানানো।

  • ansible-vault হলো Ansible data file-এর জন্য একটা encryption/decryption utility Source 41সোর্স 41। প্রথম দুটো লাইন password file, vault-pass.txt, আর data file, secrets.yml, লেখে। একটা vault password file-এ রাখতে, আপনি file-এর একটাই লাইনে password-টা একটা string হিসেবে লেখেন Source 44সোর্স 44। docs আরও বলে, file-এর permission উপযুক্ত কি না নিশ্চিত করতে, আর password file source control-এ যোগ না করতে Source 44সোর্স 44। টিউটোরিয়াল তার file-এর permission বদলায়নি, যে file শুধু run-এর অস্থায়ী folder-এ থাকে।
  • একটা বিদ্যমান file encrypt করতে আপনি ansible-vault encrypt command ব্যবহার করেন Source 27সোর্স 27। --vault-password-file option একটা vault password file নেয় Source 41সোর্স 41। এই run-এ command কিছু ছাপেনি।
  • head -n 2 secrets.yml ছেপেছে header লাইন, $ANSIBLE_VAULT;1.1;AES256, আর hex অঙ্কের একটা লাইন। docs $ANSIBLE_VAULT;1.1;AES256 header সহ encrypted content-এর একটা উদাহরণ দেখায় Source 27সোর্স 27।
  • grep -c ছেপেছে 0, তাই encrypted file-এর কোনো লাইনে made-up-db-password লেখাটা নেই।
  • ansible-vault view ছেপেছে db_password: made-up-db-password। একটা encrypted file edit না করে তার content দেখতে আপনি ansible-vault view command ব্যবহার করতে পারেন Source 27সোর্স 27। Ansible Vault দুই ধরনের content encrypt করতে পারে, variable আর file Source 27সোর্স 27। এই ধাপ একটা file encrypt করেছে।

How a tester uses it

  • Test the result, and not the tool. Ansible resources are models of desired state, so it should not be necessary to test that services are started or that packages are installed Source 28সোর্স 28. The assert module makes it very easy to validate various kinds of truth Source 28সোর্স 28. In step 6, the test read the file that the playbook wrote, and it checked its text and its mode.
  • Use stat for what the configuration does not set. If you need to test for the existence of files that your Ansible configuration does not set declaratively, the stat module is a great choice Source 28সোর্স 28. Its return value mode holds the Unix permissions of the file in octal representation as a string Source 40সোর্স 40.
  • Do not test what Ansible tests. There is no need to check the return codes of commands, because Ansible checks them automatically Source 28সোর্স 28.
  • Run a playbook twice, and read the second recap. Most Ansible modules exit without performing any actions if the desired final state has already been achieved Source 10সোর্স 10. In step 3, the second run reported changed=0. Not all playbooks and not all modules behave this way Source 10সোর্স 10. A second run that reports changes is a finding.
  • Use check mode as a drift test, and know its limits. With --check, Ansible reports if it thinks it would have had to make any changes to bring the system into a desired state Source 28সোর্স 28. In step 5, it found the hand edit. Check mode is just a simulation Source 15সোর্স 15. Modules that do not support it report nothing and do nothing Source 15সোর্স 15. Ordinarily, scripts and commands do not run in check mode Source 28সোর্স 28. A check does not generate output for tasks that use conditionals based on registered variables Source 15সোর্স 15.
  • Read the diff, and mind the secrets in it. In diff mode, Ansible provides before-and-after comparisons Source 15সোর্স 15. Because --diff can reveal sensitive information, you can disable it for a task with diff: false Source 15সোর্স 15.
  • Lint before you run. You can use ansible-lint for detailed, Ansible-specific feedback on your playbooks before you execute them Source 10সোর্স 10. The option --strict returns a non-zero exit code on warnings as well as errors Source 33সোর্স 33. In step 7, the exit status was 0 for the two good files and 2 for the bad file.
  • Use the cheap checks first. --syntax-check performs a syntax check on the playbook, but does not execute it Source 20সোর্স 20. --list-hosts outputs a list of matching hosts, and it does not execute anything else Source 20সোর্স 20. --list-tasks lists all tasks that would be executed Source 20সোর্স 20. In step 3, the tutorial ran --syntax-check and --list-tasks before the real run.
  • Keep secrets in Vault, and keep the password out of Git. The tips page says that you should encrypt sensitive or secret variables with Ansible Vault Source 29সোর্স 29. The docs say not to add password files to source control Source 44সোর্স 44. Step 8 shows that the encrypted file does not hold the plain text, and that ansible-vault view shows it again.
  • Keep the environments apart. You can keep your production environment separate from development, test, and staging environments by using separate inventory files or directories for each environment Source 29সোর্স 29. If an inventory contains both production and development environments, developers using that inventory would be able to access production secrets Source 29সোর্স 29.
  • Use the right tool for the right test. Molecule is an Ansible testing framework designed for developing and testing Ansible collections, playbooks, and roles Source 37সোর্স 37. An integration test battery, such as Selenium tests or automated API tests, should be written by your QA team if you are a production webservice Source 28সোর্স 28. It would usually not be embedded into your playbooks Source 28সোর্স 28. It does make sense to include some basic health checks into your playbooks Source 28সোর্স 28.

সহজ English

  • Test the result, and not the tool. Ansible resources are models of desired state, so it should not be necessary to test that services are started or that packages are installed Source 28সোর্স 28. The assert module makes it very easy to validate various kinds of truth Source 28সোর্স 28. In step 6, the test read the file that the playbook wrote, and it checked its text and its mode.
  • Use stat for what the configuration does not set. If you need to test for the existence of files that your Ansible configuration does not set declaratively, the stat module is a great choice Source 28সোর্স 28. Its return value mode holds the Unix permissions of the file in octal representation as a string Source 40সোর্স 40.
  • Do not test what Ansible tests. There is no need to check the return codes of commands, because Ansible checks them automatically Source 28সোর্স 28.
  • Run a playbook twice, and read the second recap. Most Ansible modules exit without performing any actions if the desired final state has already been achieved Source 10সোর্স 10. In step 3, the second run reported changed=0. Not all playbooks and not all modules behave this way Source 10সোর্স 10. A second run that reports changes is a finding.
  • Use check mode as a drift test, and know its limits. With --check, Ansible reports if it thinks it would have had to make any changes to bring the system into a desired state Source 28সোর্স 28. In step 5, it found the hand edit. Check mode is just a simulation Source 15সোর্স 15. Modules that do not support it report nothing and do nothing Source 15সোর্স 15. Ordinarily, scripts and commands do not run in check mode Source 28সোর্স 28. A check does not generate output for tasks that use conditionals based on registered variables Source 15সোর্স 15.
  • Read the diff, and mind the secrets in it. In diff mode, Ansible provides before-and-after comparisons Source 15সোর্স 15. Because --diff can reveal sensitive information, you can disable it for a task with diff: false Source 15সোর্স 15.
  • Lint before you run. You can use ansible-lint for detailed, Ansible-specific feedback on your playbooks before you execute them Source 10সোর্স 10. The option --strict returns a non-zero exit code on warnings as well as errors Source 33সোর্স 33. In step 7, the exit status was 0 for the two good files and 2 for the bad file.
  • Use the cheap checks first. --syntax-check performs a syntax check on the playbook, but does not execute it Source 20সোর্স 20. --list-hosts outputs a list of matching hosts, and it does not execute anything else Source 20সোর্স 20. --list-tasks lists all tasks that would be executed Source 20সোর্স 20. In step 3, the tutorial ran --syntax-check and --list-tasks before the real run.
  • Keep secrets in Vault, and keep the password out of Git. The tips page says that you should encrypt sensitive or secret variables with Ansible Vault Source 29সোর্স 29. The docs say not to add password files to source control Source 44সোর্স 44. Step 8 shows that the encrypted file does not hold the plain text, and that ansible-vault view shows it again.
  • Keep the environments apart. You can keep your production environment separate from development, test, and staging environments by using separate inventory files or directories for each environment Source 29সোর্স 29. If an inventory contains both production and development environments, developers using that inventory would be able to access production secrets Source 29সোর্স 29.
  • Use the right tool for the right test. Molecule is an Ansible testing framework designed for developing and testing Ansible collections, playbooks, and roles Source 37সোর্স 37. An integration test battery, such as Selenium tests or automated API tests, should be written by your QA team if you are a production webservice Source 28সোর্স 28. It would usually not be embedded into your playbooks Source 28সোর্স 28. It does make sense to include some basic health checks into your playbooks Source 28সোর্স 28.

বাংলা ব্যাখ্যা

  • tool-এর নয়, ফলের test করুন। Ansible resource হলো কাঙ্ক্ষিত অবস্থার মডেল, তাই service চালু আছে বা package install করা আছে কি না test করার দরকার হওয়া উচিত নয় Source 28সোর্স 28। assert module নানা ধরনের সত্যতা যাচাই করা খুব সহজ করে Source 28সোর্স 28। ৬ নম্বর ধাপে test playbook-এর লেখা file পড়েছে, আর তার text ও mode যাচাই করেছে।
  • configuration যা ঠিক করে না, তার জন্য stat ব্যবহার করুন। আপনার Ansible configuration যে file-এর অস্তিত্ব ঘোষণামূলকভাবে ঠিক করে না, তা test করার দরকার হলে stat module দারুণ পছন্দ Source 28সোর্স 28। এর mode ফেরত-মান file-এর Unix permission ধরে, octal রূপে একটা string হিসেবে Source 40সোর্স 40।
  • Ansible যা test করে, তা test করবেন না। command-এর return code যাচাই করার দরকার নেই, কারণ Ansible সেগুলো আপনা থেকেই যাচাই করে Source 28সোর্স 28।
  • একটা playbook দুবার চালান, আর দ্বিতীয় সারাংশ পড়ুন। বেশির ভাগ Ansible module কাঙ্ক্ষিত চূড়ান্ত অবস্থা আগেই অর্জিত হয়ে থাকলে কোনো কাজ না করেই exit করে Source 10সোর্স 10। ৩ নম্বর ধাপে দ্বিতীয় run জানিয়েছে changed=0। সব playbook আর সব module এভাবে আচরণ করে না Source 10সোর্স 10। যে দ্বিতীয় run পরিবর্তন জানায়, সেটা একটা আবিষ্কার।
  • check mode drift test হিসেবে ব্যবহার করুন, আর তার সীমা জানুন। --check দিলে system-কে কাঙ্ক্ষিত অবস্থায় আনতে Ansible-কে কোনো পরিবর্তন করতে হতো বলে তার ধারণা হলে, সে তা জানায় Source 28সোর্স 28। ৫ নম্বর ধাপে সেটা হাতে করা edit ধরেছে। check mode শুধু একটা simulation Source 15সোর্স 15। যে module এটা সমর্থন করে না, তারা কিছু জানায় না আর কিছু করে না Source 15সোর্স 15। সাধারণত script আর command check mode-এ চলে না Source 28সোর্স 28। registered variable-ভিত্তিক conditional ব্যবহার করা task-এর জন্য check কোনো output দেয় না Source 15সোর্স 15।
  • diff পড়ুন, আর তার ভেতরের secret-এর দিকে নজর রাখুন। diff mode আগে-পরের তুলনা দেয় Source 15সোর্স 15। --diff সংবেদনশীল তথ্য প্রকাশ করতে পারে বলে আপনি একটা task-এর জন্য diff: false দিয়ে সেটা বন্ধ করতে পারেন Source 15সোর্স 15।
  • চালানোর আগে lint করুন। একটা playbook চালানোর আগে আপনি ansible-lint দিয়ে বিস্তারিত, Ansible-নির্দিষ্ট মতামত পেতে পারেন Source 10সোর্স 10। --strict option warning আর error দুটোতেই শূন্য নয় এমন exit code ফেরত দেয় Source 33সোর্স 33। ৭ নম্বর ধাপে দুটো ভালো file-এর exit status ছিল ০, আর খারাপ file-এর ২।
  • সস্তা যাচাই আগে করুন। --syntax-check playbook চালায় না Source 20সোর্স 20। --list-hosts মেলা host-এর তালিকা দেয়, আর আর কিছু চালায় না Source 20সোর্স 20। --list-tasks যে সব task চালানো হতো তার তালিকা দেয় Source 20সোর্স 20। ৩ নম্বর ধাপে টিউটোরিয়াল আসল run-এর আগে --syntax-check আর --list-tasks চালিয়েছে।
  • secret রাখুন Vault-এ, আর password রাখুন Git-এর বাইরে। tips page বলে, সংবেদনশীল বা গোপন variable Ansible Vault দিয়ে encrypt করা উচিত Source 29সোর্স 29। docs বলে, password file source control-এ যোগ না করতে Source 44সোর্স 44। ৮ নম্বর ধাপ দেখায় encrypted file-এ plain text নেই, আর ansible-vault view সেটা আবার দেখায়।
  • পরিবেশগুলো আলাদা রাখুন। আপনি প্রতিটা পরিবেশের জন্য আলাদা inventory file বা directory ব্যবহার করে আপনার production পরিবেশকে development, test আর staging পরিবেশ থেকে আলাদা রাখতে পারেন Source 29সোর্স 29। একটা inventory-তে production আর development দুটোই থাকলে সেটা যারা ব্যবহার করেন সেই developer-রা production-এর secret-এ প্রবেশ করতে পারতেন Source 29সোর্স 29।
  • ঠিক test-এর জন্য ঠিক tool ব্যবহার করুন। Molecule হলো একটা Ansible testing framework, যা Ansible collection, playbook আর role তৈরি ও test করার জন্য বানানো Source 37সোর্স 37। Selenium test বা automated API test-এর মতো একটা integration test battery আপনি production webservice হলে আপনার QA team-এর লেখা উচিত Source 28সোর্স 28। সেটা সাধারণত আপনার playbook-এর ভেতরে বসানো হয় না Source 28সোর্স 28। playbook-এ কিছু মৌলিক health check রাখা অর্থবহ Source 28সোর্স 28।

Common mistakes

  • Reading ping as a network test. The ping module always returns pong on successful contact Source 39সোর্স 39. It does not make sense in playbooks, but it is useful from /usr/bin/ansible to verify the ability to log in and that a usable Python is configured Source 39সোর্স 39.
  • Running shell or command without changed_when. You should always use the changed_when clause on tasks that do not naturally detect if a change has occurred Source 35সোর্স 35. Some of the most common examples are the shell and command modules, which run arbitrary commands Source 35সোর্স 35. The rule no-changed-when of ansible-lint checks that tasks return changes to results or conditions Source 35সোর্স 35. Step 7 shows it.
  • Treating check mode as a full preview. Check mode is just a simulation Source 15সোর্স 15. Modules that do not support check mode report nothing and do nothing Source 15সোর্স 15. Ordinarily, scripts and commands do not run in check mode Source 28সোর্স 28. A task with check_mode: false runs in normal mode and makes changes to the system, even when the playbook is called with --check Source 15সোর্স 15.
  • Reading the exit status of a check as the result. In steps 4 and 5, the exit status of --check was 0, although the check reported a change. The tutorial looked at the recap instead.
  • Reading ok as "the task did not run". In steps 4 and 5, the handler ran and printed ok, because its copy task found nothing to change.
  • Expecting a handler to run at once, or after a failure. Handlers run in the order of the handlers section, and not in the order of the notify list Source 13সোর্স 13. Notifying the same handler multiple times results in executing the handler only once, regardless of how many tasks notify it Source 13সোর্স 13. The meta: flush_handlers task triggers the handlers that have been notified at that point in the play Source 13সোর্স 13. The option --force-handlers runs handlers even if a task fails Source 20সোর্স 20. Step 3 shows that --list-tasks does not list handlers.
  • Using ignore_errors to hide a failure. The directive only works when the task can run and returns a value of failed Source 16সোর্স 16. It does not make Ansible ignore undefined variable errors, connection failures, execution issues, or syntax errors Source 16সোর্স 16.
  • Leaving a file mode unquoted. For consistent results, quote octal numbers, so that Ansible receives a string Source 21সোর্স 21.
  • Leaving plays and tasks without names. In its output, Ansible shows you the name of each named entity it runs Source 29সোর্স 29. The rule name[play] says that all plays should be named, and name[missing] says that all tasks should be named Source 34সোর্স 34. Step 7 shows both.
  • Using the short name of a module. For Ansible 2.10 and later, you should use the fully-qualified collection name (FQCN) in your playbooks Source 10সোর্স 10.
  • Testing what Ansible already tests. There is no need to check the return codes of commands, because Ansible checks them automatically Source 28সোর্স 28.
  • Treating a clean lint as a test of the result. The playbooks page describes ansible-lint as feedback on your playbooks before you execute them Source 10সোর্স 10. In step 7, site.yml met the production profile, and steps 3 and 5 showed what the playbook does to the file.
  • Putting a vault password file in Git. The docs say not to add password files to source control Source 44সোর্স 44.
  • Leaving --diff on for a secret. Because --diff can reveal sensitive information, you can disable it for a task with diff: false Source 15সোর্স 15.
  • Mixing production and development in one inventory. If an inventory contains both, developers who use it would be able to access production secrets Source 29সোর্স 29.
  • Not knowing where the tools write. The setting ANSIBLE_HOME is the default root path for Ansible config files on the controller, and its default is ~/.ansible Source 30সোর্স 30. The setting remote_tmp is the temporary directory to use on targets when executing tasks, and its default is ~/.ansible/tmp Source 9সোর্স 9. In the tutorial's run, the empty home folder held the file ~/.cache/ansible-lint/latest.json after the steps. Use an empty HOME for a practice run. Look into a folder before you delete it, because the docs say not to delete shared ~/.ansible or ANSIBLE_HOME directories when they contain installed roles or collections Source 33সোর্স 33.

সহজ English

  • Reading ping as a network test. The ping module always returns pong on successful contact Source 39সোর্স 39. It does not make sense in playbooks, but it is useful from /usr/bin/ansible to verify the ability to log in and that a usable Python is configured Source 39সোর্স 39.
  • Running shell or command without changed_when. You should always use the changed_when clause on tasks that do not naturally detect if a change has occurred Source 35সোর্স 35. Some of the most common examples are the shell and command modules, which run arbitrary commands Source 35সোর্স 35. The rule no-changed-when of ansible-lint checks that tasks return changes to results or conditions Source 35সোর্স 35. Step 7 shows it.
  • Treating check mode as a full preview. Check mode is just a simulation Source 15সোর্স 15. Modules that do not support check mode report nothing and do nothing Source 15সোর্স 15. Ordinarily, scripts and commands do not run in check mode Source 28সোর্স 28. A task with check_mode: false runs in normal mode and makes changes to the system, even when the playbook is called with --check Source 15সোর্স 15.
  • Reading the exit status of a check as the result. In steps 4 and 5, the exit status of --check was 0, although the check reported a change. The tutorial looked at the recap instead.
  • Reading ok as "the task did not run". In steps 4 and 5, the handler ran and printed ok, because its copy task found nothing to change.
  • Expecting a handler to run at once, or after a failure. Handlers run in the order of the handlers section, and not in the order of the notify list Source 13সোর্স 13. Notifying the same handler multiple times results in executing the handler only once, regardless of how many tasks notify it Source 13সোর্স 13. The meta: flush_handlers task triggers the handlers that have been notified at that point in the play Source 13সোর্স 13. The option --force-handlers runs handlers even if a task fails Source 20সোর্স 20. Step 3 shows that --list-tasks does not list handlers.
  • Using ignore_errors to hide a failure. The directive only works when the task can run and returns a value of failed Source 16সোর্স 16. It does not make Ansible ignore undefined variable errors, connection failures, execution issues, or syntax errors Source 16সোর্স 16.
  • Leaving a file mode unquoted. For consistent results, quote octal numbers, so that Ansible receives a string Source 21সোর্স 21.
  • Leaving plays and tasks without names. In its output, Ansible shows you the name of each named entity it runs Source 29সোর্স 29. The rule name[play] says that all plays should be named, and name[missing] says that all tasks should be named Source 34সোর্স 34. Step 7 shows both.
  • Using the short name of a module. For Ansible 2.10 and later, you should use the fully-qualified collection name (FQCN) in your playbooks Source 10সোর্স 10.
  • Testing what Ansible already tests. There is no need to check the return codes of commands, because Ansible checks them automatically Source 28সোর্স 28.
  • Treating a clean lint as a test of the result. The playbooks page describes ansible-lint as feedback on your playbooks before you execute them Source 10সোর্স 10. In step 7, site.yml met the production profile, and steps 3 and 5 showed what the playbook does to the file.
  • Putting a vault password file in Git. The docs say not to add password files to source control Source 44সোর্স 44.
  • Leaving --diff on for a secret. Because --diff can reveal sensitive information, you can disable it for a task with diff: false Source 15সোর্স 15.
  • Mixing production and development in one inventory. If an inventory contains both, developers who use it would be able to access production secrets Source 29সোর্স 29.
  • Not knowing where the tools write. The setting ANSIBLE_HOME is the default root path for Ansible config files on the controller, and its default is ~/.ansible Source 30সোর্স 30. The setting remote_tmp is the temporary directory to use on targets when executing tasks, and its default is ~/.ansible/tmp Source 9সোর্স 9. In the tutorial's run, the empty home folder held the file ~/.cache/ansible-lint/latest.json after the steps. Use an empty HOME for a practice run. Look into a folder before you delete it, because the docs say not to delete shared ~/.ansible or ANSIBLE_HOME directories when they contain installed roles or collections Source 33সোর্স 33.

বাংলা ব্যাখ্যা

  • ping-কে network test ভাবা। ping module সফল যোগাযোগে সবসময় pong ফেরত দেয় Source 39সোর্স 39। এটা playbook-এ অর্থবহ নয়, কিন্তু login করার ক্ষমতা আর একটা ব্যবহারযোগ্য Python ঠিক করা আছে কি না যাচাই করতে /usr/bin/ansible থেকে কাজে লাগে Source 39সোর্স 39।
  • changed_when ছাড়া shell বা command চালানো। যে task স্বাভাবিকভাবে ধরতে পারে না কোনো পরিবর্তন হয়েছে কি না, তাতে সবসময় changed_when clause ব্যবহার করা উচিত Source 35সোর্স 35। সবচেয়ে প্রচলিত উদাহরণগুলোর মধ্যে আছে shell আর command module, যারা যেকোনো command চালায় Source 35সোর্স 35। ansible-lint-এর no-changed-when rule যাচাই করে task ফলাফল বা condition দিয়ে পরিবর্তন জানায় কি না Source 35সোর্স 35। ৭ নম্বর ধাপ সেটা দেখায়।
  • check mode-কে পূর্ণ পূর্বরূপ ভাবা। check mode শুধু একটা simulation Source 15সোর্স 15। যে module check mode সমর্থন করে না, তারা কিছু জানায় না আর কিছু করে না Source 15সোর্স 15। সাধারণত script আর command check mode-এ চলে না Source 28সোর্স 28। check_mode: false দেওয়া একটা task playbook --check দিয়ে ডাকা হলেও স্বাভাবিক mode-এ চলে আর system-এ পরিবর্তন করে Source 15সোর্স 15।
  • একটা check-এর exit status-কে ফল ভাবা। ৪ আর ৫ নম্বর ধাপে --check-এর exit status ছিল ০, যদিও check একটা পরিবর্তন জানিয়েছে। টিউটোরিয়াল তার বদলে সারাংশ দেখেছে।
  • ok-কে "task চলেনি" ভাবা। ৪ আর ৫ নম্বর ধাপে handler চলেছে আর ok ছেপেছে, কারণ তার copy task-এর বদলানোর কিছু ছিল না।
  • আশা করা handler সঙ্গে সঙ্গে চলবে, বা ব্যর্থতার পরেও চলবে। handler চলে handlers section-এর ক্রমে, notify তালিকার ক্রমে নয় Source 13সোর্স 13। একই handler বহুবার notify করলে সেটা একবারই চলে Source 13সোর্স 13। meta: flush_handlers task play-র সেই বিন্দুতে notify হয়ে থাকা handler চালু করে Source 13সোর্স 13। --force-handlers option কোনো task ব্যর্থ হলেও handler চালায় Source 20সোর্স 20। ৩ নম্বর ধাপ দেখায় --list-tasks handler তালিকাভুক্ত করে না।
  • ব্যর্থতা লুকাতে ignore_errors ব্যবহার করা। এই directive কাজ করে শুধু যখন task চলতে পারে আর failed মান ফেরত দেয় Source 16সোর্স 16। এটা undefined variable error, connection ব্যর্থতা, execution সমস্যা বা syntax error উপেক্ষা করায় না Source 16সোর্স 16।
  • file mode quote ছাড়া রাখা। সঙ্গতিপূর্ণ ফলের জন্য octal সংখ্যা quote করুন, যাতে Ansible একটা string পায় Source 21সোর্স 21।
  • play আর task-কে নাম ছাড়া রাখা। output-এ Ansible প্রতিটা নামযুক্ত জিনিসের নাম দেখায়, যা সে চালায় Source 29সোর্স 29। name[play] rule বলে সব play-এর নাম থাকা উচিত, আর name[missing] বলে সব task-এর নাম থাকা উচিত Source 34সোর্স 34। ৭ নম্বর ধাপ দুটোই দেখায়।
  • module-এর ছোট নাম ব্যবহার করা। Ansible 2.10 আর তার পরে আপনার playbook-এ fully-qualified collection name (FQCN) ব্যবহার করা উচিত Source 10সোর্স 10।
  • Ansible যা আগেই test করে তা test করা। command-এর return code যাচাই করার দরকার নেই, কারণ Ansible সেগুলো আপনা থেকেই যাচাই করে Source 28সোর্স 28।
  • পরিষ্কার lint-কে ফলের test ভাবা। playbook page ansible-lint-কে বর্ণনা করে আপনার playbook চালানোর আগে মতামত হিসেবে Source 10সোর্স 10। ৭ নম্বর ধাপে site.yml production profile পূরণ করেছে, আর ৩ ও ৫ নম্বর ধাপ দেখিয়েছে playbook file-টার সঙ্গে কী করে।
  • vault password file Git-এ রাখা। docs বলে, password file source control-এ যোগ না করতে Source 44সোর্স 44।
  • secret-এর জন্য --diff চালু রাখা। --diff সংবেদনশীল তথ্য প্রকাশ করতে পারে বলে আপনি একটা task-এর জন্য diff: false দিয়ে সেটা বন্ধ করতে পারেন Source 15সোর্স 15।
  • একটা inventory-তে production আর development মেশানো। একটা inventory-তে দুটোই থাকলে সেটা যারা ব্যবহার করেন সেই developer-রা production-এর secret-এ প্রবেশ করতে পারতেন Source 29সোর্স 29।
  • tool-গুলো কোথায় লেখে তা না জানা। ANSIBLE_HOME setting হলো controller-এ Ansible config file-এর default root path, আর এর default ~/.ansible Source 30সোর্স 30। remote_tmp setting হলো target-এ task চালানোর সময় ব্যবহারের অস্থায়ী directory, আর এর default ~/.ansible/tmp Source 9সোর্স 9। টিউটোরিয়ালের run-এ ধাপগুলোর পর খালি home folder-এ ছিল ~/.cache/ansible-lint/latest.json file। practice run-এর জন্য একটা খালি HOME ব্যবহার করুন। কোনো folder মোছার আগে ভেতরে দেখুন, কারণ docs বলে, shared ~/.ansible বা ANSIBLE_HOME directory-তে ইনস্টল করা role বা collection থাকলে সেগুলো না মুছতে Source 33সোর্স 33।

What a tester can check

Tutorial advice

This list is the tutorial's own advice for a tester who works with Ansible.

  • Run ansible-playbook --syntax-check and ansible-lint on every pull request, and fail the build on a non-zero exit status.
  • Run a playbook twice on a clean machine, and expect changed=0 in the second run.
  • Run --check --diff against a system before you deploy, and read the diff, and not only the exit status.
  • Count the changes in the recap of a check run, and fail the test when the count is above 0 for a system that must not drift.
  • Write a test playbook with assert, and write one failing variant of it, to prove that the test can fail.
  • Name every play and task, and use the full name of every module, so that a failure points to a name that you can read.
  • Set changed_when on every command and shell task.
  • Keep vault passwords, vault password files, and decrypted output out of Git, bug reports, and chat messages.
  • Use diff: false on tasks that handle secrets.
  • Use made-up values and a throwaway folder for a practice run, and use an empty HOME.
  • Use a separate inventory for each environment, and give a tester only the inventory of the test environment.
  • Keep the date, the versions of ansible-core and ansible-lint, and the exact commands with every test result.

সহজ English

Tutorial advice

This list is the tutorial's own advice for a tester who works with Ansible.

  • Run ansible-playbook --syntax-check and ansible-lint on every pull request, and fail the build on a non-zero exit status.
  • Run a playbook twice on a clean machine, and expect changed=0 in the second run.
  • Run --check --diff against a system before you deploy, and read the diff, and not only the exit status.
  • Count the changes in the recap of a check run, and fail the test when the count is above 0 for a system that must not drift.
  • Write a test playbook with assert, and write one failing variant of it, to prove that the test can fail.
  • Name every play and task, and use the full name of every module, so that a failure points to a name that you can read.
  • Set changed_when on every command and shell task.
  • Keep vault passwords, vault password files, and decrypted output out of Git, bug reports, and chat messages.
  • Use diff: false on tasks that handle secrets.
  • Use made-up values and a throwaway folder for a practice run, and use an empty HOME.
  • Use a separate inventory for each environment, and give a tester only the inventory of the test environment.
  • Keep the date, the versions of ansible-core and ansible-lint, and the exact commands with every test result.

বাংলা ব্যাখ্যা

Tutorial advice

এই তালিকা টিউটোরিয়ালের নিজের পরামর্শ, এমন একজন tester-এর জন্য যিনি Ansible নিয়ে কাজ করেন।

  • প্রতিটা pull request-এ ansible-playbook --syntax-check আর ansible-lint চালান, আর শূন্য নয় এমন exit status হলে build ব্যর্থ করুন।
  • একটা পরিষ্কার মেশিনে একটা playbook দুবার চালান, আর দ্বিতীয় run-এ changed=0 আশা করুন।
  • deploy করার আগে একটা system-এর বিপরীতে --check --diff চালান, আর diff পড়ুন, শুধু exit status নয়।
  • একটা check run-এর সারাংশের পরিবর্তন গুনুন, আর যে system-এর drift করা চলবে না, তার জন্য সংখ্যা ০-র বেশি হলে test ব্যর্থ করুন।
  • assert দিয়ে একটা test playbook লিখুন, আর তার একটা ব্যর্থ রূপও লিখুন, প্রমাণ করতে যে test ব্যর্থ হতে পারে।
  • প্রতিটা play আর task-এর নাম দিন, আর প্রতিটা module-এর পুরো নাম ব্যবহার করুন, যাতে ব্যর্থতা এমন একটা নাম দেখায়, যা আপনি পড়তে পারেন।
  • প্রতিটা command আর shell task-এ changed_when সেট করুন।
  • vault password, vault password file আর decrypt করা output Git, bug report আর chat message-এর বাইরে রাখুন।
  • যে task secret সামলায় তাতে diff: false ব্যবহার করুন।
  • practice run-এর জন্য বানানো মান আর একটা ফেলে দেওয়ার মতো folder ব্যবহার করুন, আর একটা খালি HOME ব্যবহার করুন।
  • প্রতিটা পরিবেশের জন্য আলাদা inventory ব্যবহার করুন, আর একজন tester-কে শুধু test পরিবেশের inventory দিন।
  • প্রতিটা test-এর ফলের সঙ্গে তারিখ, ansible-core ও ansible-lint-এর version আর হুবহু command রাখুন।

Key words

TermMeaning
Agent-lessAnsible is designed around an agent-less architecture
Desired stateYou declare the desired state of a local or remote system in your playbook
Control nodeA system on which Ansible is installed
Managed nodeA remote system, or host, that Ansible controls
InventoryA list of managed nodes that are logically organized
PlaybookPlaybooks are automation blueprints, in YAML format, that Ansible uses to deploy and configure managed nodes
PlayAn ordered list of tasks that maps to managed nodes in an inventory
TaskA reference to a single module that defines the operations that Ansible performs
ModuleA unit of code or binary that Ansible runs on managed nodes
Ad hoc commandAn ad hoc command uses the /usr/bin/ansible command-line tool to automate a single task on one or more managed nodes
IdempotentAn operation is idempotent if the result of performing it once is exactly the same as the result of performing it repeatedly without any intervening actions
VariableAnsible uses variables to manage differences between systems
FactFacts are things that are discovered about remote nodes
TemplateTemplates are processed by the Jinja2 templating language
HandlerHandlers are tasks that only run when notified
BlockBlocks create logical groups of tasks
RoleRoles let you automatically load related vars, files, tasks, handlers, and other Ansible artifacts based on a known file structure
Check modeIn check mode, Ansible runs without making any changes on remote systems
Diff modeIn diff mode, Ansible provides before-and-after comparisons
Ansible VaultAnsible vault provides a way to encrypt and manage sensitive data such as passwords
Ansible LintAnsible Lint is a command-line tool for linting playbooks, roles and collections
ProfileProfiles gradually increase the strictness of the rules
MoleculeMolecule is an Ansible testing framework designed for developing and testing Ansible collections, playbooks, and roles

Reels on this topicএই টপিকের রিলস

Short videos from other creators, picked for this topic. They are not part of this page's fact-checked text. Nothing loads from YouTube until you press Play.অন্য ক্রিয়েটরদের বানানো ছোট ভিডিও, এই টপিকের জন্য বাছাই করা। এগুলো এই পেজের ফ্যাক্ট-চেক করা লেখার অংশ নয়। চালান বাটন চাপার আগে YouTube থেকে কিছুই লোড হয় না।

  1. [1]
    Introduction to Ansible

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  2. [2]
    Getting started with Ansible

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  3. [3]
    Building an inventory

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  4. [4]
    Creating a playbook

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  5. [5]
    Installing Ansible

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  6. [6]
    How to build your inventory

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  7. [7]
    ansible.builtin.local connection

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  8. [8]
    Interpreter Discovery

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  9. [9]
    ansible.builtin.sh shell

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  10. [10]
    Ansible playbooks

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  11. [11]
    Using variables

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  12. [12]
    Templating (Jinja2)

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  13. [13]
    Handlers: running operations on change

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  14. [14]
    Roles

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  15. [15]
    Validating tasks: check mode and diff mode

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  16. [16]
    Error handling in playbooks

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  17. [17]
    Blocks

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  18. [18]
    Return Values

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  19. [19]
    Glossary

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  20. [20]
    ansible-playbook

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  21. [21]
    ansible.builtin.file module

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  22. [22]
    ansible.builtin.copy module

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  23. [23]
    ansible.builtin.template module

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  24. [24]
    ansible.builtin.slurp module

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  25. [25]
    ansible.builtin.assert module

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  26. [26]
    Protecting sensitive data with Ansible vault

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  27. [27]
    Encrypting content with Ansible Vault

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  28. [28]
    Testing Strategies

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  29. [29]
    Ansible tips and tricks

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  30. [30]
    Ansible Configuration Settings

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  31. [31]
    Ansible Lint Documentation

    Ansible Lint Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  32. [32]
    Profiles

    Ansible Lint Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  33. [33]
    Using

    Ansible Lint Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  34. [34]
    name

    Ansible Lint Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  35. [35]
    no-changed-when

    Ansible Lint Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  36. [36]
    risky-file-permissions

    Ansible Lint Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  37. [37]
    Ansible Molecule

    Ansible Molecule Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  38. [38]
    ansible-inventory

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  39. [39]
    ansible.builtin.ping module

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  40. [40]
    ansible.builtin.stat module

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  41. [41]
    ansible-vault

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  42. [42]
    Introduction to ad hoc commands

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  43. [43]
    Special Variables

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  44. [44]
    Managing vault passwords

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19

  45. [45]
    Playbook Keywords

    Ansible Community Documentation · accessed 2026-11-19দেখা হয়েছে: 2026-11-19