Sobes.tech
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:

  1. 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.

  1. 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:
    - ...
  1. Use variables and conditions within the playbook: You can set a variable and use the when condition 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.

How can you configure an Ansible Playbook to only… - sobes.tech