saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.2k stars 5.48k forks source link

salt unable to find custom module #42797

Closed Set4now closed 7 years ago

Set4now commented 7 years ago

Hi, i have a custom module and copied it under /srv/salt/_modules then i did a salt master saltutil.sync_all, modules etc.. also restarted the salt-minion. still its showing 'renderv1' (module name) is not available. I also copied it under /usr/lib/python2.7/dist-packages/salt/modules/ and tried to run it, still no luck, restarted the salt-master, still no luck Please let me know what else can be checked. salt 2017.7.0 (Nitrogen)

Set4now commented 7 years ago

root@cri-server5:/usr/lib/python2.7/dist-packages/salt/modules# cp renderv1.py /srv/salt/_modules/ root@cri-server5:/usr/lib/python2.7/dist-packages/salt/modules# salt master saltutil.sync_all master:

beacons:
clouds:
engines:
grains:
log_handlers:
modules:
    - modules.renderv1
output:
proxymodules:
renderers:
returners:
sdb:
states:
utils:

root@cri-server5:/usr/lib/python2.7/dist-packages/salt/modules# salt master renderv1.run_query master: 'renderv1.run_query' is not available. ERROR: Minions returned with non-zero exit code

garethgreenaway commented 7 years ago

So far I haven't been able to reproduce this, can you provide what the custom module looks like?

Set4now commented 7 years ago

from sqlalchemy import * from jinja2 import Template import json import ast import inspect

def run_query(template, user, host, password, dbtype, dbname, **pillar): with open('/home/cloudadmin/jinja/' + template) as f: a=f.read() t=Template(a) if bool(pillar): for i in pillar.iteritems(): str=i[1]

result=t.render(str)
#result=t.render(tablename=pillar["tablename"], key=pillar["col_name"], value=pillar["value"])

db_url = "{}+pymysql://{}:{}@{}/{}?charset=utf8mb4&use_unicode=0".format(dbtype,user,password,host,dbname) engine = create_engine(db_url, pool_recycle=3600) connection = engine.connect() try: res=engine.execute(result) if res.returns_rows: output=[] for r in res: output.append(dict(r)) return json.dumps(output, indent=3) else: if res.class: return "Success" except: return "Invalid Query"