我构建了一个 API,它将系统配置参数作为剧本变量,并动态构建剧本并尝试运行它们。我可以访问我的 API,但 Ansible 在通过调用时抛出以下错误
Options = namedtuple('Options', ['connection', 'module_path', 'forks', 'become', 'become_method', 'become_user', 'check', 'diff', 'listhosts', 'listtasks', 'listtags', 'syntax'])
loader = DataLoader()
options = Options(connection='local', module_path='%s/' % (ROOT_DIR), forks=100, become=None, become_method=None, become_user=None, check=False,
diff=False, listhosts=False, listtasks=False, listtags=False, syntax=False)
passwords = dict(vault_pass='secret')
inventory = InventoryManager(loader=loader, sources=[inventory_path])
variable_manager = VariableManager(loader=loader, inventory=inventory)
executor = PlaybookExecutor(
playbooks=[playbook_path], inventory=inventory, variable_manager=variable_manager, loader=loader,
options=options, passwords=passwords)
results = executor.run()
这是错误:
fatal: [localhost]: UNREACHABLE! => {"changed": false, "msg": "Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \"/tmp\". Failed command was: ( umask 77 && mkdir -p \"
echo /tmp/ansible/ansible-tmp-1527184628.45-99532072739462
\" && echo ansible-tmp-1527184628.45-99532072739462=\"echo /tmp/ansible/ansible-tmp-1527184628.45-99532072739462
\" ), exited with result 127", "unreachable": true}
剧本在本地主机上运行,我的连接参数也设置为本地,所以我不确定问题是什么。
最佳答案
检查 /tmp/ansible
下的权限。最好的选择是将您的 ansible.cfg
配置为指向:
remote_tmp = /tmp/.ansible-${USER}/tmp
From davesnigier.com and github
关于python - 尝试通过远程 api 调用运行 ansible playbook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50588415/