What is the purpose of the 'become: yes' directive in the Ansible playbook?

QuestionsQuestions8 SkillsProAnsible Apt ModuleAug, 23 2025
0475

The become: yes directive in an Ansible playbook is used to enable privilege escalation. This allows the playbook to execute tasks with elevated privileges, typically as the root user or another specified user.

When become: yes is set, Ansible will use the configured method (like sudo) to run the tasks that require higher permissions. This is particularly useful for tasks that need to modify system files, install packages, or perform other administrative actions.

Here's an example of how it might be used in a playbook:

---
- name: Example Playbook
  hosts: all
  become: yes
  tasks:
    - name: Install a package
      apt:
        name: git
        state: present

In this example, the apt task will run with elevated privileges to install the git package on the target hosts.

0 Comments

no data
Be the first to share your comment!