Book Image

Learning Ansible

By : Madhurranjan Mohaan, Ramesh Raithatha
Book Image

Learning Ansible

By: Madhurranjan Mohaan, Ramesh Raithatha

Overview of this book

<p>Automation includes provisioning new servers, making sure the servers adhere to their role and maintain the desired state from a configuration perspective, and orchestrating various actions across environments and deploying code as expected to all these servers. This is where Ansible steps in. It is secure, highly reliable, and minimalistic in nature. It automates configuration management, application deployment, and many other IT needs.</p> <p>Learning Ansible will equip you with the necessary skills to automate/improve your infrastructure from a configuration management perspective. You will also be able to use Ansible for one-click deployments, provisioning, and orchestrating your infrastructure.</p>
Table of Contents (16 chapters)
Learning Ansible
Credits
About the Authors
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Working with loops


Have you ever wondered how life would be if you had to install several packages on your remote systems manually? We saw how Ansible helped us in such a situation by automating the package installation. However, it would be still a nightmare if you have to write the same task multiple times with different package names. To overcome such situations and to make your life easier, Ansible provides you with loops.

Standard loops

Using standard loops, you can pass a list of packages to install and Ansible will run that task for all packages listed. Confused? Let's now go through an example playbook.

In the preceding playbook, Ansible will run the Installing packages task multiple times (in this case, three times): once for each of the packages that are defined under the with_items construct. Each of the packages is exposed as item, which is a default variable that Ansible creates. Ansible then assigns a package name to item, based on the iteration it is currently part of. So, for...