Interview Prep/Real-World Interview/Write-an-Ansible-playbook tasks

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.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-an-Ansible-playbook tasks