Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible not looking for modules in ./library alongside playbook

Tags:

ansible

In the ansible documentation intro_configuration it is said that:

Ansible ... it also will look for modules in the ”./library” directory alongside a playbook.

Im my case the only way I get that the directive provide by gaqzi.ssh-config was seen by ansible was to explicitly export ANSIBLE_LIBRARY with a full path ;(

Without that gaqzi.ssh-config module is not found by ansible, regarding the documentation it should.

Here what I have to do to make it work::

$ cd playbook   # my folder were the plabooks are
$ ansible-galaxy install -p library gaqzi.ssh-config  # I get a lib
$ export ANSIBLE_LIBRARY=/home/me/full/path/to/the/above/playbook/library
$    # the export above is annoying

How can I dynamicaly check the places Ansible is really looking for 'library' ?

PS1: I'm using ansible 2.0 and vagrant 1.8.1::

$ vagrant --version
Vagrant 1.8.1
$ ansible --version
ansible 2.0.0.2
config file = /etc/ansible/ansible.cfg
$

PS2: I took care to remove all ansible.cfg/.ansible.cfg files excepted the one provide by ubuntu in /etc/ansible/ansible.cfg

like image 248
user3313834 Avatar asked May 15 '16 08:05

user3313834


2 Answers

Ansible actually do search in current_playbook/library directory.

You can test this with the following setup:

  1. Place this custom_module.py into library subdir:

    #!/usr/bin/python
    import json
    print json.dumps({"hello" : "world"})
    
  2. Make the following test.yml playbook:

    ---
    - hosts: localhost
      tasks:
        - name: custom module
          custom_module:
    
  3. Execute ansible-playbook -vv test.yml

With ansible-galaxy you install role, not module.
Parameter -p for ansible-galaxy defines the ROLE_PATH.

If you want just a module ssh_config from the gaqzi.ssh-config role,
you need to copy the ssh_config.py from current_playbook/library/gaqzi.ssh-config/library into current_playbook/library.

Alternatively you can install the gaqzi.ssh-config role into roles directory, as expected.
Then modify your playbook to apply this role by adding:

roles:
  - gaqzi.ssh-config

After applying this role, module ssh_config will become available in your playbook.

like image 75
Konstantin Suvorov Avatar answered Oct 31 '22 23:10

Konstantin Suvorov


Actually, you can set a role module as a dependency of your role, for example in your meta/main.yml file:

---
dependencies:
  - { role: gaqzi.ssh-config }

Then you can start using the module in your role.

like image 45
jbactad Avatar answered Nov 01 '22 01:11

jbactad