Wie kommen Ansible Templates zur Anwendung und wieso ist der Ansible Loop so wichtig?
How are Ansible templates used and why is the Ansible Loop so important?
Playbooks use a simple descriptive language based on YAML and Jinja templates. Templates can be inherited with Jinja2. Generally valid elements can be defined in a base template. Parts of child templates can be overwritten in so-called "blocks". A specific Ansible template is used for the website. The variables included there in Jinja syntax are then filled in by Ansible when the file is copied to the desired location using the template module. Template files are given the file extension .j2. The Ansible template file and the stylesheet are then used to create an exact folder structure. The following task is similar to restarting the firewall service: If the index file or the stylesheet changes during deployment, nginx can be restarted or the delivered files can be changed during operation. The last task should now set a message as "Message-of-the-day", which is displayed when the server logs in via SSH. Again, the Ansible template module is used to copy the desired file to etc/motd. A motd.j2 template file is therefore added. The ansible_* variables come from the host facts in the same way as the website template. However, this does not apply to webserver_name, as this variable should be different for each server and must therefore be defined accordingly.
Each Ansible module can be written independently and in any programming language. The modules should be idempotent in the sense of an "Ansible loop". This means that even if a process is repeated several times - e.g. when recovering from a failure - the system is always restored to the same state.