Creating loops in ansible
Ansible provides many ways to repeat the same task inside a play, but with a different value each time. For example, when you want to install multiple packages on a server, you don't need to create a task for each package. Rather, you can create a task that installs a package and provides a list of package names to the task, and Ansible will iterate over them until it finishes the installation. To accomplish this, we will need the with_items flag inside of the task that contains a list, and the variable {{ item }}, which serves as a placeholder for the items in the list. The playbook will leverage the with_items flag to iterate over a set of packages and provide them to the yum module, which requires the name and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access