Working with iterates in Ansible

You may have noticed that up to now we have never used cycles, so every time we had to do multiple, similar operations, we wrote the code multiple times. An example of this is the webserver.yaml code.

In fact, this was the content of the webserver.yaml file:

--- - hosts: webserver remote_user: ansible tasks: - name: Ensure the HTTPd package is installed yum: name: httpd state: present become: True - name: Ensure the HTTPd service is enabled and running service: name: httpd state: started enabled: True become: True - name: Ensure HTTP can pass the firewall firewalld: service: http state: enabled permanent: True immediate: True become: True - name: Ensure HTTPS can pass the firewall firewalld: service: https state: ...

Get Learning Ansible 2 - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.