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 দেখুন।
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 --versionOutput 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.1ansible --versionprinted the version of the packageansible-core,[core 2.22.0], and the paths that the run used. The folder of the run holds noansible.cfgfile, and the output saysconfig 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 settingANSIBLE_HOMEis the default root path for Ansible config files on the controller Source 30সোর্স 30.ansible-lint --versionprintedansible-lint 26.11.0, and it also printed the version ofansible-corethat 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: localThe 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.pingOutput 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 --graphprinted a tree of the inventory. The--graphoption creates an inventory graph, and a pattern that you supply must be a valid group name Source 38সোর্স 38. The group@allholds the groups@ungroupedand@app, andlocalhostis under@app. The tutorial defined no groupungrouped, and Ansible still created it. It creates the two default groupsallandungrouped, even if you define no groups Source 6সোর্স 6.ansible-inventory --listprinted the same inventory as JSON. The--listoption outputs all hosts info, and it works as an inventory script Source 38সোর্স 38. The variableansible_connectionoflocalhostis under_metaandhostvars. The block_metaalso has a keyprofilewith the valueinventory_legacy. No page that the tutorial read describes that key.ansible app -i inventory.yml -m ansible.builtin.pingis an ad hoc command. An ad hoc command uses the/usr/bin/ansiblecommand-line tool to automate a single task on one or more managed nodes Source 42সোর্স 42. It looks likeansible [pattern] -m [module] -a "[module options]"Source 42সোর্স 42. Hereappis the pattern, andansible.builtin.pingis the module. Thepingmodule is a trivial test module that always returnspongon successful contact Source 39সোর্স 39. It is useful from/usr/bin/ansibleto verify the ability to log in, and that a usable Python is configured Source 39সোর্স 39. The output hasSUCCESS,"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
autoissues a warning that a future installation of another Python interpreter could alter the one chosen Source 8সোর্স 8. In the run,discovered_interpreter_pythonis/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: appmakes the play target the groupapp. The keywordhostsis a list of groups, hosts, or host patterns that translate into the targets of the play Source 45সোর্স 45.- The section
varsholds three variables for the play Source 45সোর্স 45. The variableplaybook_diris the path to the directory of the current playbook Source 43সোর্স 43. So the playbook writes into a folderoutnext to itself. - The keyword
gather_factsis a boolean that controls if the play will automatically run thesetuptask to gather facts for the hosts Source 45সোর্স 45. The tutorial setsgather_facts: false, because the playbook uses no facts. The output has noGathering Factstask. - The
filetask creates the folderout. Withstate: 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
templatetask renderstemplates/settings.env.j2intoout/qa.env. Thesrcis the path of a Jinja2 formatted template on the controller Source 23সোর্স 23, anddestis 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 foldertemplates/holds files for use with the template resource, and templates end in.j2Source 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 changenames the handler. The keywordnotifyis a list of handlers to notify when the task returns achanged=Truestatus Source 45সোর্স 45. Thehandlerssection holds tasks that do not run normally, only when notified after each section of tasks is complete Source 45সোর্স 45. The handler writes the textsettings changedintoout/changed.logwith thecopymodule. When you usecontentinstead ofsrc, 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-checkprintedplaybook: 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-tasksprinted 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 printedRUNNING HANDLER [Record the change], and that saidchangedtoo. The recap saysok=3andchanged=3, and the exit status was 0.catprinted the rendered file,env=qaandbase_url=http://localhost:8080, and then the log,settings changed. - The second run printed
okfor both tasks, and it ran no handler. The recap saysok=2andchanged=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 achanged=Truestatus 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-checkor--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.envOutput 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
-esets additional variables askey=valueSource 20সোর্স 20. Extra vars, for example-e "user=my_user", always win precedence Source 11সোর্স 11. Sobase_urlwashttp://localhost:9090in this run, and not the value of the play. --checkruns the playbook without making any changes on remote systems, and--diffprovides 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:8080and+base_url=http://localhost:9090. That task saidchanged, and the recap sayschanged=1.- The path after
+++ after:is under.ansible/tmpin the empty home folder of the run, and parts of its name change in each run. The settingDEFAULT_LOCAL_TMPis 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.envstill printedbase_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 filechanged.logalready heldsettings 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.envOutput 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.envholds onlyenv=changed-by-hand. It is the tutorial's own way to make the file differ from the playbook. --check --diffprinted a diff:-env=changed-by-hand,+env=qa, and+base_url=http://localhost:8080. The template task saidchanged, and the recap sayschanged=1. The exit status of the check was 0 again, so the exit status does not tell you if there is a difference.- The
grepis the tutorial's own test. It looks forchanged=with a count above 0 in the recap of a check run, and theechoprinteddrift 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 namedCheck Mode As A Drift TestSource 28সোর্স 28. - After the check,
catstill printedenv=changed-by-hand. The check did not repair the file. - The real run repaired it. The template task said
changed, the handler ran and saidok, and the recap saysok=3andchanged=1.catprintedenv=qaandbase_url=http://localhost:8080again. The handler ran because a task notified it, and its owncopytask 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
slurptask readsout/qa.env. The module is used for fetching a base64-encoded blob containing the data in a remote file Source 24সোর্স 24. The keywordregisteris the name of the variable that will contain the task status and the module return data Source 45সোর্স 45. Sosettingsholds the result of theslurptask. - The
stattask registers the status of the file insettings_stat. The module retrieves facts for a file, similar to the Linux/Unixstatcommand Source 40সোর্স 40. Its return valuemodeholds 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
asserttask has three expressions inthat. The optionthatis a list of string expressions of the same form that can be passed to thewhenstatement Source 25সোর্স 25. The example of theslurpmodule uses the expression{{ mounts['content'] | b64decode }}to decode the content Source 24সোর্স 24. The first two expressions of the test do the same withsettings.content, and check that the text holdsenv=qaandbase_url=http://localhost:8080. The third checks the mode. The optionsuccess_msgis the customized message used for a successful assertion, andfail_msgis 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
okfor all three tasks. Theasserttask printed itssuccess_msg,The settings are what the test expects., and the exit status was 0. - The
sedcommand madebad-check.yml, a copy that expectsenv=prod. In that run, theasserttask failed. The output hasfatal: [localhost]: FAILED!, the expression that failed,"evaluated_to": false, and thefail_msg. The recap saysfailed=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 ofansible-playbook. - The failure begins with
[ERROR]: Task failed: Action failed:, and the lineOrigin: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.ymlandcheck.yml. The option--project-diris the location of project/repository Source 33সোর্স 33. The result isPassed: 0 failure(s), 0 warning(s), the last profile that the files met isproduction, 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--profiletakes one ofmin,basic,moderate,safety,shared, andproductionSource 33সোর্স 33. Theproductionprofile 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 callbacksonelineandtreehave been deprecated, and that the feature will be removed from ansible-core version 2.23. Both sayOrigin: <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 settingDEPRECATION_WARNINGSis a toggle to control the showing of deprecation warnings Source 30সোর্স 30, and its environment variable isANSIBLE_DEPRECATION_WARNINGSSource 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 runsansible.builtin.command, and acopytask without amode, whose name starts with a lowercase letter. ansible-lint reported five violations, and the exit status was 2. - The rule
namechecks the names:name[play]says that all plays should be named,name[missing]that all tasks should be named, andname[casing]that all names should start with an uppercase letter for languages that support it Source 34সোর্স 34. The ruleno-changed-whenchecks that tasks return changes to results or conditions Source 35সোর্স 35. The rulerisky-file-permissionsis 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 listsnamethree times, once for each of its violations. - The summary shows
profile:basicfor all five violations, and the last profile that the file met ismin. Theminprofile ensures that Ansible can load content Source 32সোর্স 32. Thebasicprofile 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}/.ansiblewhen 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.txtOutput of the tutorial's run:
$ANSIBLE_VAULT;1.1;AES256
31353436626163303837616632383237326136666565343433393465366663346538633966316231
0
db_password: made-up-db-passwordThe password and the secret of this step are made up for the tutorial.
ansible-vaultis 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 encryptcommand Source 27সোর্স 27. The option--vault-password-filetakes a vault password file Source 41সোর্স 41. The command printed nothing in this run. head -n 2 secrets.ymlprinted 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;AES256Source 27সোর্স 27.grep -cprinted0, so no line of the encrypted file holds the textmade-up-db-password.ansible-vault viewprinteddb_password: made-up-db-password. To view the contents of an encrypted file without editing it, you can use theansible-vault viewcommand 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 --versionOutput 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.1ansible --versionprinted the version of the packageansible-core,[core 2.22.0], and the paths that the run used. The folder of the run holds noansible.cfgfile, and the output saysconfig 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 settingANSIBLE_HOMEis the default root path for Ansible config files on the controller Source 30সোর্স 30.ansible-lint --versionprintedansible-lint 26.11.0, and it also printed the version ofansible-corethat 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: localThe 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.pingOutput 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 --graphprinted a tree of the inventory. The--graphoption creates an inventory graph, and a pattern that you supply must be a valid group name Source 38সোর্স 38. The group@allholds the groups@ungroupedand@app, andlocalhostis under@app. The tutorial defined no groupungrouped, and Ansible still created it. It creates the two default groupsallandungrouped, even if you define no groups Source 6সোর্স 6.ansible-inventory --listprinted the same inventory as JSON. The--listoption outputs all hosts info, and it works as an inventory script Source 38সোর্স 38. The variableansible_connectionoflocalhostis under_metaandhostvars. The block_metaalso has a keyprofilewith the valueinventory_legacy. No page that the tutorial read describes that key.ansible app -i inventory.yml -m ansible.builtin.pingis an ad hoc command. An ad hoc command uses the/usr/bin/ansiblecommand-line tool to automate a single task on one or more managed nodes Source 42সোর্স 42. It looks likeansible [pattern] -m [module] -a "[module options]"Source 42সোর্স 42. Hereappis the pattern, andansible.builtin.pingis the module. Thepingmodule is a trivial test module that always returnspongon successful contact Source 39সোর্স 39. It is useful from/usr/bin/ansibleto verify the ability to log in, and that a usable Python is configured Source 39সোর্স 39. The output hasSUCCESS,"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
autoissues a warning that a future installation of another Python interpreter could alter the one chosen Source 8সোর্স 8. In the run,discovered_interpreter_pythonis/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: appmakes the play target the groupapp. The keywordhostsis a list of groups, hosts, or host patterns that translate into the targets of the play Source 45সোর্স 45.- The section
varsholds three variables for the play Source 45সোর্স 45. The variableplaybook_diris the path to the directory of the current playbook Source 43সোর্স 43. So the playbook writes into a folderoutnext to itself. - The keyword
gather_factsis a boolean that controls if the play will automatically run thesetuptask to gather facts for the hosts Source 45সোর্স 45. The tutorial setsgather_facts: false, because the playbook uses no facts. The output has noGathering Factstask. - The
filetask creates the folderout. Withstate: 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
templatetask renderstemplates/settings.env.j2intoout/qa.env. Thesrcis the path of a Jinja2 formatted template on the controller Source 23সোর্স 23, anddestis 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 foldertemplates/holds files for use with the template resource, and templates end in.j2Source 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 changenames the handler. The keywordnotifyis a list of handlers to notify when the task returns achanged=Truestatus Source 45সোর্স 45. Thehandlerssection holds tasks that do not run normally, only when notified after each section of tasks is complete Source 45সোর্স 45. The handler writes the textsettings changedintoout/changed.logwith thecopymodule. When you usecontentinstead ofsrc, 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-checkprintedplaybook: 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-tasksprinted 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 printedRUNNING HANDLER [Record the change], and that saidchangedtoo. The recap saysok=3andchanged=3, and the exit status was 0.catprinted the rendered file,env=qaandbase_url=http://localhost:8080, and then the log,settings changed. - The second run printed
okfor both tasks, and it ran no handler. The recap saysok=2andchanged=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 achanged=Truestatus 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-checkor--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.envOutput 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
-esets additional variables askey=valueSource 20সোর্স 20. Extra vars, for example-e "user=my_user", always win precedence Source 11সোর্স 11. Sobase_urlwashttp://localhost:9090in this run, and not the value of the play. --checkruns the playbook without making any changes on remote systems, and--diffprovides 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:8080and+base_url=http://localhost:9090. That task saidchanged, and the recap sayschanged=1.- The path after
+++ after:is under.ansible/tmpin the empty home folder of the run, and parts of its name change in each run. The settingDEFAULT_LOCAL_TMPis 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.envstill printedbase_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 filechanged.logalready heldsettings 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.envOutput 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.envholds onlyenv=changed-by-hand. It is the tutorial's own way to make the file differ from the playbook. --check --diffprinted a diff:-env=changed-by-hand,+env=qa, and+base_url=http://localhost:8080. The template task saidchanged, and the recap sayschanged=1. The exit status of the check was 0 again, so the exit status does not tell you if there is a difference.- The
grepis the tutorial's own test. It looks forchanged=with a count above 0 in the recap of a check run, and theechoprinteddrift 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 namedCheck Mode As A Drift TestSource 28সোর্স 28. - After the check,
catstill printedenv=changed-by-hand. The check did not repair the file. - The real run repaired it. The template task said
changed, the handler ran and saidok, and the recap saysok=3andchanged=1.catprintedenv=qaandbase_url=http://localhost:8080again. The handler ran because a task notified it, and its owncopytask 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
slurptask readsout/qa.env. The module is used for fetching a base64-encoded blob containing the data in a remote file Source 24সোর্স 24. The keywordregisteris the name of the variable that will contain the task status and the module return data Source 45সোর্স 45. Sosettingsholds the result of theslurptask. - The
stattask registers the status of the file insettings_stat. The module retrieves facts for a file, similar to the Linux/Unixstatcommand Source 40সোর্স 40. Its return valuemodeholds 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
asserttask has three expressions inthat. The optionthatis a list of string expressions of the same form that can be passed to thewhenstatement Source 25সোর্স 25. The example of theslurpmodule uses the expression{{ mounts['content'] | b64decode }}to decode the content Source 24সোর্স 24. The first two expressions of the test do the same withsettings.content, and check that the text holdsenv=qaandbase_url=http://localhost:8080. The third checks the mode. The optionsuccess_msgis the customized message used for a successful assertion, andfail_msgis 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
okfor all three tasks. Theasserttask printed itssuccess_msg,The settings are what the test expects., and the exit status was 0. - The
sedcommand madebad-check.yml, a copy that expectsenv=prod. In that run, theasserttask failed. The output hasfatal: [localhost]: FAILED!, the expression that failed,"evaluated_to": false, and thefail_msg. The recap saysfailed=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 ofansible-playbook. - The failure begins with
[ERROR]: Task failed: Action failed:, and the lineOrigin: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.ymlandcheck.yml. The option--project-diris the location of project/repository Source 33সোর্স 33. The result isPassed: 0 failure(s), 0 warning(s), the last profile that the files met isproduction, 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--profiletakes one ofmin,basic,moderate,safety,shared, andproductionSource 33সোর্স 33. Theproductionprofile 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 callbacksonelineandtreehave been deprecated, and that the feature will be removed from ansible-core version 2.23. Both sayOrigin: <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 settingDEPRECATION_WARNINGSis a toggle to control the showing of deprecation warnings Source 30সোর্স 30, and its environment variable isANSIBLE_DEPRECATION_WARNINGSSource 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 runsansible.builtin.command, and acopytask without amode, whose name starts with a lowercase letter. ansible-lint reported five violations, and the exit status was 2. - The rule
namechecks the names:name[play]says that all plays should be named,name[missing]that all tasks should be named, andname[casing]that all names should start with an uppercase letter for languages that support it Source 34সোর্স 34. The ruleno-changed-whenchecks that tasks return changes to results or conditions Source 35সোর্স 35. The rulerisky-file-permissionsis 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 listsnamethree times, once for each of its violations. - The summary shows
profile:basicfor all five violations, and the last profile that the file met ismin. Theminprofile ensures that Ansible can load content Source 32সোর্স 32. Thebasicprofile 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}/.ansiblewhen 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.txtOutput of the tutorial's run:
$ANSIBLE_VAULT;1.1;AES256
31353436626163303837616632383237326136666565343433393465366663346538633966316231
0
db_password: made-up-db-passwordThe password and the secret of this step are made up for the tutorial.
ansible-vaultis 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 encryptcommand Source 27সোর্স 27. The option--vault-password-filetakes a vault password file Source 41সোর্স 41. The command printed nothing in this run. head -n 2 secrets.ymlprinted 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;AES256Source 27সোর্স 27.grep -cprinted0, so no line of the encrypted file holds the textmade-up-db-password.ansible-vault viewprinteddb_password: made-up-db-password. To view the contents of an encrypted file without editing it, you can use theansible-vault viewcommand 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.1ansible --versionansible-corepackage-এর version ছেপেছে,[core 2.22.0], আর run যে path-গুলো ব্যবহার করেছে। run-এর folder-এ কোনোansible.cfgfile নেই, আর output বলেconfig file = None। module আর collection-এর path শুরু হয়/work/home/.ansibleদিয়ে, যা run-এর খালি home folder-এ।ANSIBLE_HOMEsetting হলো controller-এ Ansible config file-এর default root path Source 30সোর্স 30।ansible-lint --versionছেপেছেansible-lint 26.11.0, আর সেটা যেansible-coreversion ব্যবহার করেছে তা-ও ছেপেছে,2.22.0, সঙ্গে আরও দুটো package-এর version।
২. একটা inventory লিখুন, আর সেটা দেখুন। এটা inventory.yml নামে save করুন:
all:
children:
app:
hosts:
localhost:
ansible_connection: localfile-টা একটা 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 --graphinventory-র একটা গাছ ছেপেছে।--graphoption একটা inventory graph বানায়, আর আপনার দেওয়া pattern একটা বৈধ group-এর নাম হতে হবে Source 38সোর্স 38।@allgroup-এ আছে@ungroupedআর@appgroup, আরlocalhostআছে@app-এর নিচে। টিউটোরিয়ালungroupedনামে কোনো group ঠিক করেনি, তবু Ansible সেটা বানিয়েছে। আপনি কোনো group না বানালেও Ansible দুটো default group বানায়,allআরungroupedSource 6সোর্স 6।ansible-inventory --listএকই inventory JSON হিসেবে ছেপেছে।--listoption সব host-এর তথ্য দেয়, আর এটা একটা inventory script-এর মতো কাজ করে Source 38সোর্স 38।localhost-এরansible_connectionvariable আছে_metaআরhostvars-এর নিচে।_metablock-এprofileনামে একটা key-ও আছে, মানinventory_legacy। টিউটোরিয়াল যে page-গুলো পড়েছে, তার কোনোটাই এই key বর্ণনা করে না।ansible app -i inventory.yml -m ansible.builtin.pingএকটা ad hoc command। একটা ad hoc command/usr/bin/ansiblecommand-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।pingmodule একটা তুচ্ছ 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: appplay-কেappgroup লক্ষ্য করায়।hostskeyword হলো group, host বা host pattern-এর একটা তালিকা, যা play-এর লক্ষ্যে পরিণত হয় Source 45সোর্স 45।varssection play-র জন্য তিনটা variable ধরে Source 45সোর্স 45।playbook_dirvariable হলো বর্তমান playbook-এর directory-র path Source 43সোর্স 43। তাই playbook তার পাশেরoutনামের একটা folder-এ লেখে।gather_factskeyword একটা boolean, যা ঠিক করে play আপনা থেকে hosts-এর fact সংগ্রহ করতেsetuptask চালাবে কি না Source 45সোর্স 45। টিউটোরিয়ালgather_facts: falseদিয়েছে, কারণ playbook কোনো fact ব্যবহার করে না। output-এ কোনোGathering Factstask নেই।filetaskoutfolder বানায়।state: directoryদিলে লক্ষ্যটা একটা directory, আর Ansible যেকোনো অনুপস্থিত parent folder বানায় Source 21সোর্স 21। mode"0755", quote-সহ, কারণ octal সংখ্যা quote করা উচিত, যাতে Ansible একটা string পায় Source 21সোর্স 21।templatetasktemplates/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 changehandler-এর নাম দেয়।notifykeyword হলো সেই handler-এর তালিকা, যাদের taskchanged=Truestatus ফেরত দিলে notify করা হয় Source 45সোর্স 45।handlerssection-এ এমন task থাকে, যা স্বাভাবিকভাবে চলে না, চলে শুধু task-এর প্রতিটা section শেষ হওয়ার পর notify করা হলে Source 45সোর্স 45। handlercopymodule দিয়ে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-tasksplay আর তার দুটো 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। taskchanged=Truestatus ফেরত দিলে 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-eoptionkey=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_TMPsetting হলো 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.logfile-এ আগে থেকেই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 TestSource 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 করেছে, আর তার নিজেরcopytask-এর বদলানোর কিছু ছিল না।
৬. 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 আছে:
slurptaskout/qa.envপড়ে। module একটা দূরের file-এর data ধরা base64-encoded blob আনতে ব্যবহার করা হয় Source 24সোর্স 24।registerkeyword হলো সেই variable-এর নাম, যাতে task-এর status আর module-এর ফেরত দেওয়া data থাকবে Source 45সোর্স 45। তাইsettings-এslurptask-এর ফল আছে।stattask file-এর statussettings_stat-এ register করে। module একটা file-এর facts আনে, Linux/Unix-এরstatcommand-এর মতো Source 40সোর্স 40। এরmodeফেরত-মান file-এর Unix permission ধরে, octal রূপে একটা string হিসেবে Source 40সোর্স 40। তাই test সেটাকে'0644'string-এর সঙ্গে মেলায়।asserttask-এরthat-এ তিনটা expression আছে।thatoption হলো একই ধরনের string expression-এর একটা তালিকা, যাwhenstatement-এ দেওয়া যায় Source 25সোর্স 25।slurpmodule-এর উদাহরণ content decode করতে{{ mounts['content'] | b64decode }}expression ব্যবহার করে Source 24সোর্স 24। test-এর প্রথম দুটো expressionsettings.content-এর সঙ্গে একই কাজ করে, আর যাচাই করে text-এenv=qaআরbase_url=http://localhost:8080আছে। তৃতীয়টা mode যাচাই করে।success_msgoption হলো সফল 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ছেপেছে।asserttask তারsuccess_msg,The settings are what the test expects., ছেপেছে, আর exit status ছিল ০। sedcommandbad-check.ymlবানিয়েছে, একটা কপি যাenv=prodআশা করে। সেই run-এasserttask ব্যর্থ হয়েছে। 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.ymllint করে।--project-diroption হলো project বা repository-র অবস্থান Source 33সোর্স 33। ফলPassed: 0 failure(s), 0 warning(s), file দুটো যে শেষ profile পূরণ করেছে সেটাproduction, আর exit status ছিল ০। profile নিয়মের কঠোরতা ধাপে ধাপে বাড়ায়, যেমন যেমন আপনার Ansible content-এর জীবনচক্র পরিণত হয় Source 32সোর্স 32।--profileoption নেয়min,basic,moderate,safety,sharedআরproduction-এর একটা Source 33সোর্স 33।productionprofile নিশ্চিত করে যে content Ansible Automation Platform (AAP)-এ validated বা certified content হিসেবে অন্তর্ভুক্ত হওয়ার শর্ত পূরণ করে Source 32সোর্স 32। - এই ধাপের প্রথম লাইন,
export ANSIBLE_DEPRECATION_WARNINGS=false, টিউটোরিয়ালের নিজের সিদ্ধান্ত। এটা ছাড়া একই command ফলের আগে দুটো deprecation সতর্কবার্তা ছেপেছিল। সেগুলো বলেonelineআরtreecallback deprecated হয়েছে, আর ফিচারটা ansible-core version 2.23 থেকে সরানো হবে। দুটোতেই লেখাOrigin: <unknown>। টিউটোরিয়ালের file আর environment কোনো callback সেট করে না, আর টিউটোরিয়াল যে page-গুলো পড়েছে তার কোনোটাই বলে না ansible-lint সেগুলো কেন ছেপেছে।DEPRECATION_WARNINGSsetting হলো deprecation সতর্কবার্তা দেখানো নিয়ন্ত্রণের একটা toggle Source 30সোর্স 30, আর এর environment variable হলোANSIBLE_DEPRECATION_WARNINGSSource 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.ymllint করে, এমন একটা file, যা টিউটোরিয়াল ইচ্ছে করে লিখেছে আর চালায়নি। এতে আছে নামহীন একটা play,ansible.builtin.commandচালানো নামহীন একটা task, আরmodeছাড়া একটাcopytask, যার নাম ছোট হাতের অক্ষর দিয়ে শুরু। ansible-lint পাঁচটা লঙ্ঘন জানিয়েছে, আর exit status ছিল ২। namerule নামগুলো যাচাই করে:name[play]বলে সব play-এর নাম থাকা উচিত,name[missing]বলে সব task-এর নাম থাকা উচিত, আরname[casing]বলে যেসব ভাষা এটা সমর্থন করে, সেগুলোর জন্য সব নাম বড় হাতের অক্ষর দিয়ে শুরু হওয়া উচিত Source 34সোর্স 34।no-changed-whenrule যাচাই করে task ফলাফল বা condition দিয়ে পরিবর্তন জানায় কি না Source 35সোর্স 35।risky-file-permissionsrule চালু হয় এমন নানা module-এ, যা এমন permission সহ নতুন file বানাতে পারে, যা বেশি খোলা বা অনির্ভরযোগ্য হতে পারে Source 36সোর্স 36। সারাংশnameতিনবার তালিকাভুক্ত করেছে, তার প্রতিটা লঙ্ঘনের জন্য একবার করে।- সারাংশ পাঁচটা লঙ্ঘনের সবগুলোর জন্য
profile:basicদেখায়, আর file-টা যে শেষ profile পূরণ করেছে সেটাmin।minprofile নিশ্চিত করে যে Ansible content load করতে পারে Source 32সোর্স 32।basicprofile সাধারণ coding সমস্যা ঠেকায় আর মান ধরনের style ও formatting চাপায় Source 32সোর্স 32। - ansible-lint ইনস্টল করা role ও collection সহ cache বানায় runtime cache directory-র নিচে, যা offline না হলে সাধারণত
{project}/.ansibleSource 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 encryptcommand ব্যবহার করেন Source 27সোর্স 27।--vault-password-fileoption একটা 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;AES256header সহ 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 viewcommand ব্যবহার করতে পারেন 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
assertmodule 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
statfor what the configuration does not set. If you need to test for the existence of files that your Ansible configuration does not set declaratively, thestatmodule is a great choice Source 28সোর্স 28. Its return valuemodeholds 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
--diffcan reveal sensitive information, you can disable it for a task withdiff: falseSource 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
--strictreturns 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-checkperforms a syntax check on the playbook, but does not execute it Source 20সোর্স 20.--list-hostsoutputs a list of matching hosts, and it does not execute anything else Source 20সোর্স 20.--list-taskslists all tasks that would be executed Source 20সোর্স 20. In step 3, the tutorial ran--syntax-checkand--list-tasksbefore 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 viewshows 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
assertmodule 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
statfor what the configuration does not set. If you need to test for the existence of files that your Ansible configuration does not set declaratively, thestatmodule is a great choice Source 28সোর্স 28. Its return valuemodeholds 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
--diffcan reveal sensitive information, you can disable it for a task withdiff: falseSource 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
--strictreturns 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-checkperforms a syntax check on the playbook, but does not execute it Source 20সোর্স 20.--list-hostsoutputs a list of matching hosts, and it does not execute anything else Source 20সোর্স 20.--list-taskslists all tasks that would be executed Source 20সোর্স 20. In step 3, the tutorial ran--syntax-checkand--list-tasksbefore 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 viewshows 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।
assertmodule নানা ধরনের সত্যতা যাচাই করা খুব সহজ করে Source 28সোর্স 28। ৬ নম্বর ধাপে test playbook-এর লেখা file পড়েছে, আর তার text ও mode যাচাই করেছে। - configuration যা ঠিক করে না, তার জন্য
statব্যবহার করুন। আপনার Ansible configuration যে file-এর অস্তিত্ব ঘোষণামূলকভাবে ঠিক করে না, তা test করার দরকার হলেstatmodule দারুণ পছন্দ 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।
--strictoption warning আর error দুটোতেই শূন্য নয় এমন exit code ফেরত দেয় Source 33সোর্স 33। ৭ নম্বর ধাপে দুটো ভালো file-এর exit status ছিল ০, আর খারাপ file-এর ২। - সস্তা যাচাই আগে করুন।
--syntax-checkplaybook চালায় না 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
pingas a network test. Thepingmodule always returnspongon successful contact Source 39সোর্স 39. It does not make sense in playbooks, but it is useful from/usr/bin/ansibleto verify the ability to log in and that a usable Python is configured Source 39সোর্স 39. - Running
shellorcommandwithoutchanged_when. You should always use thechanged_whenclause on tasks that do not naturally detect if a change has occurred Source 35সোর্স 35. Some of the most common examples are theshellandcommandmodules, which run arbitrary commands Source 35সোর্স 35. The ruleno-changed-whenof 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: falseruns in normal mode and makes changes to the system, even when the playbook is called with--checkSource 15সোর্স 15. - Reading the exit status of a check as the result. In steps 4 and 5, the exit status of
--checkwas 0, although the check reported a change. The tutorial looked at the recap instead. - Reading
okas "the task did not run". In steps 4 and 5, the handler ran and printedok, because itscopytask found nothing to change. - Expecting a handler to run at once, or after a failure. Handlers run in the order of the
handlerssection, and not in the order of thenotifylist 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. Themeta: flush_handlerstask triggers the handlers that have been notified at that point in the play Source 13সোর্স 13. The option--force-handlersruns handlers even if a task fails Source 20সোর্স 20. Step 3 shows that--list-tasksdoes not list handlers. - Using
ignore_errorsto 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, andname[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.ymlmet theproductionprofile, 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
--diffon for a secret. Because--diffcan reveal sensitive information, you can disable it for a task withdiff: falseSource 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_HOMEis the default root path for Ansible config files on the controller, and its default is~/.ansibleSource 30সোর্স 30. The settingremote_tmpis the temporary directory to use on targets when executing tasks, and its default is~/.ansible/tmpSource 9সোর্স 9. In the tutorial's run, the empty home folder held the file~/.cache/ansible-lint/latest.jsonafter the steps. Use an emptyHOMEfor a practice run. Look into a folder before you delete it, because the docs say not to delete shared~/.ansibleorANSIBLE_HOMEdirectories when they contain installed roles or collections Source 33সোর্স 33.
সহজ English
- Reading
pingas a network test. Thepingmodule always returnspongon successful contact Source 39সোর্স 39. It does not make sense in playbooks, but it is useful from/usr/bin/ansibleto verify the ability to log in and that a usable Python is configured Source 39সোর্স 39. - Running
shellorcommandwithoutchanged_when. You should always use thechanged_whenclause on tasks that do not naturally detect if a change has occurred Source 35সোর্স 35. Some of the most common examples are theshellandcommandmodules, which run arbitrary commands Source 35সোর্স 35. The ruleno-changed-whenof 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: falseruns in normal mode and makes changes to the system, even when the playbook is called with--checkSource 15সোর্স 15. - Reading the exit status of a check as the result. In steps 4 and 5, the exit status of
--checkwas 0, although the check reported a change. The tutorial looked at the recap instead. - Reading
okas "the task did not run". In steps 4 and 5, the handler ran and printedok, because itscopytask found nothing to change. - Expecting a handler to run at once, or after a failure. Handlers run in the order of the
handlerssection, and not in the order of thenotifylist 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. Themeta: flush_handlerstask triggers the handlers that have been notified at that point in the play Source 13সোর্স 13. The option--force-handlersruns handlers even if a task fails Source 20সোর্স 20. Step 3 shows that--list-tasksdoes not list handlers. - Using
ignore_errorsto 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, andname[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.ymlmet theproductionprofile, 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
--diffon for a secret. Because--diffcan reveal sensitive information, you can disable it for a task withdiff: falseSource 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_HOMEis the default root path for Ansible config files on the controller, and its default is~/.ansibleSource 30সোর্স 30. The settingremote_tmpis the temporary directory to use on targets when executing tasks, and its default is~/.ansible/tmpSource 9সোর্স 9. In the tutorial's run, the empty home folder held the file~/.cache/ansible-lint/latest.jsonafter the steps. Use an emptyHOMEfor a practice run. Look into a folder before you delete it, because the docs say not to delete shared~/.ansibleorANSIBLE_HOMEdirectories when they contain installed roles or collections Source 33সোর্স 33.
বাংলা ব্যাখ্যা
ping-কে network test ভাবা।pingmodule সফল যোগাযোগে সবসময়pongফেরত দেয় Source 39সোর্স 39। এটা playbook-এ অর্থবহ নয়, কিন্তু login করার ক্ষমতা আর একটা ব্যবহারযোগ্য Python ঠিক করা আছে কি না যাচাই করতে/usr/bin/ansibleথেকে কাজে লাগে Source 39সোর্স 39।changed_whenছাড়াshellবাcommandচালানো। যে task স্বাভাবিকভাবে ধরতে পারে না কোনো পরিবর্তন হয়েছে কি না, তাতে সবসময়changed_whenclause ব্যবহার করা উচিত Source 35সোর্স 35। সবচেয়ে প্রচলিত উদাহরণগুলোর মধ্যে আছেshellআরcommandmodule, যারা যেকোনো command চালায় Source 35সোর্স 35। ansible-lint-এরno-changed-whenrule যাচাই করে 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ছেপেছে, কারণ তারcopytask-এর বদলানোর কিছু ছিল না।- আশা করা handler সঙ্গে সঙ্গে চলবে, বা ব্যর্থতার পরেও চলবে। handler চলে
handlerssection-এর ক্রমে,notifyতালিকার ক্রমে নয় Source 13সোর্স 13। একই handler বহুবার notify করলে সেটা একবারই চলে Source 13সোর্স 13।meta: flush_handlerstask play-র সেই বিন্দুতে notify হয়ে থাকা handler চালু করে Source 13সোর্স 13।--force-handlersoption কোনো task ব্যর্থ হলেও handler চালায় Source 20সোর্স 20। ৩ নম্বর ধাপ দেখায়--list-taskshandler তালিকাভুক্ত করে না। - ব্যর্থতা লুকাতে
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.ymlproductionprofile পূরণ করেছে, আর ৩ ও ৫ নম্বর ধাপ দেখিয়েছে 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_HOMEsetting হলো controller-এ Ansible config file-এর default root path, আর এর default~/.ansibleSource 30সোর্স 30।remote_tmpsetting হলো target-এ task চালানোর সময় ব্যবহারের অস্থায়ী directory, আর এর default~/.ansible/tmpSource 9সোর্স 9। টিউটোরিয়ালের run-এ ধাপগুলোর পর খালি home folder-এ ছিল~/.cache/ansible-lint/latest.jsonfile। practice run-এর জন্য একটা খালিHOMEব্যবহার করুন। কোনো folder মোছার আগে ভেতরে দেখুন, কারণ docs বলে, shared~/.ansibleবাANSIBLE_HOMEdirectory-তে ইনস্টল করা 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-checkandansible-linton every pull request, and fail the build on a non-zero exit status. - Run a playbook twice on a clean machine, and expect
changed=0in the second run. - Run
--check --diffagainst 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_whenon everycommandandshelltask. - Keep vault passwords, vault password files, and decrypted output out of Git, bug reports, and chat messages.
- Use
diff: falseon 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-checkandansible-linton every pull request, and fail the build on a non-zero exit status. - Run a playbook twice on a clean machine, and expect
changed=0in the second run. - Run
--check --diffagainst 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_whenon everycommandandshelltask. - Keep vault passwords, vault password files, and decrypted output out of Git, bug reports, and chat messages.
- Use
diff: falseon 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আরshelltask-এ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
| Term | Meaning |
|---|---|
| Agent-less | Ansible is designed around an agent-less architecture |
| Desired state | You declare the desired state of a local or remote system in your playbook |
| Control node | A system on which Ansible is installed |
| Managed node | A remote system, or host, that Ansible controls |
| Inventory | A list of managed nodes that are logically organized |
| Playbook | Playbooks are automation blueprints, in YAML format, that Ansible uses to deploy and configure managed nodes |
| Play | An ordered list of tasks that maps to managed nodes in an inventory |
| Task | A reference to a single module that defines the operations that Ansible performs |
| Module | A unit of code or binary that Ansible runs on managed nodes |
| 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 |
| Idempotent | 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 |
| Variable | Ansible uses variables to manage differences between systems |
| Fact | Facts are things that are discovered about remote nodes |
| Template | Templates are processed by the Jinja2 templating language |
| Handler | Handlers are tasks that only run when notified |
| Block | Blocks create logical groups of tasks |
| Role | Roles let you automatically load related vars, files, tasks, handlers, and other Ansible artifacts based on a known file structure |
| Check mode | In check mode, Ansible runs without making any changes on remote systems |
| Diff mode | In diff mode, Ansible provides before-and-after comparisons |
| Ansible Vault | Ansible vault provides a way to encrypt and manage sensitive data such as passwords |
| Ansible Lint | Ansible Lint is a command-line tool for linting playbooks, roles and collections |
| Profile | Profiles gradually increase the strictness of the rules |
| Molecule | Molecule is an Ansible testing framework designed for developing and testing Ansible collections, playbooks, and roles |