1

Is there any nice way to use Ansible Galaxy order to install and enable Ansible (2.7.9) custom modules?

My requirement allows Ansible Galaxy to download the right Ansible role which embeds my custom module. Once ansible-galaxy install --roles-path ansible/roles/ -r roles/requirements.yml, I get the following structure (non-exhaustive):

├── ansible
│   ├── roles
│   │   ├── mymodule (being imported by Galaxy)
│   │   │   ├── library
│   │   │   │   └── mymodule.py

By looking this part of the documentation, it seems like my module is at the right place and does not require any further configuration: https://docs.ansible.com/ansible/latest/user_guide/playbooks_best_practices.html?highlight=library#directory-layout

But when I found this part of the documentation I got confused. Is ANSIBLE_LIBRARY related to the custom modules?

DEFAULT_MODULE_PATH

Description: Colon separated paths in which Ansible will search for Modules.

Type: pathspec

Default: ~/.ansible/plugins/modules:/usr/share/ansible/plugins/modules

Ini Section: defaults

Ini Key: library

Environment: ANSIBLE_LIBRARY

https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-module-path

When calling my module,

  - name: Test of my Module
    mymodule:

I get the following error:

ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

I expected not to have to configure the ANSIBLE_LIBRARY and the module being automatically callable. Am I understanding correctly or should I also trick this var?

Ninroot
  • 61
  • 1
  • 8

1 Answers1

1

If your custom module is in a role, you need to include the role in your playbook, so at the very least:

---
- hosts: myhosts

  roles:
    - role: mymodule

  tasks:
    - name: Test of my Module
      mymodule:
Zeitounator
  • 38,476
  • 7
  • 53
  • 66
  • Works like a charm! Not sure to understand why we need to explicitly include it though. Any explanation or documentation? – Ninroot Oct 24 '19 at 15:58
  • 1
    Ansible is not parsing all your roles by default when it starts your playbook. Roles can contain e.g. handlers. You can use those handlers only if role was used. Same goes for custom modules. You can put your modules in a `library` folder at the same level as your playbook. Those will be parsed unconditionally. – Zeitounator Oct 24 '19 at 19:29