iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >ansible + tornado + MongoDB
  • 678
分享到

ansible + tornado + MongoDB

2024-04-02 19:04:59 678人浏览 独家记忆
摘要

Http://blog.csdn.net/smallfish2983/article/details/38078019照着上面那哥们写的,初学,不要吐血,基本功能实现了。root@ubuntu12:~/an

Http://blog.csdn.net/smallfish2983/article/details/38078019


照着上面那哥们写的,初学,不要吐血,基本功能实现了。


ansible + tornado + MongoDB

ansible + tornado + MongoDB

ansible + tornado + MongoDB



root@ubuntu12:~/ansible/tornado# tree
.
├── templates
│   ├── index.html
│   └── result.html
└── test.py


root@ubuntu12:~/ansible/tornado# cat test.py

#coding:utf-8  

import os.path
import tornado.locale
import tornado.httpserver
import tornado.ioloop  
import tornado.options  
import tornado.WEB  
from tornado.options import define, options  
import pymonGo  


define("port", default=8000, help="run on the given port", type=int)  

class Application(tornado.web.Application):  
    def __init__(self):  
        #初始化一些东西  
        handlers = [  
            #url匹配  
            (r"/", MainHandler),  
            (r"/index", MainHandler),   
            (r"/result", Module_actionHandler),  
 
        ]  
        settings = dict(  
            #程序设置,字典形式  
            template_path=os.path.join(os.path.dirname(__file__), "templates"),  
            #设置模板文件路径  
            static_path=os.path.join(os.path.dirname(__file__), "static"),  
            #设置静态文件路径,如CSS\jpg\gif等  
            # ui_modules={"Book": BookModule},  
            #设置ui模块,可以用字典添加多个  
            debug=True,  
        )  

        tornado.web.Application.__init__(self, handlers, **settings)  
        #传入设置配置  

class MainHandler(tornado.web.RequestHandler):  
    #主页函数方法  
    def get(self):  
        #设置get方法函数  
        self.render(  
            "index.html",  
        )  

class Module_actionHandler(tornado.web.RequestHandler):  
    #定义模块操作函数方法  
       
 
    def post(self, *args, **kwargs): 

        pattern = self.get_arguments('pattern')[0]  
        #获取主机名  
        module_name = self.get_arguments('module_name')[0]  
        #获取模块名  
        module_args = self.get_arguments('module_args')[0]  
        #获取参数  
        
        import ansible.runner  
        runner = ansible.runner.Runner(  
            #根据ansible的api来运行脚本  
            module_name = module_name,  
            module_args = module_args, 
            pattern = pattern, 
        )  
        result = runner.run()  
    
        conn = pymongo.Connection("localhost", 27017)
        db = conn["ansible"]
        if type(result) == dict:
           db.ansible.insert(result)       
     
 
        def pars_result(result):  
            # 定义一个判断结果的函数  
            if len(result['dark'])>0:  
                # dark返回不为空则表示操作失败了  
                return result['dark'],'失败!'  
            else:  
                return result['contacted'],'成功!'  
        result = pars_result(result)  

        self.render(  
            "result.html", 
            message = result[0],  
            result = result[1]  
        )  

if __name__ == "__main__":  
    tornado.options.parse_command_line()  
    http_server = tornado.httpserver.HTTPServer(Application())  
    http_server.listen(options.port)  
    tornado.ioloop.IOLoop.instance().start() 


# cat index.html

<!DOCTYPE html>
<html>
    <head><title>ansible </title></head>
    <body>
        <h2>Enter arg bellow:</h2>
        <fORM method="post" action="/result">
        <p>pattern<br><input type="text" name="pattern"></p>
        <p>module_name<br><input type="text" name="module_name"></p>
        <p>module_args<br><input type="text" name="module_args"></p>
        <input type="submit">
        </form>
    </body>
</html>

# cat result.html

<!DOCTYPE html>
<html>
    <head><title>ansible result</title></head>
    <body>
        <h2>ansible result</h2>
                <p> message: `message` </p>
                <p> result: `result` </p>
    </body>
</html>

附件:http://down.51cto.com/data/2364907
您可能感兴趣的文档:

--结束END--

本文标题: ansible + tornado + MongoDB

本文链接: https://www.lsjlt.com/news/41931.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • ansible + tornado + MongoDB
    http://blog.csdn.net/smallfish2983/article/details/38078019照着上面那哥们写的,初学,不要吐血,基本功能实现了。root@ubuntu12:~/an...
    99+
    2022-10-18
  • ansible runner把结果写入MongoDB
    http://rfyiamcool.blog.51cto.com/1030776/1440624 http://rfyiamcool.blog.51cto.com/1030776/1422263 root@...
    99+
    2022-10-18
  • python-tornado
     《introduction-to-tornado》笔记http://docs.pythontab.com/tornado/introduction-to-tornado/index.html 一、安装tornado $curl -L -O...
    99+
    2023-01-31
    python tornado
  • tornado SSL3_READ_BY
    //////////// 支付宝回调,遇到问题//////WARNING:tornado.general:SSL Error on 9 ('110.75.248.125', 13675): [Errno 1] _ssl.c:504: err...
    99+
    2023-01-31
    tornado SSL3_READ_BY
  • Python Tornado
    一、先安装 pip3 install tornado 二、小试牛刀 from tornado.web import Application from tornado.web import RequestHandler from torna...
    99+
    2023-01-31
    Python Tornado
  • Tornado进阶
    三、Tornado进阶 3.1 Application settings debug,设置tornado是否工作在调试模式,默认为False即工作在生产模式。当设置debug=True 后,tornado会工作在调试/开发模式,在此种模式...
    99+
    2023-01-31
    进阶 Tornado
  • 初识Tornado
    引言 回想Django的部署方式 以Django为代表的python web应用部署时采用wsgi协议与服务器对接(被服务器托管),而这类服务器通常都是基于多线程的,也就是说每一个网络请求服务器都会有一个对应的线程来用web应用(如Dja...
    99+
    2023-01-31
    Tornado
  • ansible
    用ansible在客户端上创建一个用户,用户名为test,脚本语言如下:[root@master ansible]# vim 1.yml  --- - name: create_user               /说明代码的作用。可以...
    99+
    2023-01-31
    ansible
  • python安装Tornado
    1.通过pip进行安装 命令:pip install tornado 截图:2.验证安装是否成功 示例代码: #!/usr/bin/python import tornado.ioloop import tornado.web   clas...
    99+
    2023-01-31
    python Tornado
  • Tornado集成Apscheduler
    熟悉Python的人可能都知道,Apscheduler是python里面一款非常优秀的任务调度框架,这个框架是从鼎鼎大名的Quartz移植而来。 之前有用过Flask版本的Apscheduler做定时任务。刚好前不久接触了Tornado,...
    99+
    2023-01-31
    Tornado Apscheduler
  • python3.2安装tornado
    1、下载tornado:wget https://pypi.python.org/packages/source/t/tornado/tornado-3.1.tar.gz --no-check-certificate2、编译安装tornad...
    99+
    2023-01-31
    tornado
  • ansible--roles
    role类似于salt-stack里面的state,state有一定的组织架构。而role则是ansible中playbook的目录组织架构,如果把所有内容都写到playbooks里,可能会导致playbo...
    99+
    2022-10-18
  • tornado学习笔记
    一.UIMOTHODS: 1.在项目目录创建uimothods.py文件(名称可以任意)内容: def test2(self): return ('hello uimothods')2.tornado项目文件中导入并注册: #导入f...
    99+
    2023-01-30
    学习笔记 tornado
  • Tornado异步模式
    先介绍下背景:由于工作需要,前段时间又写了一段爬虫去获取和更新一些数据。之前爬虫主要用Scrapy框架批量爬取一些页面数据,或者用Gevent调用目标站点的接口。偶然看到了Tornado,听说这个框架很强大,所以打算这次爬虫用Tornad...
    99+
    2023-01-31
    模式 Tornado
  • Python Web框架Tornado
    Python Web框架Tornado的异步处理代码示例Tornado是一个轻量级但高性能的Python web框架,与另一个流行的Python web框架Django相比,tornado不提供操作数据库的ORM接口及严格的MVC开发模式,...
    99+
    2023-01-31
    框架 Python Web
  • python Tornado框架 入
    Tornado介绍 Tornado 是一个Python web框架和异步网络库 起初由 FriendFeed 开发. 通过使用非阻塞网络I/O, Tornado 可以支持上万级的连接,处理 长连接, WebSockets, 和其他...
    99+
    2023-01-31
    框架 python Tornado
  • ansible (2.4.2.0) A
    转自 jumpserver 5.0 测试版本 下载地址 https://github.com/hequan2017/zabbix-models/tree/master/ansible_run 只是简单改了一下 能够单独使用。 目录结构 a...
    99+
    2023-01-31
    ansible
  • ansible--基础
    马哥出品 ansible中文文档:http://www.ansible.com.cn/index.htmlansible介绍:ansible是个什么东西呢?官方的title是“Ansible is Simp...
    99+
    2022-10-18
  • ansible--变量
    ansible中的变量主要来源于以下几种场景:Inventory(host vars,group vars)playbook里面命令行playbook执行task过程中产生结果,可以register起来,作...
    99+
    2022-10-18
  • tornado handler 方法复用
    特性 在一次 tornado 请求中调用其他 tornado handler 中的方法, 比如 run 方法 引言 在后台开发中, 有时需要做一些功能的整合, 比如请求1,2,3 各自完成一项功能, 而现在有需求, 需要一次请求完成这三...
    99+
    2023-01-30
    复用 方法 tornado
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作