zoukankan      html  css  js  c++  java
  • 开发动态的Inventory数据源

    开发动态的Inventory数据源:
    
    # !/usr/bin/env python
    # -*- coding: utf-8 -*-
    import json
    a={
        "all": [
            "192.168.1.6",
            "192.168.1.10"
        ]
    }
    print a
    print type(a)
    print a['all']
    print type(a['all'])
    b=json.dumps(a)
    print b
    print type(b)
    
    
    C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/Django/a20.py
    {'all': ['192.168.1.6', '192.168.1.10']}
    <type 'dict'>
    ['192.168.1.6', '192.168.1.10']
    <type 'list'>
    {"all": ["192.168.1.6", "192.168.1.10"]}
    <type 'str'>
    
    
    测试:
    [root@node01 ~]# cat /etc/ansible/inventory.py 
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    import json
    a={
        "all": [
            "192.168.137.3"
        ]
    }
    b=json.dumps(a)
    print b
    
    
    [root@node01 ~]# python -i /etc/ansible/inventory.py --list
    {"all": ["192.168.137.3"]}
    >>> exit()
    
    [root@node01 ~]# python  /etc/ansible/inventory.py  --list
    {"all": ["192.168.137.3"]}
    [root@node01 ~]# python  /etc/ansible/inventory.py  --hosts
    {"all": ["192.168.137.3"]}
    
    
    [root@node01 ~]# ansible -i  /etc/ansible/inventory.py all -m raw -a "hostname"
    192.168.137.3 | SUCCESS | rc=0 >>
    node2
    Shared connection to 192.168.137.3 closed.
    

  • 相关阅读:
    跨域问题
    window7_64+python3.6安装Twisted
    resful协议1
    Http状态码
    数据库学习笔记
    linux学习笔记
    前端学习笔记
    python学习笔记
    mongoDB
    git的使用方法
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349491.html
Copyright © 2011-2022 走看看