2017-03-05 38 views
0

我正在AWS LAMBDA內部下面的腳本:「博託需要這種模塊」錯誤Ansible

#!/usr/bin/python 

from __future__ import print_function 

import json 
import os 
import ansible.inventory 
import ansible.playbook 
import ansible.runner 
import ansible.constants 
from ansible import utils 
from ansible import callbacks 

print('Loading function') 

def run_playbook(**kwargs): 

    stats = callbacks.AggregateStats() 
    playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY) 
    runner_cb = callbacks.PlaybookRunnerCallbacks(
     stats, verbose=utils.VERBOSITY) 

    # use /tmp instead of $HOME 
    ansible.constants.DEFAULT_REMOTE_TMP = '/tmp/ansible' 

    out = ansible.playbook.PlayBook(
     callbacks=playbook_cb, 
     runner_callbacks=runner_cb, 
     stats=stats, 
     **kwargs 
    ).run() 

    return out 


def lambda_handler(event, context): 
    return main() 



def main(): 
    out = run_playbook(
     playbook='little.yml', 
     inventory=ansible.inventory.Inventory(['localhost']) 
    ) 
    return(out) 


if __name__ == '__main__': 
    main() 

不過,我得到以下錯誤:failed=True msg='boto required for this module'

然而,根據此評論(https://github.com/ansible/ansible/issues/5734#issuecomment-33135727 ), 有用。

但是,我不理解我在腳本中如何提及它?或者,我可以單獨擁有一個hosts文件,並將其包含在腳本中,就像我打電話給我的劇本一樣?

如果是這樣,那麼怎麼樣?

[編輯 - 1] 我添加了這行inventory=ansible.inventory.Inventory('hosts') 用hosts文件:

[localhost] 
127.0.0.1 ansible_python_interpreter=/usr/local/bin/python 

但是,我得到這個錯誤:/bin/sh: /usr/local/bin/python: No such file or directory

所以,凡被蟒蛇位於內AWS LAMBDA?

我安裝boto就像我安裝在拉姆達的部署其它軟件包:pip install boto -t <folder-name>

+0

爲什麼沒有提到你是如何安裝boto的?相反,你可以參考一篇關於macOS中Homebrew軟件包管理器的默認目錄結構的文章?這裏與AWS Lambda的連接是什麼? – techraf

+0

@techraf更新了答案。在AWS Lambda中,所有包和腳本應位於同一個根文件夾中。 [腳本在我的本地運行良好]。因此,Lambda在boto軟件包中的位置肯定存在問題。 – Dawny33

回答

0

bash命令which python將通常給Python的二進制文件的位置。有一個如何從AWS Lambda here調用bash腳本的示例。