zoukankan      html  css  js  c++  java
  • 生成ansible-playbook的yaml文件的代码(字典排序问题无法解决)

    import yaml
    import collections
    
    def add_task():
        return None
    
    
    def add_vars():
        return None
    
    
    def add_handles():
        return None
    
    
    def add_project(name=None,gather_facts=False,hosts=None,remote_user=None,
                    tasks=None,handlers=None,varstrings=None):
        aproject = collections.OrderedDict()
        aproject['name']=name
        aproject['hosts'] = hosts
        aproject['gather_facts'] = gather_facts
        aproject['remote_user'] = remote_user
        aproject['tasks'] = tasks
        aproject['handlers'] = handlers
        aproject['vars'] = varstrings
    
        for k,v in aproject.items():
            if v is None:
                aproject.pop(k)
    
        print aproject
        bprojects={}
        for key in aproject:
            print {key: aproject[key]}
    
        print bprojects
        f = open('test.yaml', 'w')
        result = yaml.dump(aproject, f, default_flow_style=False, allow_unicode=True)
        print result
    
    if __name__=='__main__':
        tasks=add_task()
        handlers=add_handles()
        varstrings=add_vars()
        add_project(name='Silenthand Olleander',gather_facts=False,hosts=None,remote_user=None,
                    tasks=tasks,handlers=handlers,varstrings=varstrings)
  • 相关阅读:
    织梦网站底部的Power by DedeCms怎么去掉?
    在线文档预览
    Hyper-v网络配置
    office web apps部署(二)
    iOS 学习资料整理
    office web apps部署(一)
    cdr格式文件抠图
    iframe载入等待
    Vcl.FileCtrl.SelectDirectory
    Function Pointer in Delpni
  • 原文地址:https://www.cnblogs.com/slqt/p/6605151.html
Copyright © 2011-2022 走看看