本文整理汇总了Python中ansible.inventory.host.Host方法的典型用法代码示例。如果您正苦于以下问题:Python host.Host方法的具体用法?Python host.Host怎么用?Python host.Host使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ansible.inventory.host
的用法示例。
在下文中一共展示了host.Host方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __parse_groups
# 需要导入模块: from ansible.inventory import host [as 别名]
# 或者: from ansible.inventory.host import Host [as 别名]
def __parse_groups(self):
for g in self.group_list:
name = g.get("name")
group = self.get_or_create_group(name)
# 添加Host到组
hosts = g.get("hosts", [])
for hostname in hosts:
host = self.get_host(hostname)
if not host:
continue
group.add_host(host)
# 添加Children到组
children = [
self.get_or_create_group(n) for n in g.get('children', [])
]
for child in children:
group.add_child_group(child)
# 组变量
for k, v in g.get("vars", {}).items():
group.set_variable(k, v)
示例2: _get_plugin_vars
# 需要导入模块: from ansible.inventory import host [as 别名]
# 或者: from ansible.inventory.host import Host [as 别名]
def _get_plugin_vars(self, plugin, path, entities):
from ansible.inventory.host import Host
data = {}
try:
data = plugin.get_vars(self.variable_manager._loader, path, entities)
except AttributeError:
for entity in entities:
if isinstance(entity, Host):
data.update(plugin.get_host_vars(entity.name))
else:
data.update(plugin.get_group_vars(entity.name))
return data
示例3: _convert_host_to_name
# 需要导入模块: from ansible.inventory import host [as 别名]
# 或者: from ansible.inventory.host import Host [as 别名]
def _convert_host_to_name(self, key):
if isinstance(key, (Host,)):
return key.get_name()
return key
示例4: add_dynamic_group
# 需要导入模块: from ansible.inventory import host [as 别名]
# 或者: from ansible.inventory.host import Host [as 别名]
def add_dynamic_group(self, hosts, groupname, groupvars=None):
"""
add hosts to a group
"""
self.inventory.add_group(groupname)
my_group = Group(name=groupname)
# if group variables exists, add them to group
if groupvars:
for key, value in groupvars.iteritems():
my_group.set_variable(key, value)
# add hosts to group
for host in hosts:
# set connection variables
hostname = host.get("hostname")
hostip = host.get('ip', hostname)
hostport = host.get("port")
username = host.get("username")
password = host.get("password")
ssh_key = host.get("ssh_key")
my_host = Host(name=hostname, port=hostport)
self.variable_manager.set_host_variable(host=my_host,varname='ansible_ssh_host',value=hostip)
self.variable_manager.set_host_variable(host=my_host,varname='ansible_ssh_pass',value=password)
self.variable_manager.set_host_variable(host=my_host,varname='ansible_ssh_port',value=hostport)
self.variable_manager.set_host_variable(host=my_host,varname='ansible_ssh_user',value=username)
self.variable_manager.set_host_variable(host=my_host,varname='ansible_ssh_private_key_file',value=ssh_key)
# my_host.set_variable('ansible_ssh_pass', password)
# my_host.set_variable('ansible_ssh_private_key_file', ssh_key)
# set other variables
for key, value in host.iteritems():
if key not in ["hostname", "port", "username", "password"]:
self.variable_manager.set_host_variable(host=my_host,varname=key,value=value)
# add to group
self.inventory.add_host(host=hostname,group=groupname,port=hostport)
ghost = Host(name="192.168.8.119")
示例5: my_add_group
# 需要导入模块: from ansible.inventory import host [as 别名]
# 或者: from ansible.inventory.host import Host [as 别名]
def my_add_group(self, hosts, groupname, groupvars=None):
"""
add hosts to a group
"""
my_group = Group(name=groupname)
# if group variables exists, add them to group
if groupvars:
for key, value in groupvars.iteritems():
my_group.set_variable(key, value)
# add hosts to group
for host in hosts:
# set connection variables
hostname = host.get("hostname")
hostip = host.get('ip', hostname)
hostport = host.get("port")
username = host.get("username")
password = host.get("password")
ssh_key = host.get("ssh_key")
my_host = Host(name=hostname, port=hostport)
my_host.set_variable('ansible_ssh_host', hostip)
my_host.set_variable('ansible_ssh_port', hostport)
my_host.set_variable('ansible_ssh_user', username)
my_host.set_variable('ansible_ssh_pass', password)
my_host.set_variable('ansible_ssh_private_key_file', ssh_key)
# set other variables
for key, value in host.iteritems():
if key not in ["hostname", "port", "username", "password"]:
my_host.set_variable(key, value)
# add to group
my_group.add_host(my_host)
self.inventory.add_group(my_group)