我正在尝试在python中编写自己的salt runner,它执行git存储库的克隆,解析一些数据并提供一个名单文件 .

我现在被使用盐状态所困扰,好像我现在所拥有的是 .

def a_runner():
    gittarget='/var/tmp/some-repository'
    remote_url= 'ssh://git@some-repostitory'
    result = __salt__['state.single']('git.latest', name=remote_url, branch='master', target=gittarget, force_checkout=True, force_reset=True)

如果我跑这个跑步者我得到这个错误

Exception occurred in runner test.a_runner: Traceback (most recent call last):
      File "/usr/lib/python2.7/dist-packages/salt/client/mixins.py", line 382, in _low
        data['return'] = self.functions[fun](*args, **kwargs)
      File "/srv/salt/_runners/test.py", line 11, in a_runner
        result = __salt__['state.single']('git.latest',
      File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1114, in __getitem__
        func = super(LazyLoader, self).__getitem__(item)
      File "/usr/lib/python2.7/dist-packages/salt/utils/lazy.py", line 101, in __getitem__
        raise KeyError(key)
    KeyError: 'state.single'

我找到了解决问题的方法 . 不是最好的,但它对我有用

def a_runner():

    client = salt.client.LocalClient(__opts__['conf_file'])
    gittarget='/var/tmp/some-repository'
    remote_url= 'ssh://git@some-repostitory'

    try:
        clone_success = __salt__['salt.cmd'](fun='git.clone', cwd=gittarget, url=remote_url)

    except Exception as exc:
        log.error(
            'Exception \'%s\' caught while cloning git repository '
            'remote \'%s\'', str(exc), remote_url,
            exc_info_on_loglevel=logging.DEBUG
        )