当前位置: 首页>>代码示例>>Python>>正文


Python host.Host方法代码示例

本文整理汇总了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) 
开发者ID:KubeOperator,项目名称:KubeOperator,代码行数:22,代码来源:inventory.py

示例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 
开发者ID:willthames,项目名称:ansible-inventory-grapher,代码行数:14,代码来源:inventory.py

示例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 
开发者ID:AlanCoding,项目名称:Ansible-inventory-file-examples,代码行数:6,代码来源:steve.py

示例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") 
开发者ID:iopsgroup,项目名称:imoocc,代码行数:43,代码来源:ansible_api.py

示例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) 
开发者ID:zsjtoby,项目名称:DevOpsCloud,代码行数:37,代码来源:ansible_api.py


注:本文中的ansible.inventory.host.Host方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。