-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
请问,这个支持其他端口么? #7
Comments
branch: for-2.4
python: 2.7
ansible: 2.4 我看 myinventory.py中介绍的 使用如下方法: 于是乎我修改我的python代码: # cat ad_hoc.py
#!/usr/bin/env python
from pprint import pprint
from ansible2_myAPI.runner import Runner
runner = Runner(
module_name="shell",
module_args="df -h",
pattern="all",
hosts={
"group1": {
"hosts": [{"hostname": "10.10.10.10", "port": "23",
"username": "test", "password": "mypass"}]
}
}
)
result = runner.run()
print(result)
# 修改完毕后,报错如下: # ./ad_hoc.py
Traceback (most recent call last):
File "./ad_hoc.py", line 13, in <module>
"username": "test", "password": "mypass"}]
File "/root/python/ansible2_myAPI/runner.py", line 118, in __init__
self.inventory = MyInventory(host_list=hosts)
File "/root/python/ansible2_myAPI/myinventory.py", line 33, in __init__
super(MyInventory, self).__init__(self.loader, host_list)
File "/usr/lib/python2.7/site-packages/ansible/inventory/manager.py", line 145, in __init__
self.parse_sources()
File "/root/python/ansible2_myAPI/myinventory.py", line 50, in parse_sources
parsed = self.parse_source(self._sources)
File "/root/python/ansible2_myAPI/myinventory.py", line 71, in parse_source
raise AnsibleParserError("No plugin could parse your data.")
ansible.errors.AnsibleParserError: No plugin could parse your data.
# 请问,修改端口应该怎么样修改呢? |
组变量里不能放置密码,这里应该是我写错了, 你用sshkey的方式执行下应该可以执行通过。 |
大胸弟,不行呀,我试了一下,还是有问题,我尝试修改了一下你的代码,让它输出一些信息出来,如下: def parse_sources(self, cache=False):
"""
覆盖父类的解析方法,因为父类的该方法要:
1. 遍历内容
2. 路径字符串处理
而这里的解析只需要直接解析就行.
"""
self._setup_inventory_plugins()
parsed = self.parse_source(self._sources)
if parsed:
self._inventory.reconcile_inventory()
self._inventory_plugins = []
def parse_source(self, source):
parsed = False
if not self._inventory_plugins:
self._setup_inventory_plugins()
for plugin in self._inventory_plugins:
if plugin.verify_file(source):
print (type(plugin))
try:
plugin.parse(self._inventory, self._loader, source)
parsed = True
break
except Exception as e:
print ("The Program Exception ... ")
print (e)
pass
else:
raise AnsibleParserError("No plugin could parse your data.")
return parsed 我的客户端python测试脚本 # cat ad_hoc.py
#!/usr/bin/env python
from pprint import pprint
from ansible2_myAPI.runner import Runner
runner = Runner(
module_name="shell",
module_args="df -h",
pattern="all",
hosts={
"group1": {
"hosts": [{
"hostname": "127.0.0.1",
}]
}
}
)
result = runner.run()
pprint(result)
# 报错如下: # ./ad_hoc.py
<class 'ansible2_myAPI.myinventory.InventoryDictPlugin'>
The Program Exception ...
unhashable type: 'dict'
Traceback (most recent call last):
File "./ad_hoc.py", line 13, in <module>
"hostname": "127.0.0.1",
File "/root/python/ansible2_myAPI/runner.py", line 118, in __init__
self.inventory = MyInventory(host_list=hosts)
File "/root/python/ansible2_myAPI/myinventory.py", line 33, in __init__
super(MyInventory, self).__init__(self.loader, host_list)
File "/usr/lib/python2.7/site-packages/ansible/inventory/manager.py", line 145, in __init__
self.parse_sources()
File "/root/python/ansible2_myAPI/myinventory.py", line 50, in parse_sources
parsed = self.parse_source(self._sources)
File "/root/python/ansible2_myAPI/myinventory.py", line 74, in parse_source
raise AnsibleParserError("No plugin could parse your data.")
ansible.errors.AnsibleParserError: No plugin could parse your data.
# 最后报错 unhashable type: 'dict' 这个有点蒙蔽,看不太懂 |
hosts = { 参考下这个格式 |
我刚看了下,默认仅支持22端口对吧,请问,支持其他端口么?
The text was updated successfully, but these errors were encountered: