Outils pour utilisateurs

Outils du site


tech:ansible_collection

Ceci est une ancienne révision du document !


Ansible collection

Généralités

Les collections les plus utilisées

  • ansible.builtin
  • community.general
  • ansible.posix

Dépôts distants :

Collection path

$ ansible --version |grep collection
  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 ^#

Utiliser une collection distante

requirements.yml
---
collections:
  - name: https://acme.fr/plop/acme-plop.tar.gz
    version: X.Y.Z

  - name: git+https://git.acme.local/acme/plop.git#ansible_collections/acme/plop
    version: master

Rapatrier les collections distantes en local

ansible-galaxy collection install -r collections/requirements.yml
play.yml
#!/usr/bin/env ansible-playbook
---
- name: exemple
  hosts: localhost
  collections:
    - acme.plop

  roles:
    - install_plop

Ou

git clone ssh://git@git.acme.fr/plop/plop.git
 
cd plop/
mkdir ~/.ansible/
cp -a collection/ ~/.ansible/
 
ls -l ~/.ansible/collections/ansible_collections/awx
 
ansible-doc acme.awx.tower_credential

Exemple de collection distante sur Git

requirements.yml
---    

collections:
  - name: https://git.acme.fr/ansible-automation-platform/PlaybooksGroupe/dns_cache_enable
    type: git

git.acme.fr/ansible-automation-platform/PlaybooksGroupe/dns_cache_enable

dns_cache_enable/

  • roles/
  • galaxy.yml
galaxy.yml
---

namespace: acme
name: dns
version: 1.0.0
license: BSD
readme: README.md
authors:
  - Jean <jean@acme.fr>

description: DNS client collection
tasks/main.yml
- name: Enable local cache DNS
  include_role:
    name: acme.dns.enable_local_cache_dns

Utiliser une collection locale

Chemin possible

  • ~/.ansible/collections/ansible_collections/acme/plop/
  • collections/ansible_collections/acme/plop/

Composition d'une collection

Exemple d'arborescence :

  • COPYING
  • FILES.json
  • images/
  • MANIFEST.json
  • meta/
  • plugins/
  • README.md
  • requirements.txt
  • setup.cfg
  • test/
  • TESTING.md
  • tests/
  • tools/

Autres

git clone ssh://git@git.acme.fr/plop/projet1.git

cd projet1/
mkdir ~/.ansible/
cp -a collection/ ~/.ansible/

ln -s ~/.ansible/collections/ansible_collections/acme ~/.ansible/collections/ansible_collections/awx

ansible-doc acme.awx.tower_credential

Créer un paquet d'un role

tar czvf ./role_name.tar.gz ./role_name

La documentation est dans :

  • meta/main.yml
  • README.md

Installer un role

ansible-galaxy install ./role_name.tar.gz
ansible-galaxy install role_name

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.1756910859.txt.gz · Dernière modification : de Jean-Baptiste

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki