Dragon Creature
Dragon Creature

Reputation: 1995

Include none python files to module

I'm writing my own module to ansible and part of the code can't be in python as the software I'm working against does not have a python api. It does support groovy so I included a groovy script but in the module directory but when i run the module i notice that ansible copies all python files in the module to /tmp/ansible_{{ some_random_character }}. However ansible does not include my groovy script so when i try to run the module it crashes as it can't find the groovy script. Is there some way to tell ansible to include all files in the module directory not just python files?

The module directory look like this now

module

  __init__.py
  deploy.groovy
  deploy.py

code sample (if there is a better way to do it)

pathname = os.path.dirname(sys.argv[0])
p = subprocess.Popen("groovy " + pathname + "/deploy.groovy ")

Upvotes: 0

Views: 109

Answers (1)

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68279

From Developing Modules:

Modules must be self-contained in one file to be auto-transferred by ansible.

Why not use groovy-script as a module?

Put groovy_module into library directory:

#!/usr/bin/groovy

// Groovy code goes here
println "{\"hello\":\"world\"}"

And call from your playbook:

  tasks:
    - groovy_module:

Ensure that groovy is installed on the target machine.

Upvotes: 1

Related Questions