Write an ad-hoc command set for quick live tasks: ping, run a command, copy a file, restart a service.
BeginnerHands-onWrite-an-Ansible-playbook tasks
Answer
ansible all -i inventory.yml -m ansible.builtin.ping
ansible web -i inventory.yml -a "uptime"
ansible web -i inventory.yml -b -m ansible.builtin.copy -a "src=motd dest=/etc/motd mode=0644"
ansible web -i inventory.yml -b -m ansible.builtin.service -a "name=nginx state=restarted" --forks 5
Key trick → -b means become (sudo), and --forks controls parallelism (default 5). The ping module tests SSH and Python on the host, not ICMP.
More on Write-an-Ansible-playbook tasks
Write a playbook that installs and starts Nginx on Ubuntu web servers.BeginnerWrite an inventory with groups, a group of groups, and per-group variables.BeginnerWrite a playbook that deploys a config file from a Jinja2 template and restarts the service only if it changed.BeginnerWrite a role structure for a Node.js app and show what goes in each folder.IntermediateWrite a task that creates multiple users with SSH keys from a list.BeginnerWrite a rolling deploy playbook: 2 servers at a time, removed from the load balancer during the update.Advanced