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 privilege escalation is enabled with become: true. Use become_user to choose the account that executes the task, and become_method to choose the escalation mechanism. The default method is sudo and the default target account is root. Because become_user only changes the requested identity and does not activate escalation, a task that sets it without become: true will not switch users.

What Ansible become does

Ansible connects to a managed host as the remote user, transfers a module, and executes that module. Become inserts a privilege-escalation step between the connection and module execution so the module runs as another account. The Ansible Core Documentation describes the name this way: “Because this feature allows you to ‘become’ another user, different from the user that logged into the machine (remote user), we call it ‘become’.”

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

The three controls have separate jobs:

  • become activates escalation.
  • become_user identifies the account that should run the task. If omitted, the target is normally root.
  • become_method selects the plugin or operating-system mechanism, such as sudo, su, doas, runas, or a network device’s enable mode.

These settings can be supplied at play or task scope, through inventory connection variables, or on the command line. Ansible precedence rules determine which value wins when more than one location sets the same option.

Run one task as root

Task-level escalation is the safest default when only one operation needs extra rights. The following play connects normally and elevates only the service task:

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application:Upgraded attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Warranty & Support: Our Electric air duster comes with 5 years warranty and 24/7 customer service. During this period, if you have any questions,pls kindly feel free to contact us.
---
- hosts: web
  tasks:
    - name: Ensure the web service is running
      ansible.builtin.service:
        name: httpd
        state: started
      become: true

All other tasks in this play continue under the connection account. This limits the number of modules that can modify protected files or system state if a play contains an error.

Run a command as a named service account

Set both activation and identity when the operation must run as a non-root account:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
- name: Run as apache
  ansible.builtin.command: somecommand
  become: true
  become_user: apache

The target account must exist on the managed host, and the selected escalation method must permit the connection user to become it. A service account may have deliberately limited permissions; becoming it is not equivalent to becoming root.

Choose the right scope

Use the narrowest scope that satisfies the operational requirement. Scope affects both security and how easily a reader can tell which tasks are privileged.

Scope Typical use Important behavior
Task One package, file, service, or command needs elevation Only that task runs through become; this is the preferred least-privilege pattern
Play Every task in a play needs the same elevated identity All tasks inherit the play’s become settings unless a more specific value overrides them
Inventory A host or group follows a consistent escalation policy Connection variables provide host or group defaults; protect any password variable with Vault
Command line A run-time choice applies to an ad hoc command or an entire invocation CLI options can supply or override values for that run, subject to precedence

Play-level escalation

- hosts: database
  become: true
  become_user: root
  tasks:
    - name: Install database packages
      ansible.builtin.package:
        name: postgresql
        state: present
    - name: Enable the database service
      ansible.builtin.service:
        name: postgresql
        enabled: true
        state: started

Use this form when every task genuinely requires the same identity. If only package installation and service management need root while configuration templating can run unprivileged, split the work or move become down to those tasks.

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth

Command-line forms and password prompts

The short and long command-line options are:

Purpose Options
Enable become -b or --become
Select target user --become-user
Select method --become-method
Prompt for escalation password -K or --ask-become-pass

For example, an ad hoc command that runs as apache with a password prompt is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ansible web -m ansible.builtin.command -a 'somecommand' 
  --become --become-user apache --ask-become-pass

-K only asks for the password; it does not enable become by itself. A run that appears frozen after connecting may actually be waiting for this prompt, especially when output is not attached to an interactive terminal.

Inventory variables and secret handling

The principal inventory connection variables are:

  • ansible_become
  • ansible_become_method
  • ansible_become_user
  • ansible_become_password
  • ansible_become_exe

A group-level example can establish a common policy:

[web:vars]
ansible_become=true
ansible_become_method=sudo
ansible_become_user=root

Do not store ansible_become_password in plain text. Put it in an Ansible Vault-encrypted variable or supply it through a centrally managed credential mechanism. Keep the password out of playbook source, ordinary inventory, shell history, and logs.

If hosts in the same group require different methods or target accounts, use host-specific variables rather than forcing one group default. Verify the effective values before a production run with a controlled test host.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

Become methods and connection compatibility

Current Ansible Core documentation lists these become plugins: sudo, su, pbrun, pfexec, doas, dzdo, ksu, runas, and machinectl. Become plugins are enabled by default and can be listed with:

ansible-doc -t become -l

The method is not interchangeable with the connection plugin. Become support depends on how Ansible reaches the host, and only one escalation method may be enabled for a host at a time. Ansible cannot chain methods, such as using sudo and then su as one combined escalation sequence.

Scenario Settings to use Constraint
Unix host with standard sudo policy become: true; default sudo method; target usually root The connection user must be allowed to run the required sudo operation
Unix host using another supported mechanism Set become_method to the host’s configured plugin The selected connection plugin and host policy must support that method
Network device privileged EXEC mode become: true with become_method: enable Use a supporting network_cli or httpapi connection
Windows host Use become_method: runas with the same inventory and CLI naming pattern The connection account must already be an Administrator; an underprivileged account cannot be elevated

Why a task hangs for a sudo password

A hang usually means the escalation program is waiting for credentials or for a host-side condition that Ansible cannot satisfy. Work through these checks in order:

  1. Confirm that the task actually has become: true, or that the play or command line enables it.
  2. If you expect an interactive prompt, run with -K or --ask-become-pass. Remember that -K does not turn become on.
  3. Check whether the sudo policy permits the connection user to become the requested become_user.
  4. Check that the selected become_method matches the host and connection plugin. A method unsupported by the connection cannot complete.
  5. Verify that the target user exists and that its shell, account status, and host-side policy permit non-interactive execution.
  6. Run a minimal test, such as a command that prints the effective identity, before retrying a large play.

For unattended automation, provide the credential through a protected Vault variable, a password file, or centralized credential management rather than relying on a prompt that no scheduler can answer.

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

Security when switching between two unprivileged users

Privilege escalation is not limited to root. You can connect as one unprivileged account and become another, but Ansible must still transfer a module to the managed host before executing it. The second account needs read access to that temporary module file and, depending on the module, to its arguments.

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.

Ansible attempts safer mechanisms first. It may use POSIX access-control lists and then a configured common group through ansible_common_remote_group. In some configurations it can fall back to a world-readable temporary directory. That fallback matters because module files can contain parameters, including secrets.

  • Prefer a shared, restricted group and correct filesystem permissions when two unprivileged accounts must cooperate.
  • Inspect temporary-directory permissions on the managed host and avoid exposing module files to unrelated users.
  • Do not treat a successful task as proof that its parameters were private; file readability is a separate security property.

Since Ansible 2.1, the default behavior is to error when it cannot execute this unprivileged-to-unprivileged transfer securely. Setting world_readable_temp changes that failure into a warning and permits the task. Enable it only as an explicit risk decision on a trusted managed node, after accepting that other local users may read module contents.

Windows runas has different prerequisites

On Windows, runas follows the same inventory and command-line naming pattern, but it cannot turn an underprivileged connection into an administrator. The connection account must already be an Administrator. Results also depend on token privileges, the Secondary Logon service, and configured logon rights.

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

When a Windows escalation fails, check those host prerequisites before changing YAML. A correct become: true declaration cannot compensate for a connection account that lacks the required administrator status or a disabled service.

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

Network enable mode

Network automation commonly uses a privileged EXEC or enable context rather than a Unix root account. For platforms that support it, configure:

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.
- hosts: switches
  connection: ansible.netcommon.network_cli
  become: true
  become_method: enable
  tasks:
    - name: Collect privileged state
      ansible.netcommon.cli_command:
        command: show running-config

The exact network collection and command module depend on the platform, but the escalation pattern is the same: the connection must support the method, and the device must authorize the enable transition.

Restricted sudo rules and enterprise access

Some environments restrict sudo, pbrun, or doas to specific command paths. If Ansible’s generated module command does not match those rules, a task can fail even though an administrator can run a similar command manually.

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

Documentation recommends either a special account without that command-path constraint or a centralized access design such as AWX or Red Hat Ansible Automation Platform to manage indirect access to SSH credentials. Whichever model you choose, document which account is allowed to escalate, which methods are permitted, and how each execution is audited.

Linting and verifying playbook intent

Ansible Lint’s partial-become rule checks that escalation is activated when a task changes users. The rule does not evaluate inherited play-level or command-line values, so a warning may require you to make the task’s intent clearer even when a higher-level setting supplies become at runtime.

Before merging a playbook, review each user change and ask:

  • Is become: true present at the narrowest practical scope?
  • Is become_user necessary, and does that account have exactly the required permissions?
  • Is the method compatible with the connection plugin and host operating system?
  • Are credentials protected with Vault or an approved centralized secret store?
  • Could an unprivileged-to-unprivileged task expose module arguments through temporary-file permissions?

A practical troubleshooting checklist

  1. Start with a single harmless task that reports the effective user.
  2. Set become: true explicitly and add become_user only when the target is not the default.
  3. Choose one supported become_method; do not attempt to chain methods.
  4. Test the exact connection plugin used by the real play.
  5. For password-protected escalation, use -K interactively or a Vault-protected credential non-interactively.
  6. If both users are unprivileged, verify POSIX ACL, common-group, and temporary-directory behavior before permitting the play.
  7. Reduce the scope back to task level after diagnosing a play-level failure.

Design principles for safer playbooks

  • Separate activation from identity. Treat become as the switch and become_user as the identity selector.
  • Use least privilege. Elevate only the tasks that require it and select a service account instead of root when that account is sufficient.
  • Make secrets unambiguous. Protect escalation passwords with Vault and keep prompts out of unattended jobs.
  • Match the method to the platform. Unix, network, and Windows hosts have different connection and policy requirements.
  • Assume module files can matter. Review temporary-file permissions whenever two unprivileged users are involved.
  • Test the effective identity. A successful SSH connection does not prove that the requested escalation is authorized.

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.

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.