Junior — Middle
How can you configure an Ansible Playbook to only make changes on selected servers?
sobes.tech AI
Answer from AI
To ensure that an Ansible Playbook makes changes only on selected servers, you can use the following approaches:
- Specify specific hosts or groups in the command line:
ansible-playbook playbook.yml -l server1,server2
The -l (limit) parameter restricts execution to the specified hosts.
- Define the required hosts in the inventory file: In the inventory file, you can group servers by categories, for example:
[webservers]
server1
server2
[dbservers]
server3
Specify the group in the playbook:
- hosts: webservers
tasks:
- ...
- Use variables and conditions within the playbook:
You can set a variable and use the
whencondition to execute tasks only on the desired hosts.
Thus, the selection of servers for playbook execution can be controlled through the inventory, launch parameters, and conditions within the playbook.