Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Create and Run Your First Ansible Playbook

A practical first-playbook walkthrough covering control nodes, inventories, YAML plays and tasks, validation commands, safe check mode, output statuses, idempotency, and network-device differences.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To create and run a first Ansible playbook, make an inventory that names reachable managed hosts, write a YAML playbook with a target group and ordered tasks, check the file, then run ansible-playbook -i inventory.ini playbook.yaml from a control node. The smallest useful example checks connectivity with ansible.builtin.ping and prints a message with ansible.builtin.debug.

This guide takes you from an empty directory to a verified run, explains every line of the files, shows how to preview changes safely, and gives separate guidance for network devices.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How Ansible’s pieces fit together

Ansible runs from a control node against one or more managed nodes. The control node is the computer where Ansible is installed and where you run ansible and ansible-playbook. The managed nodes are the systems Ansible controls. An inventory describes those nodes and groups them for targeting.

Ansible’s own documentation describes playbooks as “automation blueprints, in YAML format, that Ansible uses to deploy and configure managed nodes.” A playbook is a list of plays. Each play maps an ordered list of tasks to a host group. Each task calls a module, which is the code or binary Ansible runs on a managed node.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Control node

Install Ansible on the control node and work from a shell in a directory you control. The control node must be able to reach the managed nodes and authenticate to them. Whether that means SSH keys, passwords, a bastion, network credentials, or another method depends on your environment; the first-playbook workflow does not prescribe one universal authentication setup.

Inventory

The inventory can be a static INI or YAML file, or it can come from a dynamic inventory source. For a first run, a static INI file is easiest. Groups in the inventory become the values you use in a play’s hosts field. Inventory entries can also carry connection data such as the SSH user and, for network automation, the network operating system.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Managed nodes

A managed node must be addressable from the control node and must accept the connection method configured in your inventory and Ansible settings. Use hostnames or addresses that are real in your environment; the documentation address in the example below is only a safe syntax example.

Build a small working directory

Create a directory containing the two files needed for the basic workflow: an inventory and a playbook.

  1. Create and enter a directory:

    mkdir ansible_quickstart
    cd ansible_quickstart
  2. Create inventory.ini with a group named myhosts:

    [myhosts]
    server1 ansible_host=192.0.2.10 ansible_user=ansible

    Replace 192.0.2.10 with the managed host’s real address and ansible with the account that can authenticate on that host. The group name is significant: the playbook will target myhosts.

  3. Create an empty file named playbook.yaml. You will add the play in the next section.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep the files together while learning. When they live elsewhere, pass their actual paths to the command instead of assuming the current directory.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

Write the first playbook

Put this content in playbook.yaml:

- name: My first play
  hosts: myhosts
  tasks:
    - name: Ping my hosts
      ansible.builtin.ping:

    - name: Print message
      ansible.builtin.debug:
        msg: Hello world

What the top-level list means

The first character is a hyphen because a playbook is a YAML list of plays. This file contains one play. Ansible processes plays from top to bottom, and it processes tasks inside each play from top to bottom.

Why the names matter

name values are labels for people. The play name and both task names appear in command output, so descriptive names let you identify the step that ran without opening the file again.

How host targeting works

hosts: myhosts selects the inventory group created earlier. If the group does not exist or has no matching hosts, the play cannot do useful work. You can target another inventory group by changing this value, but the spelling must match the inventory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What each module does

ansible.builtin.ping checks that Ansible can communicate with the managed node and that the node can answer the module request. It is not an ICMP network ping. ansible.builtin.debug writes the supplied message to the Ansible output; here it prints Hello world.

Why these names use a namespace

For Ansible 2.10 and later, the playbook guide recommends fully qualified collection names (FQCNs), such as ansible.builtin.ping. The namespace makes it clear which collection supplies a module when different collections contain similarly named modules. Older tutorials may show the short name ping; the fully qualified form is the safer modern style.

Check the files before changing anything

Run verification commands in this order. They catch different classes of mistakes and let you see what Ansible intends to target before a real run.

  1. Check YAML and playbook structure:

    ansible-playbook --syntax-check -i inventory.ini playbook.yaml

    A successful syntax check means Ansible can parse the playbook. It does not prove that a host is reachable or that a task will succeed.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    Rank #3
    Sale
    LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
    • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
    • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
    • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
    • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
    • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)
  2. List the hosts selected by the play:

    ansible-playbook --list-hosts -i inventory.ini playbook.yaml

    Confirm that the expected inventory members appear. This is especially useful when group names or inventory paths have changed.

  3. List the tasks Ansible will run:

    ansible-playbook --list-tasks -i inventory.ini playbook.yaml

    Use this to catch an unintended task, a misspelled playbook path, or a play that targets a different group than you expected.

  4. Preview changes with check mode and a diff:

    ansible-playbook --check --diff -i inventory.ini playbook.yaml

    Check mode executes the playbook without applying alterations and reports changes Ansible would have made. The --diff option asks modules that support it to show before-and-after content.

Check mode is a preview, not a guarantee. Modules vary in their check-mode support, and a real run can still depend on permissions, connectivity, variables, and external systems. A connectivity-only play such as the example above primarily validates access; a configuration play should be checked in a sandbox before production use.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run the playbook

Once the syntax, host list, and task list look right, run the exact command from the directory containing both files:

ansible-playbook -i inventory.ini playbook.yaml

The -i option tells Ansible which inventory to load, and the final argument is the playbook file. If your files have different names or are in different directories, substitute those paths.

During execution Ansible prints the play name, each task name, and a result for every targeted host. By default, a play also includes an implicit Gathering Facts task before the tasks you wrote. Fact gathering collects managed-node information; it is separate from the explicit ping task.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

Read the result and the final recap

A successful first run normally shows the ping task as ok and the debug task printing Hello world. At the end, Ansible prints a PLAY RECAP line for every targeted host.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Status Meaning What to inspect
ok The task completed and did not require a change. Confirm that the task output matches the intended host and values.
changed The task reported that it changed something. Review the task output and, for configuration tasks, the diff or resulting state.
unreachable Ansible could not communicate with the host. Check the address, route, firewall, connection plugin, credentials, and SSH or network-device access.
failed The host was reached, but task execution returned an error. Read the preceding error text, then check module arguments, permissions, variables, and the managed system.
skipped A task was not run because its conditions or selection rules excluded it. Inspect any conditions, tags, or host/group targeting that control the task.
rescued A task failure was handled by a rescue block. Read the failure and rescue output to verify that the recovery path produced the desired state.
ignored A failure was explicitly allowed to continue. Treat the ignored error as a problem to investigate, even though the play continued.

Use the first detailed error, not only the recap count, to choose a fix. An unreachable result is normally a communication or authentication issue; a failed result generally means Ansible reached the host but a task could not complete.

Make repeat runs predictable

Most Ansible modules check whether the desired final state has already been reached and avoid making another change. Modules with that behavior are called idempotent. This is why a declarative playbook can converge on a state: after the first successful application, later runs often report ok instead of changed.

Idempotency is not universal. Some modules or command-style tasks can perform an action every time, and check mode may not fully model their behavior. If you are uncertain, test the playbook in a sandbox, run it twice, and inspect whether the second run reports the stable state you expect. Do not interpret a clean second run as proof that every task in a larger playbook is safe to repeat.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Network-device playbooks use a different connection model

The generic example assumes ordinary managed nodes. Network automation commonly uses a network connection plugin instead of the default managed-node workflow. The official network tutorial shows a play with connection: ansible.netcommon.network_cli, gather_facts: false, a network facts module, and a debug task.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A network inventory group can carry the device operating system and login user, for example:

[switches]
switch1 ansible_host=192.0.2.20 ansible_user=netadmin ansible_network_os=vendor.platform

Replace the address, account, and ansible_network_os value with settings for the device and collection you actually use. The facts module name is platform-specific, so select it from the collection for that operating system rather than copying a generic Linux module. Setting gather_facts: false is intentional in this pattern: network devices do not use the same automatic fact-gathering path as ordinary hosts. The remainder of the workflow is unchanged: syntax-check the play, list hosts and tasks, preview where supported, and then apply it.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

Choose the right first-run workflow

Decision point Generic managed nodes Network devices
Typical target Linux or another host managed through the normal Ansible connection workflow. Switches, routers, or other devices using a network connection plugin.
Inventory details Host address and connection user are common starting values. Host address, connection user, and ansible_network_os identify the platform and access method.
Play connection Use the connection configured for the managed host. Use ansible.netcommon.network_cli when that plugin matches the device workflow.
Fact handling Fact gathering runs by default unless disabled. The documented network pattern sets gather_facts: false and calls a platform facts module explicitly.
Inventory source Static INI or YAML is simplest for a first test; dynamic inventory is an alternative at larger scale. Static or dynamic inventory can be used, provided it supplies the network connection variables your collection needs.
Safety sequence Syntax check, list hosts, list tasks, check mode and diff where supported, then apply. Use the same sequence, while allowing for module and device differences in check-mode support.

Troubleshoot the common first-playbook failures

The play reports no matching hosts

Compare the value after hosts: with the inventory group header character for character. Run --list-hosts with the same -i path you will use for the real run. If the list is empty, you are probably using the wrong inventory file, group name, or working directory.

The host is unreachable

Start with the address and route from the control node. Then verify that the account in ansible_user is valid, that the host accepts the selected connection method, and that credentials are available to Ansible. Firewalls, bastions, changed SSH host keys, and device-specific access controls can all prevent communication. The recap’s unreachable count tells you this is a connection-stage problem rather than a module result.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The play parses but a task fails

Read the task’s full error immediately above the recap. A failed result means Ansible reached the host but the module could not complete. Check the module name and namespace, required arguments, privilege or file permissions, variables, and the current state of the managed system. Do not replace a detailed error with a blind retry; fix the condition that produced it.

YAML syntax errors appear after editing

YAML depends on indentation. Keep task keys at the same indentation level, put module parameters beneath the module name, and run --syntax-check after each structural edit. A syntax check cannot validate whether an address, credential, or module argument is semantically correct, so continue with host and task listings.

Short module names behave differently from examples

Legacy material may use names such as ping. Modern playbooks should use FQCNs such as ansible.builtin.ping so Ansible selects the intended collection. If a module is not found, confirm the namespace, the installed collection, and the Ansible version rather than changing unrelated YAML.

A play changed more than expected

Stop applying it and inspect the check-mode output, diff, target host list, and task order. Check mode is advisory and cannot predict every external effect, so test risky changes in a sandbox. The module’s idempotency and check-mode support determine how trustworthy the preview is.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A previously valid playbook behaves differently after an upgrade

The current Ansible Core getting-started material warns that ansible-core 2.19 introduced significant templating changes that may require playbook updates. Record the installed release, consult version-specific documentation, and re-run syntax, host, task, and check-mode validation after an upgrade.

A repeatable checklist for future playbooks

  • Work from a control node with Ansible installed.
  • Create or select an inventory that contains the intended managed nodes and required connection variables.
  • Target an inventory group that actually appears in --list-hosts.
  • Write plays and tasks in the order they should execute, with descriptive names.
  • Use fully qualified module names, especially for modern Ansible 2.10-and-later playbooks.
  • Run --syntax-check, --list-hosts, and --list-tasks.
  • Preview configuration changes with --check --diff when the modules support those options.
  • Apply with ansible-playbook -i inventory.ini playbook.yaml.
  • Read each task result and the complete PLAY RECAP, not just the final exit status.
  • Test uncertain or non-idempotent behavior in a sandbox before production use.

Once this loop is familiar, adding more plays is mainly a matter of choosing the correct module and expressing the desired final state. Keep the inventory, target selection, validation commands, and recap review as deliberate parts of every run.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.