Bearbeiten von „KIF490:Einführung in Ansible (einfach wartbare, reproduzierbare Systemkonfigurationen)

Aus KIF
Warnung: Du bist nicht angemeldet. Deine IP-Adresse wird bei Bearbeitungen öffentlich sichtbar. Melde dich an oder erstelle ein Benutzerkonto, damit Bearbeitungen deinem Benutzernamen zugeordnet werden. Ein eigenes Benutzerkonto hat eine ganze Reihe von Vorteilen.

Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und veröffentliche dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.

Aktuelle Version Dein Text
Zeile 162: Zeile 162:


The [https://docs.ansible.com/ansible/latest/collections/ansible/builtin/stat_module.html <code>stat</code> module] never changes anything. It just retrieves status information about a file. But by registering the result of the task to a variable, we can use it for other parts of our playbook.
The [https://docs.ansible.com/ansible/latest/collections/ansible/builtin/stat_module.html <code>stat</code> module] never changes anything. It just retrieves status information about a file. But by registering the result of the task to a variable, we can use it for other parts of our playbook.
<div style="padding: 15px; margin-bottom: 20px; border: 1px solid transparent; border-radius: 4px; color: #31708f; background-color: #d9edf7; border-color #bce8f1;">
<div class="info" style="padding: 15px; margin-bottom: 20px; border: 1px solid transparent; border-radius: 4px; color: #31708f; background-color: #d9edf7; border-color #bce8f1;">
Be careful though, '''if you find yourself programming in a playbook, you're doing something wrong.''' Mostly you're either over-engineering/procrastinating on other problems or you really need a module that does that complicated stuff instead.
Be careful though, '''if you find yourself programming in a playbook, you're doing something wrong.''' Mostly you're either over-engineering/procrastinating on other problems or you really need a module that does that complicated stuff instead.
</div><hr>
</div><hr>
Zeile 192: Zeile 192:
There's not always a module for everything. Sometimes the usecase is too obscure, sometimes there is no meaningful way to ensure Ansible principles like idempotence.<ref>not changing stuff if the desired state is already met</ref><br>
There's not always a module for everything. Sometimes the usecase is too obscure, sometimes there is no meaningful way to ensure Ansible principles like idempotence.<ref>not changing stuff if the desired state is already met</ref><br>
The above example is trying to build minetest for maximum control over the installed version. After resetting the git repository to the desired version, the binary is built. For this, we use the [https://docs.ansible.com/ansible/latest/collections/ansible/builtin/command_module.html <code>command</code> module] – but it has no idea whether the desired state is already met or whether the command has to be run again. We manually tell it to skip this task if the repository did not change in the previous task.
The above example is trying to build minetest for maximum control over the installed version. After resetting the git repository to the desired version, the binary is built. For this, we use the [https://docs.ansible.com/ansible/latest/collections/ansible/builtin/command_module.html <code>command</code> module] – but it has no idea whether the desired state is already met or whether the command has to be run again. We manually tell it to skip this task if the repository did not change in the previous task.
<div style="padding: 15px; margin-bottom: 20px; border: 1px solid transparent; border-radius: 4px; color: #31708f; background-color: #d9edf7; border-color #bce8f1;">
<div class="info" style="padding: 15px; margin-bottom: 20px; border: 1px solid transparent; border-radius: 4px; color: #31708f; background-color: #d9edf7; border-color #bce8f1;">
There is a minor gotcha with this: Assume you abort the playbook while its running the build task because you forgot to do something else. If you run it again, the git update will be skipped, as it is already in its desired state. But now the build task will not be run again. If you have this in your playbooks, you need to be aware of this edge case.<br>
There is a minor gotcha with this: Assume you abort the playbook while its running the build task because you forgot to do something else. If you run it again, the git update will be skipped, as it is already in its desired state. But now the build task will not be run again. If you have this in your playbooks, you need to be aware of this edge case.<br>
This is another reason why logical links in playbooks should be kept to a minimum.
This is another reason why logical links in playbooks should be kept to a minimum.
</div><div style="padding: 15px; margin-bottom: 20px; border: 1px solid transparent; border-radius: 4px; color: #8a6d3b; background-color: #fcf8e3; border-color: #faebcc;">
</div><div class="warning" style="padding: 15px; margin-bottom: 20px; border: 1px solid transparent; border-radius: 4px; color: #8a6d3b; background-color: #fcf8e3; border-color: #faebcc;">
There is also the <code>shell</code> module that feels very similar. But in contrast to <code>command</code>, it runs the specified command in a shell. This opens up the use of shell features like piping, but comes at an increased security risk, especially if building the command from variables.<br>
There is also the <code>shell</code> module that feels very similar. But in contrast to <code>command</code>, it runs the specified command in a shell. This opens up the use of shell features like piping, but comes at an increased security risk, especially if building the command from variables.<br>
Using <code>shell</code> is ''not'' recommended.
Using <code>shell</code> is ''not'' recommended.
Zeile 213: Zeile 213:


It is common practice to store important variables alongside playbooks and roles in even public repositories by encryping them with [https://docs.ansible.com/ansible/latest/cli/ansible-vault.html Ansible Vault].
It is common practice to store important variables alongside playbooks and roles in even public repositories by encryping them with [https://docs.ansible.com/ansible/latest/cli/ansible-vault.html Ansible Vault].
<div style="padding: 15px; margin-bottom: 20px; border: 1px solid transparent; border-radius: 4px; color: #8a6d3b; background-color: #fcf8e3; border-color: #faebcc;">
<div class="warning" style="padding: 15px; margin-bottom: 20px; border: 1px solid transparent; border-radius: 4px; color: #8a6d3b; background-color: #fcf8e3; border-color: #faebcc;">
These are production secrets, but never management access to the target machines. Jump hosts are one popular solution to grant access to many machines to various actors: Only this host stores the admins pubkeys, while the target machines only have the key from jump host.
These are production secrets, but never management access to the target machines. Jump hosts are one popular solution to grant access to many machines to various actors: Only this host stores the admins pubkeys, while the target machines only have the key from jump host.
</div>
</div>
Bitte kopiere keine Webseiten, die nicht deine eigenen sind, benutze keine urheberrechtlich geschützten Werke ohne Erlaubnis des Urhebers!
Du gibst uns hiermit deine Zusage, dass du den Text selbst verfasst hast, dass der Text Allgemeingut (public domain) ist oder dass der Urheber seine Zustimmung gegeben hat. Falls dieser Text bereits woanders veröffentlicht wurde, weise bitte auf der Diskussionsseite darauf hin. Bitte beachte, dass alle KIF-Beiträge automatisch unter der „Namensnennung-Weitergabe unter gleichen Bedingungen 2.5 “ stehen (siehe KIF:Urheberrechte für Einzelheiten). Falls du nicht möchtest, dass deine Arbeit hier von anderen verändert und verbreitet wird, dann klicke nicht auf „Seite speichern“.
Abbrechen Bearbeitungshilfe (wird in einem neuen Fenster geöffnet)