Outils pour utilisateurs

Outils du site


tech:notes_ansible_plugins

Différences

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

Lien vers cette vue comparative

Prochaine révision
Révision précédente
tech:notes_ansible_plugins [2025/03/24 15:06] – créée - modification externe 127.0.0.1tech:notes_ansible_plugins [2026/06/07 19:12] (Version actuelle) – modification externe 127.0.0.1
Ligne 1: Ligne 1:
 +<!DOCTYPE markdown>
 +{{tag>Brouillon Ansible CA}}
 +
 +# Notes Ansible plugins
 +
 +Créer ses plugins
 +
 +Voir :
 +* https://docs.ansible.com/ansible/latest/dev_guide/developing_locally.html
 +* https://www.techbeatly.com/how-to-add-custom-modules-in-ansible/
 +* https://ansible-tutorial.schoolofdevops.com/custom_modules/
 +* https://vincent.bernat.ch/fr/blog/2020-ecrire-module-ansible
 +* https://blog.toast38coza.me/custom-ansible-module-hello-world/
 +
 +
 +## Hello world
 +
 +Plugin simple en bash et dans un rôle
 +
 +`play-test-plugin.yml`
 +~~~yaml
 +#! /usr/bin/env ansible-playbook
 +
 +- name: test plugin
 +  hosts: localhost
 +
 +  roles:
 +    - plugin
 +    - hello
 +~~~
 +
 +
 +`roles/plugin/library/plug1`
 +~~~bash
 +#! /bin/bash
 +
 +display="This is a simple bash module.."
 +echo -e "{\"Message\":\""$display"\"}"
 +~~~
 +
 +
 +`roles/hello/tasks/main.yml`
 +~~~yaml
 +---
 +
 +- name: test plugin plug1
 +  plug1:
 +~~~
 +
 +~~~bash
 +./play-test-plugin.yml -v
 +~~~
 +
 +
 +## Tester un module
 +
 +~~~bash
 +echo -e '{ "ANSIBLE_MODULE_ARGS": { "database": "hosts"} }' | python3.6 /usr/lib/python3.6/site-packages/ansible/modules/system/getent.py | jq .
 +
 +echo -e '{ "ANSIBLE_MODULE_ARGS": {} }' | python3 roles/plop/library/plop_check
 +~~~
 +
 +
  

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki