Outils pour utilisateurs

Outils du site


tech:ansible_collection

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
tech:ansible_collection [2025/09/03 16:04] Jean-Baptistetech:ansible_collection [2025/11/13 12:02] (Version actuelle) Jean-Baptiste
Ligne 2: Ligne 2:
  
 = Ansible collection = Ansible collection
 +
 +Voir :
 +  * https://setgetweb.com/p/ansible/user_guide/collections_using.html
 +  * https://www.jeffgeerling.com/blog/2020/ansible-best-practices-using-project-local-collections-and-roles:
 +  * https://bryanttseng.medium.com/use-ansible-collection-from-github-private-repository-cd7837958ddd
 +  * https://docs.fedoraproject.org/en-US/packaging-guidelines/Ansible_collections/
 +  * https://blog.octo.com/introduction-aux-ansible-content-collections
 +  * https://docs.ansible.com/ansible/latest/reference_appendices/config.html
 +
 +
 +Dépendances :
 +  * https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_reuse_roles.html#role-dependencies
 +  * https://labexio.medium.com/how-to-manage-dependencies-in-ansible-roles-6148675bf4b8
 +  * https://docs.ansible.com/ansible/latest/galaxy/user_guide.html
 +  * https://labex.io/fr/tutorials/ansible-how-to-manage-dependencies-in-ansible-roles-415194
 +  * https://docs.debops.org/en/master/ansible/roles/etc_aliases/dependency.html
 +  * https://hostperl.com/kb/tutorials/advanced-ansible-playbooks
 +
 +
 +
 +
 +Exemple
 +
 +''/data/ansible/collections/ansible_collections/acme_it/test''
 +
 +''.ansible.cfg''
 +<code python>
 +collections_path = /data/ansible/collections, $HOME/.ansible/collections, /usr/share/ansible/collections
 +</code>
 +
 +Voir aussi la variable d’environnement ''ANSIBLE_COLLECTIONS_PATHS''
 +
 +''collections/requirements.yml''
 +<code yaml>
 +---
 +
 +collections:
 +  - name: https://git.acme.local/ansible_collections/my_collection
 +    # type: git
 +    scm: git
 +    version: master
 +</code>
 +
 +<code bash>
 +ansible-galaxy collection install -r collections/requirements.yml -p /home/ansible/.ansible/collections/
 +</code>
 +
 +
 +<code yaml>
 +    - name: Install collections
 +      community.general.ansible_galaxy_install:
 +        type: collection
 +        requirements_file: collections/requirements.yml
 +        dest: ~/.ansible/collections/
 +      changed_when: false
 +</code>
 +
  
 == Généralités == Généralités
Ligne 16: Ligne 73:
  
 <code -> <code ->
-$ ansible --version |grep collection+$ ansible --version | grep collection
   ansible collection location = /home/ansible/.ansible/collections:/usr/share/ansible/collections   ansible collection location = /home/ansible/.ansible/collections:/usr/share/ansible/collections
 +
 +$ ansible-config dump | grep -i collection
 +
 +$ ansible-config init --disabled  | grep -i collection | grep -v ^#
 </code> </code>
  
  
-== Utiliser une collection distante+Lister les collections installées 
 +<code bash> 
 +ansible-galaxy collection list 
 +</code>
  
 +Rechercher une collection distante
 +<code bash>
 +ansible-galaxy search plop
 +</code>
 +
 +
 +== Utiliser une collection distante
  
-<code yaml requirements.yml>+''collections/requirements.yml'' 
 +<code yaml>
 --- ---
 collections: collections:
Ligne 39: Ligne 111:
 </code> </code>
  
-<code yaml play.yml>+''play.yml'' 
 +<code yaml>
 #!/usr/bin/env ansible-playbook #!/usr/bin/env ansible-playbook
 --- ---
Ligne 64: Ligne 137:
 ansible-doc acme.awx.tower_credential ansible-doc acme.awx.tower_credential
 </code> </code>
 +
 +
 +=== Exemple de role distant sur Git
 +
 +''roles/requirements.yml''
 +<code yaml>
 +---
 +
 +- src: ssh://git@git.acme.local:2222/ansible/ansible-role-test_jb.git
 +  scm: git
 +  version: master
 +
 +</code>
 +
  
  
 === Exemple de collection distante sur Git === Exemple de collection distante sur Git
  
-<code yaml requirements.yml>+''collections/requirements.yml'' 
 +<code yaml>
 ---     ---    
  
 collections: collections:
   - name: https://git.acme.fr/ansible-automation-platform/PlaybooksGroupe/dns_cache_enable   - name: https://git.acme.fr/ansible-automation-platform/PlaybooksGroupe/dns_cache_enable
-    type: git+    type: git 
 +    scm: git
 </code> </code>
  
Ligne 84: Ligne 173:
  
  
-<code yaml galaxy.yml>+''galaxy.yml'' 
 +<code yaml>
 --- ---
  
Ligne 98: Ligne 188:
 </code> </code>
  
-<code yaml tasks/main.yml>+ 
 +''tasks/main.yml'' 
 +<code yaml>
  
 - name: Enable local cache DNS - name: Enable local cache DNS
Ligne 130: Ligne 222:
   * tests/   * tests/
   * tools/   * tools/
 +
  
 == Autres == Autres
  
-<code ->+<code bash>
 git clone ssh://git@git.acme.fr/plop/projet1.git git clone ssh://git@git.acme.fr/plop/projet1.git
  
Ligne 146: Ligne 239:
  
  
------------------ 
- 
-Créer un paquet d'un role 
-<code bash> 
-tar czvf ./role_name.tar.gz ./role_name 
-</code> 
- 
-La documentation est dans : 
-* meta/main.yml 
-* README.md 
- 
-Installer un role 
-<code bash> 
-ansible-galaxy install ./role_name.tar.gz 
-ansible-galaxy install role_name 
-</code> 
- 
-Par défaut dans ''~/.ansible/roles/'' 
- 
- 
-Voir : 
-  * ansible-galaxy list 
-  * ansible-galaxy search  
-  * ansible-galaxy install 
-  * ansible-galaxy import 
-  * ansible-galaxy info 
  
  
  
tech/ansible_collection.1756908254.txt.gz · Dernière modification : de Jean-Baptiste

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki