Example 4
hosts.yml
centos:
hosts:
provisioner:
ansible_connection: local
centos1:
ansible_host: '192.168.77.22'
ubuntu:
hosts:
ubuntu1:
ansible_host: '192.168.77.23'
playbook.yml
- name: Example playbook
hosts: all
become: true
gather_facts: false
tasks:
- name: Example task
command: whoami
register: whoami_output
- debug:
msg: "Remote user: {{ whoami_output.stdout }}"
Tip
Privilage escalation in playbooks can be perfomed by adding the become: true
directive.
Execute the following command
ansible-playbook playbook.yml