Custom Ansible Modules.
Well, why is pretty straightforward here.
Custom modules extend Ansible's functionality.
That gives Ansible the ability to perform tasks that
otherwise don't have coverage or support.
And as you see in this benefits list,
I brought it all out together because it's really quite simple.
Sometimes you have to do it yourself.
The custom module creation process.
Remember, I'm not going into developer land here.
We're staying high level.
First thing,
you're going to want to make sure that you've specified or anchored where
your custom modules are in your Ansible config file.
You could also have a custom config for your project, of course.
The main bulk of the work is simply compiling your business logic into a Python,
py, script file.
Really, that's all it is at base.
And then, as long as Ansible knows where to go,
where your library directory is, where your custom modules are,
you can then reference those in your playbooks just
like you would any built‑ins.
It's no more complicated than that.
And here's an example custom module that I call win_service_status, and we
have in our import list here‑‑‑ This is different actually. This was a
surprise when I first saw this. I expected that Red Hat maintains an
official Ansible Python library or SDK.
But no, that's not the case.
Instead, what we're doing here is that we're importing directly from Ansible.
So we would need to have access. We would need to be connected to our control
node in order to access the internal Ansible data structures.
But this example is tapping into that data structure and bringing
out a class definition for Ansible modules.
And sure enough, AnsibleModule class allows you to create,
edit, and delete Ansible module content.
If you already know Python or you have colleagues who are proficient,
they will be relieved that there's nothing proprietary here.
The actual business logic that you want to do in your Windows environment
depends entirely on your Python skills because it's just garden variety
Python logic. And same thing down at the bottom.
You see the main method and the name declaration,
that's all standard garden variety Python entry point stuff. Time for our demo.