CN112711428B - Dynamic deployment method and system based on ANSIBLE - Google Patents

Dynamic deployment method and system based on ANSIBLE Download PDF

Info

Publication number
CN112711428B
CN112711428B CN202110060660.9A CN202110060660A CN112711428B CN 112711428 B CN112711428 B CN 112711428B CN 202110060660 A CN202110060660 A CN 202110060660A CN 112711428 B CN112711428 B CN 112711428B
Authority
CN
China
Prior art keywords
determining
parameters
playbook
deployment
vars
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110060660.9A
Other languages
Chinese (zh)
Other versions
CN112711428A (en
Inventor
赵美如
杨继伟
魏金雷
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Inspur Cloud Information Technology Co Ltd
Original Assignee
Inspur Cloud Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Inspur Cloud Information Technology Co Ltd filed Critical Inspur Cloud Information Technology Co Ltd
Priority to CN202110060660.9A priority Critical patent/CN112711428B/en
Publication of CN112711428A publication Critical patent/CN112711428A/en
Application granted granted Critical
Publication of CN112711428B publication Critical patent/CN112711428B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/61Installation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44505Configuring for program initiating, e.g. using registry, configuration files
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
    • G06F9/44526Plug-ins; Add-ons

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Computational Linguistics (AREA)
  • Stored Programmes (AREA)

Abstract

The invention discloses a dynamic deployment method and a system based on ANSIBLE, belonging to the field of automatic operation and maintenance; the method comprises the following specific steps: s1, determining a rabkitMQ configuration; s2, writing a receiver.py in a normal process of the machine to receive information; s3, calling up an execution method through cell packaging; s4, determining an Inventory according to the parameters transferred by the mq; s5, determining vars according to the parameters transferred by the mq; s6, executing a playbook to perform installation and deployment; s7, returning a result by rewriting execution of the callback custom stable; s8, sending a callback message to the mq; the invention dynamically determines the inventory by combining the mq parameter transmission mode with the database query, reduces the complexity and risk of manual maintenance, and can receive the execution condition in time by rewriting the callback method; the invention also realizes simultaneous multitasking based on celly, and increases the working efficiency.

Description

Dynamic deployment method and system based on ANSIBLE
Technical Field
The invention discloses a dynamic deployment method and system based on ANSIBLE, and relates to the technical field of automatic operation and maintenance.
Background
It is well known that anstable supports multi-node publishing and remote task execution. By default SSH is used for remote connection. The extension can be performed using various programming languages without installing additional software on the managed node. Meanwhile, the Anstable has the following characteristics:
the modular design is provided, and an Anstable can call a specific module to complete a specific task, and the modular design is a core component and is short and exquisite;
anstable is realized based on Python language, and is realized by three key modules of PyYAML and Jinja2 (templated) through Paramiko (one concurrency connection ssh host function library of Python);
the deployment of the Ancable is simple, and the agentless has no client tool;
operating in a master-slave mode;
supporting the function of a custom module;
supporting a playbook script, and completing continuous tasks according to a sequence;
each command is expected to have idempotent;
the existing manual database dynamic query method has the risks of complicated maintenance and data security, can only execute a single task of query, and has lower working efficiency, so the invention discloses a dynamic deployment method and system based on ANSIBLE, which aims to solve the problems.
Disclosure of Invention
Aiming at the problems in the prior art, the invention provides a dynamic deployment method and a system based on ANSIBLE, and the adopted technical scheme is as follows: a dynamic deployment method based on ANSIBLE comprises the following specific steps:
s1, determining a rabhitMQ configuration:
def getConnection():
credentials=pika.PlainCredentials('guest','guest')
connection=pika.BlockingConnection(
pika.ConnectionParameters(host='192.168.1.109',port=5672,virtual_host='/',credentials=credentials))
return connection
s2, writing a receiver. Py in the normal process of the machine to receive information:
def receive_sth():
print("receive_sth")
connection=getConnection()
channel=connection.channel()
channel.exchange_declare(exchange=exchange_name,exchange_type='topic',durable=False)
channel.queue_declare(queue_name_receivce)
channel.queue_bind(exchange=exchange_name,queue=queue_name_receivce,routing_key=routing_key_receive)
channel.basic_consume(queue=queue_name_receivce,on_message_callback=callback,auto_ack=True)
channel.start_consuming()
s3, calling an execution method of packaging through a cell:
def callback(ch,method,properties,body):
tasksA.runsth.delay(body)
s4, determining the identity according to the parameters transferred by the mq:
def getInventory(self,svc_id,instance_id):
dbhost='192.168.1.45'
dbport=3306
dbname='test'
dbuser='root'
password='root'
conn=MySQLdb.connect(host=dbhost,user=dbuser,passwd=password,db=dbname,charset='utf8',port=dbport)
cur=conn.cursor()
cur.execute("select code from group_component where id='"+id+"'")
s5, determining vars according to the parameters transferred by the mq;
s6, performing playbook to install and deploy:
def playbookrun(self,playbook_path):
context._init_global_context(self.ops)
print playbook_path
playbooks_path=[]
playbooks_path.append(playbook_path)
playbook=PlaybookExecutor(playbooks=playbooks_path,
inventory=self.inventory,variable_manager=self.variable_manager,
loader=self.loader,passwords=self.passwords)
s7, returning a result by rewriting the execution of the callback custom stable:
class ResultCallback(CallbackBase):
def__init__(self,*args,**kwargs):
#super(ResultsCollector,self).__init__(*args,**kwargs)
self.host_ok={}
self.host_unreachable={}
self.host_failed={}
def v2_runner_on_unreachable(self,result):
self.host_unreachable[result._host.get_name()]=result
def v2_runner_on_ok(self,result,*args,**kwargs):
self.host_ok[result._host.get_name()]=result
def v2_runner_on_failed(self,result,*args,**kwargs):
self.host_failed[result._host.get_name()]=result
s8, sending a callback message to the mq:
def send_sth(message):
connection=getConnection()
channel=connection.channel()
channel.exchange_declare(exchange=exchange_name,exchange_type='topic',durable=False)
channel.basic_publish(exchange=exchange_name,routing_key=routing_key_send,body=json.dumps(message))
print("[x]Sent%r:%r"%(routing_key_send,message))
connection.close()
s4, determining the Inventory according to the parameters transferred by the mq, and obtaining the information required in the corresponding allowable according to the parameters in the storage medium, wherein the specific steps comprise:
s401, querying components to be installed:
components=[]
for row in cur.fetchall():
components.append(row[0])
s402, circulating a component list, and inquiring ip corresponding to each component:
self.inventory.add_group('all')
for v in components:
sql="select a.ip from instance_vm_info a,("
sql=sql+"select code from group_node where component like'%"+v+"%'and id='"+id+"'"
sql=sql+")b where a.instance_id='"+instance_id+"'"
sql=sql+"and a.node_code=b.code"
cur.execute(sql)
self.inventory.add_group(v)
for row in cur.fetchall():
self.inventory.add_host(row[0],v)
self.inventory.add_host(row[0],'all')
the specific step of determining vars according to the parameters transferred by the mq in S5 comprises the following steps:
s501, acquiring corresponding vars to form extra-vars in a storage medium;
s502 query parameters are passed to the onsible execution use:
cur.execute("select col_code from group_table_column where id='"+id+"'")
extra_vars={}
cols=[]
for row in cur.fetchall():
cols.append(row[0])
cur.execute("select`table_name`from group where id='"+id+"'")
data=cur.fetchone()
""
s=,
cols_str=s.join(cols)
table_name=data[0]
sql="select"+cols_str+"from"+table_name+"where instance_id='"+instance_id+"'"
cur.execute(sql)
data=cur.fetchone()
no=0
print json.dumps(data)
for k in cols:
extra_vars[k]=data[no]
no=no+1
cur.close()
self.variable_manager._extra_vars=extra_vars
the S6 executes the playbook and calls an allowable playbook command to execute the already arranged steps for installing the deployment.
A dynamic deployment system based on ANSIBLE specifically comprises a mode determination module, an information receiving module, a task starting module, a parameter determination module A, a parameter determination module B, a deployment installation module, an analysis receipt module and an analysis feedback module:
a mode determining module: determining a rabkitmq configuration;
an information receiving module: writing a receive. Py in the normal process of the machine to receive information;
the task starting module: calling up an execution method through cell packaging;
parameter determination module a: determining an Inventory according to the parameters transferred by the mq;
parameter determination module B: determining vars according to the parameters transferred by the mq;
deploying an installation module: executing a playbook for installation and deployment;
and (5) an analysis receipt module: returning a result by rewriting the execution of the callback custom stable;
and an analysis feedback module: and sending a callback message to the mq.
The parameter determining module A determines the Inventory according to the parameters transferred by the mq, and obtains the information required in the corresponding allowable according to the parameters, wherein the parameter determining module A specifically comprises a component query module and an ip query module:
component query module: querying components to be installed;
ip query module: and circulating the component list, and inquiring the ip corresponding to each component.
The parameter determining module B specifically comprises a parameter combining module and a parameter using module:
parameter combination module: acquiring corresponding vars from a storage medium to form extra-vars;
parameter use module: the query parameters are passed to the allowable execution use.
The deployment installation module executes the playbook and invokes the allowable playbook command to execute the already orchestrated steps for installing the deployment.
The beneficial effects of the invention are as follows: the invention dynamically determines the inventory by combining the mq parameter transmission mode with the database query, reduces the complexity and risk of manual maintenance, and can receive the execution condition in time by rewriting the callback method; the invention also realizes simultaneous multitasking based on celly, and increases the working efficiency.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions of the prior art, the drawings that are needed in the embodiments or the description of the prior art will be briefly described below, it will be obvious that the drawings in the following description are some embodiments of the present invention, and that other drawings can be obtained according to these drawings without inventive effort to a person skilled in the art.
FIG. 1 is a flow chart of the method of the present invention; fig. 2 is a schematic diagram of the system of the present invention.
Detailed Description
The present invention will be further described with reference to the accompanying drawings and specific examples, which are not intended to be limiting, so that those skilled in the art will better understand the invention and practice it.
First, key terms and abbreviations involved in the present invention are explained:
ANSIBLE is a newly-emerging automatic operation and maintenance tool, and based on Python development, realizes functions such as batch system configuration, batch program deployment, batch operation command and the like
Python: programming language
Playbook: minimum execution unit of an ansable
Inventory: host inventory of an onstable
Vars: variable of an ansable
Celery: dynamic parallel framework based on python
Embodiment one:
a dynamic deployment method based on ANSIBLE comprises the following specific steps:
s1, determining a rabkitMQ configuration;
s2, writing a receiver.py in a normal process of the machine to receive information;
s3, calling up an execution method through cell packaging;
s4, determining an Inventory according to the parameters transferred by the mq;
s5, determining vars according to the parameters transferred by the mq;
s6, executing a playbook to perform installation and deployment;
s7, returning a result by rewriting execution of the callback custom stable;
s8, sending a callback message to the mq;
the invention provides a dynamic deployment method based on ANSIBLE, which adopts a rabitMQ as a middleware to realize dynamic parameter transmission, develops based on Python language, adopts an analog plug-in to realize callback, adopts a cell as a concurrence tool, firstly determines the configuration of the rabitMQ according to S1, determines the topic mode of the rabitMQ, determines key information such as routing-key, exchange and the like, and then writes a receive.py file according to S2, wherein the file is used for starting a normal formation in a machine and is used for receiving information sent from various places differently;
based on the self distributed execution function of the cell, calling an execution method through the cell package according to S3, starting a task in a multi-process mode, determining the content according to the parameters transmitted by the mq according to S4, determining vars according to the eucalyptus transmitted by the mq according to S5, and executing the playbook according to S6 for installation and deployment;
the step of rewriting the callbacks according to S7 is mainly to use the execution return result of the custom analysis so as to analyze the callbacks in a highly personalized way and return the execution result to the user, and finally, the analyzed information is returned to the user by sending the callback information to mq according to S8, and the user analyzes the analyzed information according to the custom rule so as to give different feedback to the user;
further, the step S4 of determining the identity according to the parameter transferred by the mq, and obtaining the information required in the corresponding stable from the storage medium according to the parameter, which specifically includes the steps of:
s401, inquiring components to be installed;
s402, circulating a component list, and inquiring an ip corresponding to each component;
s4, determining the Inventory according to the parameters transferred by the mq. According to the transferred parameters, obtaining information such as usernames, passwords, ports, IP, hostnames and the like required in corresponding analog in a certain storage medium, wherein the postgress is used in the invention;
further, the specific step of determining vars according to the parameter transferred by the mq in S5 includes:
s501, acquiring corresponding vars to form extra-vars in a storage medium;
s502, the query parameters are transmitted to an onsible for execution and use;
still further, the S6 executes a playbook, and invokes an allowable playbook command to execute the already-programmed steps for installing the deployment.
Embodiment two:
a dynamic deployment system based on ANSIBLE specifically comprises a mode determination module, an information receiving module, a task starting module, a parameter determination module A, a parameter determination module B, a deployment installation module, an analysis receipt module and an analysis feedback module:
a mode determining module: determining a rabkitmq configuration;
an information receiving module: writing a receive. Py in the normal process of the machine to receive information;
the task starting module: calling up an execution method through cell packaging;
parameter determination module a: determining an Inventory according to the parameters transferred by the mq;
parameter determination module B: determining vars according to the parameters transferred by the mq;
deploying an installation module: executing a playbook for installation and deployment;
and (5) an analysis receipt module: returning a result by rewriting the execution of the callback custom stable;
and an analysis feedback module: sending a callback message to the mq;
the invention provides a dynamic deployment system based on ANSIBLE, which adopts a rabitMQ as a middleware to realize dynamic parameter transmission, develops based on Python language, adopts an analog plug-in to realize callback, adopts a cell as a concurrence tool, firstly determines the configuration of the rabitMQ through a mode determining module, determines the key information such as routing-key, exchange and the like by using the topic mode of the rabitMQ, and then writes a receiving.py file through an information receiving module, wherein the file is used for starting a normal formation in a machine and is used for receiving information sent from various places differently;
based on the self distributed execution function of the cell, a task starting module is used for calling an execution method through cell packaging, a task is started in a multi-process mode, then a parameter determining module A determines the content according to the parameters transmitted by the mq, a parameter determining module B determines vars according to the eucalyptus transmitted by the mq, and a deployment and installation module is used for executing a playbook to carry out installation and deployment;
the step of rewriting the callbacks by the analysis receipt module mainly uses the execution return result of the custom to enable highly personalized analysis and return to the user execution result, and finally sends a callback message to mq through the analysis feedback module, returns the analyzed message to the user, and the user analyzes the analyzed message according to the custom rule to give different feedback to the user;
further, the parameter determining module a determines the identity according to the parameter transferred by the mq, and obtains the information required in the corresponding allowable according to the parameter, where the parameter determining module a specifically includes a component query module and an ip query module:
component query module: querying components to be installed;
ip query module: and circulating the component list, and inquiring the ip corresponding to each component.
Further, the parameter determining module B specifically includes a parameter combining module and a parameter using module:
parameter combination module: acquiring corresponding vars from a storage medium to form extra-vars;
parameter use module: the query parameters are transmitted to an onsible for execution;
still further, the deployment installation module executes a playbook, calls an allowable playbook command to execute the already orchestrated steps for installing the deployment.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present invention, and are not limiting; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims (3)

1. A dynamic deployment method based on ANSIBLE is characterized by comprising the following specific steps:
s1, determining a rabkitMQ configuration;
s2, writing a receiver.py in a normal process of the machine to receive information;
s3, calling up an execution method through cell packaging;
s4, determining the Inventory according to the parameters transferred by the mq, further, the S4 determines the Inventory according to the parameters transferred by the mq, and obtaining the information required in the corresponding stable according to the parameters in the storage medium, wherein the specific steps comprise:
s401, inquiring components to be installed;
s402, circulating a component list, and inquiring an ip corresponding to each component;
s4, determining an entry according to the parameters transferred by the mq; according to the transferred parameters, obtaining information such as usernames, passwords, ports, IP, hostnames and the like required in corresponding analog in a certain storage medium, wherein the postgress is used in the invention;
s5, determining vars according to the parameters transferred by the mq, wherein the specific steps of determining vars according to the parameters transferred by the mq in S5 comprise:
s501, acquiring corresponding vars to form extra-vars in a storage medium;
s502, the query parameters are transmitted to an onsible for execution and use;
still further, the S6 executes a playbook, and calls an allowable playbook command to execute the already arranged steps for installing the deployment;
s6, executing a playbook to perform installation and deployment;
s7, returning a result by rewriting execution of the callback custom stable;
s8 sends a callback message to mq.
2. The method of claim 1, wherein S6 executes a playbook, calls an allowable playbook command to execute the already orchestrated steps for installing the deployment.
3. A ANSIBLE-based dynamic deployment system characterized in that said system uses the method of claim 1.
CN202110060660.9A 2021-01-18 2021-01-18 Dynamic deployment method and system based on ANSIBLE Active CN112711428B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110060660.9A CN112711428B (en) 2021-01-18 2021-01-18 Dynamic deployment method and system based on ANSIBLE

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110060660.9A CN112711428B (en) 2021-01-18 2021-01-18 Dynamic deployment method and system based on ANSIBLE

Publications (2)

Publication Number Publication Date
CN112711428A CN112711428A (en) 2021-04-27
CN112711428B true CN112711428B (en) 2024-04-12

Family

ID=75549230

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110060660.9A Active CN112711428B (en) 2021-01-18 2021-01-18 Dynamic deployment method and system based on ANSIBLE

Country Status (1)

Country Link
CN (1) CN112711428B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2017202211A1 (en) * 2016-05-26 2017-11-30 中兴通讯股份有限公司 Method and device for installing service version on virtual machine
CN109213496A (en) * 2018-08-29 2019-01-15 郑州云海信息技术有限公司 A kind of realization method and system for disposing OpenStack
CN110460670A (en) * 2019-08-19 2019-11-15 浪潮云信息技术有限公司 A kind of application cluster framework Automation arranging method based on Terraform and Ansible

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2017202211A1 (en) * 2016-05-26 2017-11-30 中兴通讯股份有限公司 Method and device for installing service version on virtual machine
CN109213496A (en) * 2018-08-29 2019-01-15 郑州云海信息技术有限公司 A kind of realization method and system for disposing OpenStack
CN110460670A (en) * 2019-08-19 2019-11-15 浪潮云信息技术有限公司 A kind of application cluster framework Automation arranging method based on Terraform and Ansible

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
企业自动化运维管理系统的设计与实现;赵彪;张美娜;刘天奇;王楠;;电脑知识与技术(23);全文 *
基于Ansible和Flume的海量数据自动化采集系统;赵创业;唐亮亮;郭威;王哲;黄晓波;;电子设计工程(03);全文 *

Also Published As

Publication number Publication date
CN112711428A (en) 2021-04-27

Similar Documents

Publication Publication Date Title
CN112988499B (en) Data processing method and device, electronic equipment and storage medium
CN108737168B (en) Container-based micro-service architecture application automatic construction method
US8196105B2 (en) Test framework for automating multi-step and multi-machine electronic calendaring application test cases
US20140372970A1 (en) Method to auto generate jax-rs rest service implementation classes from existing interfaces
CN109284184A (en) A kind of building method of the distributed machines learning platform based on containerization technique
JPH03504173A (en) Workstations and data processing networks containing workstations
US11503109B2 (en) Processing an operation with a plurality of processing steps
WO2002019102A1 (en) Web server framework
CN111625585B (en) Access method, device, host and storage medium of hardware acceleration database
CN102664952B (en) Method for managing and monitoring embedded equipment cluster
CN112328470A (en) Automatic operation and maintenance testing method, device, equipment and storage medium
CN108415689A (en) Software sharing method based on the assembly of ubiquitous object three-stage
CN110888800A (en) Service interaction function test method, device, storage medium and test system
CN112711428B (en) Dynamic deployment method and system based on ANSIBLE
CN107896242B (en) Service sharing method and device
US6971108B1 (en) Computer software framework and method for managing communication flow between a user interface and a computer application
CN113672493A (en) Service function testing method and device, testing platform and readable storage medium
CN117194064A (en) Remote calling method and device
US8381278B2 (en) Method and apparatus for establishing security inflow contracts
CN114816357A (en) Service arrangement system for serving process bank
CN109669871B (en) Method for realizing Oracle Form automatic test
Liu et al. Analysis of web services composition and substitution via CCS
KR20210042407A (en) Application interface implementation method, device, equipment and media in the host platform layer
US9276999B2 (en) System and method for providing a service
CN111158794A (en) OpenStack-oriented API (application program interface) combination optimization method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant