## PRIVILEGE ESCALATION

Ansible Terminal

    - name: Ensure apache is installed and started
      hosts: web
      become: yes

      tasks:
      - name: Ensure httpd package is present
        yum:
          name: httpd
          state: latest

      - name: Ensure latest index.html file is present
        copy:
          src: files/index.html
          dest: /var/www/html/

      - name: Ensure httpd is started
        service:
          name: httpd
          state: started

Ansible allows you to "become" another user or with elevated rights to execute a task or an entire play (shown above). This is done using existing privilege escalation tools, which you probably already use or have configured, like sudo (the default), su, pfexec, doas, pbrun, dzdo, ksu and others.

For more details see the Privilege Escalation page in the Ansible documentation.