ERROR! 'sudo' is not a valid attribute for a Play
- hosts: RemoteMachine1
name: play2
become: yes
tasks:
- name: "Find the disk space"
command: "df -h"
register: result
- name: "Install Apache in the remote machine"
apt: name=apache2 state=latest
- debug: var=result.stdout_lines
use become: yes it will run your tasks as the root user.
Become directives
Ansible play keyword sudo
was (long ago) deprecated with warnings in version 2.0 and removed in version 2.2
See the actual supported play keywords. Use:
become: true