{{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''
#! /usr/bin/env ansible-playbook
- name: test plugin
hosts: localhost
roles:
- plugin
- hello
''roles/plugin/library/plug1''
#! /bin/bash
display="This is a simple bash module.."
echo -e "{\"Message\":\""$display"\"}"
''roles/hello/tasks/main.yml''
---
- name: test plugin plug1
plug1:
./play-test-plugin.yml -v
== Tester un module
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