我这使用ansable的时候,上面定义了options,为什么执行的时候报这个错
来源:5-18 (资产探测、扫描发现进阶)章节知识回顾
weixin_慕数据7571500
2021-04-12
Traceback (most recent call last):
File “ansible_api_k1.py”, line 85, in
passwords=passwords,
TypeError: init() got an unexpected keyword argument 'options’
root@yang-PC:/home/yang/PycharmProjects/mydevops/script#
请教老师个问提,我这使用ansable的时候,上面定义了options,为什么执行的时候报这个错
下面是代码
-- coding: utf-8 --
#!/usr/bin/env python
from collections import namedtuple
from ansible.parsing.dataloader import DataLoader
from ansible.vars.manager import VariableManager
from ansible.inventory.manager import InventoryManager
from ansible.playbook.play import Play
from ansible.executor.task_queue_manager import TaskQueueManager
from ansible.plugins.callback import CallbackBase
InventoryManager类
loader = DataLoader()
inventory = InventoryManager(loader=loader,sources=[‘imoocc_hosts’])
#VariableManager类
variable_manager = VariableManager(loader=loader,inventory=inventory)
#Options 执行选项
Options = namedtuple(‘Options’,
[‘connection’,
‘remote_user’,
‘ask_sudo_pass’,
‘verbosity’,
‘ack_pass’,
‘module_path’,
‘forks’,
‘become’,
‘become_method’,
‘become_user’,
‘check’,
‘listhosts’,
‘listtasks’,
‘listtags’,
‘syntax’,
‘sudo_user’,
‘sudo’,
‘diff’])
options = Options(connection=‘smart’,
remote_user=None,
ack_pass=None,
sudo_user=None,
forks=5,
sudo=None,
ask_sudo_pass=False,
verbosity=5,
module_path=None,
become=None,
become_method=None,
become_user=None,
check=False,
diff=False,
listhosts=None,
listtasks=None,
listtags=None,
syntax=None)
play_source = dict(
name = “Ansible Play ad-hoc test”,
hosts = ‘192.168.44.129’,
gather_facts = ‘no’,
tasks = [
dict(action=dict(module=‘shell’, args=‘touch /tmp/ad_hoc_test1’)),
# dict(action=dict(module=‘debug’, args=dict(msg=’{{shell_out.stdout}}’)))
]
)
play = Play().load(play_source, variable_manager=variable_manager, loader=loader)
passwords = dict()
print(options)
print(‘’)
print(variable_manager.get_vars())
print('’)
tqm = TaskQueueManager(
inventory=inventory,
variable_manager=variable_manager,
loader=loader,
options=options,
passwords=passwords,
)
2回答
-
Jeson
2021-04-15
看看你的ansible版本匹配吗?ansible>=2.6.3
00 -
weixin_慕数据7571500
提问者
2021-04-13
fatal: [192.168.44.129]: FAILED! => {"msg": "the connection plugin '<class 'ansible.utils.sentinel.Sentinel'>' was not found"}
把options注释掉,就能执行了。但是会报错
00
相似问题