tech:ansible_collection
Ceci est une ancienne révision du document !
Table des matières
Ansible collection
Voir :
Exemple
/data/ansible/collections/ansible_collections/acme_it/test
.ansible.cfg
collections_path = /data/ansible/collections, $HOME/.ansible/collections, /usr/share/ansible/collections
Voir aussi la variable d’environnement ANSIBLE_COLLECTIONS_PATHS
collections/requirements.yml
--- collections: - name: https://git.acme.local/ansible_collections/my_collection type: git version: master
ansible-galaxy collection install -r collections/requirements.yml -p /home/ansible/.ansible/collections/
- name: Install collections community.general.ansible_galaxy_install: type: collection requirements_file: collections/requirements.yml dest: ~/.ansible/collections/ changed_when: false
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 ^#
Lister les collections installées
ansible-galaxy collection list
Rechercher une collection distante
ansible-galaxy search plop
Utiliser une collection distante
- collections/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
- collections/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.1757510442.txt.gz · Dernière modification : de Jean-Baptiste
