{{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 ~~~