本文整理匯總了Python中ansible.constants.HOST_KEY_CHECKING屬性的典型用法代碼示例。如果您正苦於以下問題:Python constants.HOST_KEY_CHECKING屬性的具體用法?Python constants.HOST_KEY_CHECKING怎麽用?Python constants.HOST_KEY_CHECKING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類ansible.constants
的用法示例。
在下文中一共展示了constants.HOST_KEY_CHECKING屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run_playbook
# 需要導入模塊: from ansible import constants [as 別名]
# 或者: from ansible.constants import HOST_KEY_CHECKING [as 別名]
def run_playbook(self, playbook_path,extra_vars=None):
"""
run ansible palybook
"""
try:
# if self.redisKey:self.callback = PlayBookResultsCollectorToSave(self.redisKey,self.logId)
self.callback = PlayBookResultsCollector()
if extra_vars:self.variable_manager.extra_vars = extra_vars
executor = PlaybookExecutor(
playbooks=[playbook_path], inventory=self.inventory, variable_manager=self.variable_manager, loader=self.loader,
options=self.options, passwords=self.passwords,
)
executor._tqm._stdout_callback = self.callback
constants.HOST_KEY_CHECKING = False #關閉第一次使用ansible連接客戶端是輸入命令
executor.run()
except Exception as err:
return False
示例2: run_model
# 需要導入模塊: from ansible import constants [as 別名]
# 或者: from ansible.constants import HOST_KEY_CHECKING [as 別名]
def run_model(self, host_list, module_name, module_args):
"""
run module from andible ad-hoc.
module_name: ansible module_name
module_args: ansible module args
"""
play_source = dict(
name="Ansible Play",
hosts=host_list,
gather_facts='no',
tasks=[dict(action=dict(module=module_name, args=module_args))]
)
play = Play().load(play_source, variable_manager=self.variable_manager, loader=self.loader)
tqm = None
# if self.redisKey:self.callback = ModelResultsCollectorToSave(self.redisKey,self.logId)
# else:self.callback = ModelResultsCollector()
self.callback = ModelResultsCollector()
import traceback
try:
tqm = TaskQueueManager(
inventory=self.inventory,
variable_manager=self.variable_manager,
loader=self.loader,
options=self.options,
passwords=self.passwords,
stdout_callback = "minimal",
)
tqm._stdout_callback = self.callback
constants.HOST_KEY_CHECKING = False #關閉第一次使用ansible連接客戶端是輸入命令
tqm.run(play)
except Exception as err:
print traceback.print_exc()
# DsRedis.OpsAnsibleModel.lpush(self.redisKey,data=err)
# if self.logId:AnsibleSaveResult.Model.insert(self.logId, err)
finally:
if tqm is not None:
tqm.cleanup()
示例3: _connect_ssh
# 需要導入模塊: from ansible import constants [as 別名]
# 或者: from ansible.constants import HOST_KEY_CHECKING [as 別名]
def _connect_ssh(spec):
"""
Return ContextService arguments for an SSH connection.
"""
if C.HOST_KEY_CHECKING:
check_host_keys = 'enforce'
else:
check_host_keys = 'ignore'
# #334: tilde-expand private_key_file to avoid implementation difference
# between Python and OpenSSH.
private_key_file = spec.private_key_file()
if private_key_file is not None:
private_key_file = os.path.expanduser(private_key_file)
return {
'method': 'ssh',
'kwargs': {
'check_host_keys': check_host_keys,
'hostname': spec.remote_addr(),
'username': spec.remote_user(),
'compression': convert_bool(
default(spec.mitogen_ssh_compression(), True)
),
'password': spec.password(),
'port': spec.port(),
'python_path': spec.python_path(),
'identity_file': private_key_file,
'identities_only': False,
'ssh_path': spec.ssh_executable(),
'connect_timeout': spec.ansible_ssh_timeout(),
'ssh_args': spec.ssh_args(),
'ssh_debug_level': spec.mitogen_ssh_debug_level(),
'remote_name': get_remote_name(spec),
'keepalive_count': (
spec.mitogen_ssh_keepalive_count() or 10
),
'keepalive_interval': (
spec.mitogen_ssh_keepalive_interval() or 30
),
}
}