A
A
Artem Kiryanov2020-09-09 18:37:16
Ansible
Artem Kiryanov, 2020-09-09 18:37:16

How to create an Ansible plugin in Python?

You need to create a plugin for Ansible in Python. But in the official documentation I can't figure out how to create plugins for ansible.
My structure:
roles/test_tasks/main.yml - the role is described in it
. The run.yml file in it: hosts, roles are described.
I also created a library folder and wrote the code in Python. But when I start the playbook, my module doesn't start.
How to register or launch it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-09-09
@hacker342

Documentation

Ansible loads plugins automatically too, loading each type of plugin separately from a directory named for the type of plugin. Here’s the full list of plugin directory names:

action_plugins*
cache_plugins
callback_plugins
connection_plugins
filter_plugins*
inventory_plugins
lookup_plugins
shell_plugins
strategy_plugins
test_plugins*
vars_plugins
To load your local plugins automatically, create or add them in any of these locations:

any directory added to the relevant ANSIBLE_plugin_type_PLUGINS environment variable (these variables, such as $ANSIBLE_INVENTORY_PLUGINS and $ANSIBLE_VARS_PLUGINS take colon-separated lists like $PATH)
the directory named for the correct plugin_type within ~/.ansible/plugins/ - for example, ~/.ansible/plugins/callback
the directory named for the correct plugin_type within /usr/share/ansible/plugins/ - for example, /usr/share/ansible/plugins/action

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question