tech:ansible_collection
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:ansible_collection [2025/09/10 15:36] – Jean-Baptiste | tech:ansible_collection [2026/06/07 19:12] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Ansible collection | ||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | Dépendances : | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | Exemple | ||
| + | |||
| + | `/ | ||
| + | |||
| + | `.ansible.cfg` | ||
| + | ~~~python | ||
| + | collections_path = / | ||
| + | ~~~ | ||
| + | |||
| + | Voir aussi la variable d’environnement `ANSIBLE_COLLECTIONS_PATHS` | ||
| + | |||
| + | `collections/ | ||
| + | ~~~yaml | ||
| + | --- | ||
| + | |||
| + | collections: | ||
| + | - name: https:// | ||
| + | # type: git | ||
| + | scm: git | ||
| + | version: master | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | ansible-galaxy collection install -r collections/ | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ~~~yaml | ||
| + | - name: Install collections | ||
| + | community.general.ansible_galaxy_install: | ||
| + | type: collection | ||
| + | requirements_file: | ||
| + | dest: ~/ | ||
| + | changed_when: | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Généralités | ||
| + | |||
| + | Les collections les plus utilisées | ||
| + | * ansible.builtin | ||
| + | * community.general | ||
| + | * ansible.posix | ||
| + | |||
| + | Dépôts distants : | ||
| + | * https:// | ||
| + | |||
| + | Collection path | ||
| + | |||
| + | ~~~ | ||
| + | $ ansible --version | grep collection | ||
| + | ansible collection location = / | ||
| + | |||
| + | $ ansible-config dump | grep -i collection | ||
| + | |||
| + | $ ansible-config init --disabled | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Lister les collections installées | ||
| + | ~~~bash | ||
| + | ansible-galaxy collection list | ||
| + | ~~~ | ||
| + | |||
| + | Rechercher une collection distante | ||
| + | ~~~bash | ||
| + | ansible-galaxy search plop | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Utiliser une collection distante | ||
| + | |||
| + | `collections/ | ||
| + | ~~~yaml | ||
| + | --- | ||
| + | collections: | ||
| + | - name: https:// | ||
| + | version: X.Y.Z | ||
| + | |||
| + | - name: git+https:// | ||
| + | version: master | ||
| + | ~~~ | ||
| + | |||
| + | Rapatrier les collections distantes en local | ||
| + | ~~~bash | ||
| + | ansible-galaxy collection install -r collections/ | ||
| + | ~~~ | ||
| + | |||
| + | `play.yml` | ||
| + | ~~~yaml | ||
| + | # | ||
| + | --- | ||
| + | - name: exemple | ||
| + | hosts: localhost | ||
| + | collections: | ||
| + | - acme.plop | ||
| + | |||
| + | roles: | ||
| + | - install_plop | ||
| + | ~~~ | ||
| + | |||
| + | Ou | ||
| + | |||
| + | ~~~bash | ||
| + | git clone ssh:// | ||
| + | |||
| + | cd plop/ | ||
| + | mkdir ~/.ansible/ | ||
| + | cp -a collection/ ~/.ansible/ | ||
| + | |||
| + | ls -l ~/ | ||
| + | |||
| + | ansible-doc acme.awx.tower_credential | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Exemple de role distant sur Git | ||
| + | |||
| + | `roles/ | ||
| + | ~~~yaml | ||
| + | --- | ||
| + | |||
| + | - src: ssh:// | ||
| + | scm: git | ||
| + | version: master | ||
| + | |||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ### Exemple de collection distante sur Git | ||
| + | |||
| + | `collections/ | ||
| + | ~~~yaml | ||
| + | --- | ||
| + | |||
| + | collections: | ||
| + | - name: https:// | ||
| + | # type: git | ||
| + | scm: git | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | git.acme.fr/ | ||
| + | |||
| + | dns_cache_enable/ | ||
| + | * roles/ | ||
| + | * galaxy.yml | ||
| + | |||
| + | |||
| + | `galaxy.yml` | ||
| + | ~~~yaml | ||
| + | --- | ||
| + | |||
| + | namespace: acme | ||
| + | name: dns | ||
| + | version: 1.0.0 | ||
| + | license: BSD | ||
| + | readme: README.md | ||
| + | authors: | ||
| + | - Jean < | ||
| + | |||
| + | description: | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | `tasks/ | ||
| + | ~~~yaml | ||
| + | |||
| + | - name: Enable local cache DNS | ||
| + | include_role: | ||
| + | name: acme.dns.enable_local_cache_dns | ||
| + | |||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Utiliser une collection locale | ||
| + | |||
| + | |||
| + | Chemin possible | ||
| + | * ~/ | ||
| + | * collections/ | ||
| + | |||
| + | ## Composition d'une collection | ||
| + | |||
| + | Exemple d' | ||
| + | * COPYING | ||
| + | * FILES.json | ||
| + | * images/ | ||
| + | * MANIFEST.json | ||
| + | * meta/ | ||
| + | * plugins/ | ||
| + | * README.md | ||
| + | * requirements.txt | ||
| + | * setup.cfg | ||
| + | * test/ | ||
| + | * TESTING.md | ||
| + | * tests/ | ||
| + | * tools/ | ||
| + | |||
| + | |||
| + | ## Autres | ||
| + | |||
| + | ~~~bash | ||
| + | git clone ssh:// | ||
| + | |||
| + | cd projet1/ | ||
| + | mkdir ~/.ansible/ | ||
| + | cp -a collection/ ~/.ansible/ | ||
| + | |||
| + | ln -s ~/ | ||
| + | |||
| + | ansible-doc acme.awx.tower_credential | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | |||
