tech:bonnes_pratiques_ansible
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| tech:bonnes_pratiques_ansible [2025/11/03 13:53] – Jean-Baptiste | tech:bonnes_pratiques_ansible [2025/11/20 16:27] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 74: | Ligne 74: | ||
| Éviter d' | Éviter d' | ||
| Privilégier **M(command)** à **M(shell)** \\ | Privilégier **M(command)** à **M(shell)** \\ | ||
| - | Si variables Jinja en argument à M(command) ou M(shell) : utiliser '' | + | Si variables Jinja en argument à M(shell) : utiliser '' |
| Pour **M(command)**, | Pour **M(command)**, | ||
| * '' | * '' | ||
| Ligne 193: | Ligne 193: | ||
| ==== Run_once | ==== Run_once | ||
| + | |||
| + | |||
| + | |||
| + | run_once will be executed at each serial execution in the play. That means, if you choose serial = 1, it will be asked to confirm as many times as the quantity of targets on the play. | ||
| + | |||
| + | Check Ansible docs: https:// | ||
| When used together with serial, tasks marked as run_once will be run on one host in each serial batch. If the task must run only once regardless of serial mode, use '' | When used together with serial, tasks marked as run_once will be run on one host in each serial batch. If the task must run only once regardless of serial mode, use '' | ||
| Attention aux slicing ! | Attention aux slicing ! | ||
| + | |||
| + | |||
| + | |||
| + | === Limiter l' | ||
| + | |||
| + | <code yaml> | ||
| + | - name: Installation d'un logiciel sur plusieurs serveurs avec throttle | ||
| + | ansible.builtin.apt: | ||
| + | name: nginx | ||
| + | state: present | ||
| + | async: 600 # Exécution en mode asynchrone avec un délai maximum de 10 minutes | ||
| + | poll: 5 # Vérification toutes les 5 secondes | ||
| + | throttle: 3 # Limite à 3 installations simultanées | ||
| + | when: inventory_hostname in groups[' | ||
| + | </ | ||
| + | |||
| Ligne 214: | Ligne 236: | ||
| Variable Management for Inventory - Keeping variable data along with the hosts and groups definitions (see the inventory editor) is encouraged, rather than using group_vars/ and host_vars/ | Variable Management for Inventory - Keeping variable data along with the hosts and groups definitions (see the inventory editor) is encouraged, rather than using group_vars/ and host_vars/ | ||
| - | Autoscaling - Using the “callback” feature to allow newly booting instances to request configuration is very useful for auto-scaling scenarios or provisioning integration. | + | Autoscaling - Using the “callback” feature to allow newly booting instances to request configuration is very useful for auto-scaling scenarios or provisioning integration.$ |
| Larger Host Counts - Consider setting “forks” on a job template to larger values to increase parallelism of execution runs. Voir : Strategy, Mitogen, Slicing, Async (Asynchronous) (RA_PERF_N3) | Larger Host Counts - Consider setting “forks” on a job template to larger values to increase parallelism of execution runs. Voir : Strategy, Mitogen, Slicing, Async (Asynchronous) (RA_PERF_N3) | ||
| Ligne 220: | Ligne 242: | ||
| Ne pas utiliser Verbosity à 4 ou 5. Eviter d' | Ne pas utiliser Verbosity à 4 ou 5. Eviter d' | ||
| - | Ne pas mettre les facts des noeuds | + | Ne pas mettre les facts des nœuds |
| Le cache des facts doit être sur les managed_hosts et non coté serveur (RA_GEN_N1) | Le cache des facts doit être sur les managed_hosts et non coté serveur (RA_GEN_N1) | ||
| + | |||
| + | Ne pas faire de '' | ||
| + | |||
| + | |||
| Ligne 424: | Ligne 450: | ||
| Utiliser '' | Utiliser '' | ||
| + | |||
| + | Pour les données sensibles utiliser ansible-vault ou les Crendential AWX (RA_SEC_N1) | ||
| Troubleshooting untrusted templates | Troubleshooting untrusted templates | ||
| Ligne 513: | Ligne 541: | ||
| Source : https:// | Source : https:// | ||
| - | |||
| - | === Files | ||
| - | |||
| - | Si beaucoup de templates dans le role : utiliser une arborescence du style : | ||
| - | * files/ | ||
| === Extra_vars | === Extra_vars | ||
tech/bonnes_pratiques_ansible.1762174430.txt.gz · Dernière modification : de Jean-Baptiste
