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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Ansible manages Linux servers from a control node by reading an inventory, connecting over SSH, and applying modules that describe the desired state. Use ansible for a rare one-off command; use ansible-playbook for repeatable, reviewable automation. The shortest useful workflow is: define hosts, verify SSH, test with ping, make a narrowly scoped change, validate it in check mode, and then run the playbook.

What Ansible does on Linux servers

Ansible separates the machine that runs automation (the control node) from the Linux hosts being managed. The control node reads an inventory, selects hosts with a pattern such as web or all, connects using SSH by default, and sends tasks to those hosts. You normally do not install an Ansible agent on each managed server.

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

An inventory is the map of your environment. A playbook is a YAML automation blueprint that turns that map into repeatable work. Modules perform the work: package modules install software, service modules control daemons, file modules manage paths and permissions, template modules render configuration, and user modules manage accounts. State-aware modules generally report ok without changing a host that already matches the requested state.

  • Control node: the workstation, jump host, CI runner, or automation server where Ansible is installed.
  • Managed nodes: Linux servers reachable through approved credentials and SSH policy.
  • Inventory: groups, host names or addresses, connection variables, and optional host-specific data.
  • Modules: the units that express an intended state or perform an operation.
  • Playbooks: ordered YAML tasks that can be reviewed, versioned, tested, and reused.

Install and verify the control node

Install Ansible using the distribution method appropriate for your control-node operating system. The exact package name and command vary by operating system and by the Ansible version or collection content you intend to use, so check the documentation for the version you will run rather than copying an unqualified command.

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter | 4Pack Type C Female to A Male Cable Converter for Apple Duo 17 16 15 14 Plus,iWatch Watch 12 11 10,iPad 9 8 Air,Airpods 5 4
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

After installation, confirm the executable and its core version:

ansible --version

Record the reported ansible-core version for production work. Module parameters and collection content evolve, and official documentation maintains separate pages for supported releases. Pin the versions used by a project so that a later upgrade cannot silently change a module assumption.

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

Build an inventory that matches your servers

Create a plain-text inventory file named inventory (INI syntax is convenient for a first deployment). Groups let you target roles instead of typing individual addresses:

[web]
web01.example.internal
web02.example.internal

[db]
db01.example.internal

[all:vars]
ansible_user=deploy

You can use DNS names or IP addresses. If a host uses a different SSH name, port, key, or user, define those variables for the host or group. Keep connection details consistent with your organization’s SSH policy; do not place passwords or private keys in a repository.

Inspect the inventory before running a task. The graph view reveals spelling mistakes, missing groups, and unexpected nesting:

ansible-inventory -i inventory --graph

Common host patterns include:

  • all — every host in the inventory.
  • web — only members of the web group.
  • web:db — the union of the two groups.
  • web:&staging — hosts in both groups.
  • web:!retired — web hosts excluding the retired group.

Use patterns deliberately. A typo can select no hosts, while an overly broad pattern can change an entire fleet.

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

Test SSH connectivity before debugging automation

Ansible’s official ad hoc workflow assumes that the target hosts are in an inventory group and that SSH credentials work. Verify DNS or IP reachability, the intended remote user, key permissions, firewall rules, and host-key policy before examining YAML.

Rank #2
Sale
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter | USB C Dongle with 90W Max Power Delivery, 3×5Gbps USB A Data Ports, for MacBook, Dell, and More (Charger Not Included)
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
ansible all -i inventory -m ansible.builtin.ping

A successful result returns pong for each reachable host. UNREACHABLE means Ansible could not establish its connection; it is not a task failure inside your playbook. Test the same identity outside Ansible when needed:

ssh deploy@web01.example.internal

For an unreachable host, check these in order:

  1. Resolve the name or verify the IP address from the control node.
  2. Confirm routing, security groups, firewalls, and the SSH port.
  3. Confirm the inventory’s ansible_user and the key or approved credential.
  4. Check the server’s SSH daemon and host-key acceptance policy.
  5. Only after SSH works, investigate become permissions or playbook logic.

Choose between ansible and ansible-playbook

Tool Best use Strength Limitation
ansible A rare one-off operation or quick diagnostic Immediate feedback with very little scaffolding The command is not a reusable record of the whole procedure
ansible-playbook Work that must be repeated, reviewed, shared, tested, or applied consistently YAML tasks support ordering, variables, handlers, conditionals, loops, roles, tags, and check mode Requires a maintained playbook and its supporting files

An ad hoc command has the canonical form:

ansible [pattern] -m [module] -a "[module options]"

Use it for a task you genuinely expect to perform rarely, such as checking a fact, copying a temporary file, or rebooting a controlled group. Once the procedure becomes routine or has multiple steps, capture it in a playbook so another operator can inspect exactly what will happen.

High-value ad hoc commands for Linux

Install or remove a package

ansible web -i inventory -m ansible.builtin.package -a "name=nginx state=present" --become

ansible.builtin.package delegates to the platform’s package manager. Use state=present to ensure installation, state=absent for removal, and the parameters documented for the installed Ansible version when you need upgrades, repositories, or package-specific behavior.

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

Manage a service

ansible web -i inventory -m ansible.builtin.service -a "name=nginx state=started enabled=true" --become

The generic service module covers starting, stopping, restarting, and enabling services. A platform-specific service module may expose additional parameters; consult its module page before relying on them.

Copy a known file

ansible web -i inventory -m ansible.builtin.copy -a "src=./nginx.conf dest=/etc/nginx/nginx.conf owner=root group=root mode=0644" --become

copy is appropriate when the source file is already complete. It can set ownership and mode and reports no change when the destination already matches.

Create a directory or change file state

ansible web -i inventory -m ansible.builtin.file -a "path=/srv/app state=directory owner=app group=app mode=0750" --become

The file module also manages links, removes paths, and changes permissions. Express the desired state rather than issuing a sequence of shell commands.

Create or manage a user

ansible all -i inventory -m ansible.builtin.user -a "name=app state=present create_home=true" --become

The user module manages accounts and group membership. Keep password hashes and private authentication material out of command history and source control.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Reboot a controlled group

ansible web -i inventory -m ansible.builtin.reboot --become

Reboots are disruptive. Target a deliberate group, confirm maintenance timing, and verify that the module’s wait and timeout behavior matches your operating system and Ansible version.

Use the right module instead of a shell workaround

Need Preferred module Why
Install, update, or remove software ansible.builtin.package Expresses package state and uses the host’s package manager
Start, stop, restart, or enable a daemon ansible.builtin.service or a platform-specific service module Expresses service state and avoids ad hoc process commands
Place an existing file ansible.builtin.copy Controls content, owner, group, and mode
Render configuration from variables ansible.builtin.template Produces a file from a Jinja2 template and data
Create directories, links, or permissions ansible.builtin.file Manages filesystem state idempotently
Create accounts and groups ansible.builtin.user Manages account state instead of editing system files directly
No suitable module exists ansible.builtin.command, then ansible.builtin.shell only when needed Provides an escape hatch, but requires extra care to make repeats safe

command does not invoke a shell. shell does, which enables pipes, redirects, and expansion but increases quoting and injection risk. Neither should be the default for a package, service, file, or user operation. If a command must run, add a condition, a check, or another idempotence mechanism so it does not report a change on every execution.

Write a repeatable playbook

A playbook is a YAML file containing plays. Each play maps hosts to ordered tasks. This example installs a web server, deploys a template, and restarts the service only when its configuration changes:

---
- name: Configure web servers
  hosts: web
  become: true
  vars:
    web_package: nginx
    web_service: nginx
  tasks:
    - name: Install the web package
      ansible.builtin.package:
        name: "{{ web_package }}"
        state: present

    - name: Ensure the document root exists
      ansible.builtin.file:
        path: /srv/www
        state: directory
        owner: root
        group: root
        mode: '0755'

    - name: Render web-server configuration
      ansible.builtin.template:
        src: templates/nginx.conf.j2
        dest: /etc/nginx/nginx.conf
        owner: root
        group: root
        mode: '0644'
      notify: Restart web service

    - name: Ensure the service is enabled and running
      ansible.builtin.service:
        name: "{{ web_service }}"
        state: started
        enabled: true

  handlers:
    - name: Restart web service
      ansible.builtin.service:
        name: "{{ web_service }}"
        state: restarted

The handler runs later in the play when the template task reports a change. This prevents an unnecessary restart when the rendered configuration is already current. Test handler behavior in a disposable environment before using it on production services.

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

Validate, preview, and execute

  1. Check YAML and task syntax without contacting hosts:
    ansible-playbook -i inventory site.yml --syntax-check
  2. Preview supported changes and show file differences:
    ansible-playbook -i inventory site.yml --check --diff
  3. Limit the first real run to one host or a narrow group:
    ansible-playbook -i inventory site.yml --limit web01.example.internal
  4. Run against the intended inventory after reviewing the output:
    ansible-playbook -i inventory site.yml

Check mode is a forecast, not a guarantee: modules differ in how completely they support it, and commands with side effects may not be safely predictable. Treat --diff output as sensitive because configuration files can contain credentials or tokens.

Privilege escalation with become

Tasks that write under /etc, install packages, manage system services, or create system users normally need elevated privileges. Set escalation at play or task scope:

- name: Install a system package
  hosts: web
  become: true
  tasks:
    - name: Install nginx
      ansible.builtin.package:
        name: nginx
        state: present

Use become_user when the intended target is not the default elevated account:

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray | Data transfer & Fast charging for MacBook, iPhone 17/16/15, iPad, Samsung Galaxy, Apple Watch
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
- name: Run an application command as app
  ansible.builtin.command: /usr/local/bin/app-maintenance
  become: true
  become_user: app

At the command line, the equivalent switch is --become. Escalation still depends on the remote user being allowed to elevate, any required prompt being available, and the operating system’s policy. Grant the minimum rights needed and avoid embedding a privilege password in a playbook or inventory.

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.

Protect secrets with Ansible Vault

Passwords, private keys, API tokens, and vault passwords should not appear in inventories, ordinary variable files, command history, or Git history. Ansible Vault encrypts sensitive YAML data and is integrated with playbook execution. Create or edit encrypted content with the Vault commands supported by your installed version, then supply the vault-password mechanism required by your operational policy at runtime.

Keep the encrypted file separate from public defaults, limit its filesystem permissions, and ensure that logs do not print secret variables. Avoid using --diff for files that may contain credentials, and mark sensitive task variables with the appropriate no-log behavior where supported. A vault password stored beside the encrypted data defeats the purpose of encryption; use an approved password manager, protected CI secret, or interactive prompt.

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

Features that make larger playbooks maintainable

Variables and templates

Put environment-specific values in variables and render them with ansible.builtin.template. This keeps one task structure usable across staging and production while allowing different addresses, ports, or feature flags.

Loops and conditionals

Use loops to apply one task to a list of packages, directories, or users. Use when conditions for operating-system facts, environment flags, or optional components. Prefer clear data structures over repeated nearly identical tasks.

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

Tags and focused execution

Assign tags to related tasks so an operator can run a documented subset. Tags do not remove dependencies: a database schema task may still be required before an application task. Review the full play before using a narrow tag selection.

Roles, collections, and includes

Roles organize defaults, variables, tasks, handlers, templates, and files into reusable units. Collections package modules, plugins, and roles under a fully qualified collection name. Includes and imports split a large playbook into logical files; choose the form documented for your installed version because loading and evaluation timing differ.

Best Value
Sale
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Delegation and asynchronous work

Delegation lets a task run on a designated host, such as a load balancer or orchestration node, while a play targets another group. Asynchronous execution can start long-running operations without holding the SSH session open, but you must poll for completion and handle failures explicitly.

Read Ansible output and troubleshoot safely

Task output normally distinguishes ok, changed, skipped, failed, and unreachable. These states answer different questions:

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.
  • ok: the requested state already matched or the task completed without a reported change.
  • changed: Ansible modified the target or a command was considered to have made a change.
  • skipped: a condition, tag selection, or platform check excluded the task.
  • failed: the module ran but returned an error; read its message and the task arguments.
  • unreachable: Ansible could not establish the connection, so task logic did not run.
Symptom Likely checks Safer response
Every run reports changed A shell command, unstable generated content, or missing state check Replace it with a state-aware module or add a precise condition and change detection
Host is UNREACHABLE DNS, route, firewall, SSH user, key, port, or host-key policy Test SSH independently before editing the playbook
Privilege task fails Remote user’s elevation rights, become_user, or prompt policy Verify approved escalation outside the task and request only needed rights
Service restarts unexpectedly Template changes, handler placement, or broad tags Review the diff, isolate the handler, and test on a disposable host
Only some hosts change Group membership, host variables, conditionals, or platform differences Inspect inventory graph and task facts for each affected host

Use --limit to contain a change, --start-at-task only when you understand prerequisite tasks, and tags only when dependencies are documented. A task skipped by a tag may leave a service or file unprepared for a later task.

Version and collection discipline

Ansible documentation is versioned, and content evolves by release. Ansible publishes a new major release approximately twice a year, while collections can follow their own release cadence. Record the ansible-core and collection versions that a playbook expects, use fully qualified collection names where required, and verify every module parameter against the documentation for the installed version.

Do not assume that a command copied from an older article has the same defaults today. Test upgrades in a representative environment, review changelogs, and keep a lock or requirements file for collections used by production automation.

When an enterprise platform is appropriate

Red Hat’s Ansible Automation Platform is an enterprise option built around the same fundamental objects: inventories, playbooks, modules, and collections. It adds supported platform capabilities around running and governing that content. The underlying design still matters: clean inventories, idempotent modules, controlled credentials, versioned playbooks, and a tested promotion path.

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

A safe first-day workflow

  1. Install Ansible on a controlled Linux, workstation, or CI control node.
  2. Create a minimal inventory with one non-production host and an approved SSH user.
  3. Run ansible-inventory -i inventory --graph and correct group errors.
  4. Run ansible all -i inventory -m ansible.builtin.ping and resolve connectivity failures.
  5. Try one read-only or low-risk ad hoc task to confirm module execution.
  6. Move any repeatable change into a YAML playbook with fully qualified module names.
  7. Run --syntax-check, then --check --diff where the modules support meaningful previews.
  8. Use --limit for a canary host, inspect ok, changed, and failure output, then expand deliberately.
  9. Add handlers, variables, roles, tags, and collection requirements as the procedure grows.
  10. Encrypt secrets with Vault and store the playbook and version metadata in source control.

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.