Ansible-based automatic operation and maintenance method, server, computer equipment and storage medium
Ansible's automated operations and maintenance methods solve the problem of low reliability in traditional operations and maintenance methods, enabling unified management and configuration of each client, and improving operations and maintenance efficiency and reliability.
Patent Information
- Application Number
- CN202511012812.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-22
- Publication Date
- 2025-10-28
AI Technical Summary
In current mobile IT system operation and maintenance, traditional operation and maintenance methods have low reliability, require a lot of manual intervention, are prone to human error, and make it difficult to guarantee maintenance reliability.
By adopting the Ansible automated operation and maintenance method, and by configuring the ansible.cfg file, hosts file, and userconfig.yaml file, and writing the linux.yaml script file, unified management and configuration of each client can be achieved, including the distribution of automated tools, configuration file replacement and control.
It improves the efficiency and reliability of operation and maintenance, reduces human error, and enables unified management and configuration of each client.
Smart Images

Figure CN120856552A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of Ansible-based automated operation and maintenance technology, specifically to an Ansible-based automated operation and maintenance method, server, computer equipment, and storage medium. Background Art
[0002] With the increasing number of machines being maintained in mobile IT systems, current maintenance practices largely remain at the traditional level. Traditional maintenance primarily relies on manually executing shell commands or scripts, and scheduling is achieved manually or through cron jobs. These traditional methods suffer from low reliability, and with significant human intervention, human error is easily overlooked, compromising maintenance reliability. Summary of the Invention
[0003] The purpose of this disclosure is to overcome the shortcomings of the prior art and provide an Ansible-based automated operation and maintenance method, as well as a server, computer equipment, and storage media. This Ansible-based automated operation and maintenance method enables unified management and configuration of each client on the server.
[0004] According to a first aspect of the present disclosure, an Ansible-based automated operation and maintenance method is provided, which includes the following steps:
[0005] Configure the ansible.cfg file;
[0006] Configure a hosts file, which contains information about the controlled host; the information about the controlled host includes its IP address, SSH login username and password, and root user password.
[0007] Configure the userconfig.yaml file, which contains information about the controlled host running the automated disconnection tool to access the server;
[0008] Write a linux.yaml script file, which is used to configure, deploy, and manage the scripts of the controlled node.
[0009] In one embodiment, writing the linux.yaml script file includes:
[0010] The automation tools are distributed from the Ansible server to each of the controlled hosts;
[0011] Replace the configuration file in the automation tool for each controlled host according to the configuration in the userconfig.yaml file;
[0012] Control each of the controlled hosts to run the automated tool after replacing the configuration file.
[0013] In one embodiment, the method further includes:
[0014] Remove the software and automation tool packages installed on each of the aforementioned clients.
[0015] In one embodiment, the configuration ansible.cfg file includes:
[0016] Configure the host_key_checking and forks variables; the host_key_checking variable is used to determine whether to perform public key checks on the controlled host, and the forks variable is used to determine the number of Ansible concurrent threads.
[0017] In one embodiment, the information accessed by the controlled host to the server using the automated disconnection tool includes: the server's IP address, the server's operating system type, the username and password for logging into the server, and the number of times the controlled host attempts to connect to the server.
[0018] According to a second aspect of the present disclosure, a server is provided, the server comprising: a first configuration module, a second configuration module, a third configuration module, and a writing module; wherein,
[0019] The first configuration module is used to configure the ansible.cfg file;
[0020] The second configuration module is used to configure the hosts file, which contains information about the controlled host; wherein, the information about the controlled host includes the IP address, the username and password for SSH login, and the password for the root user;
[0021] The third configuration module is used to configure the userconfig.yaml file, which contains information about the controlled host running an automated disconnection tool to access the server.
[0022] The writing module is used to write linux.yaml script files, which are used to configure, deploy, and manage the scripts of the controlled nodes.
[0023] In one embodiment, the writing module specifically includes: a distribution submodule, a replacement submodule, and a control submodule; wherein,
[0024] The distribution submodule is used to distribute automation tools from the Ansible server to each of the controlled hosts;
[0025] The replacement submodule is used to replace the configuration file in the automation tool of each controlled host according to the configuration in the userconfig.yaml file;
[0026] The control submodule is used to control each controlled host to run the automation tool after the configuration file is replaced.
[0027] In one embodiment, the server further includes: a deletion module; wherein,
[0028] The deletion module is used to delete the software and automation tool packages installed on each of the clients.
[0029] According to a third aspect of the present disclosure, a computer device is provided, comprising: a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of any of the above methods.
[0030] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided having a computer program stored thereon, characterized in that the computer program, when executed by a processor, implements the steps of the method as described in any of the above.
[0031] This disclosure provides an Ansible-based automated operation and maintenance method that enables unified management and configuration of each client on the server, thereby improving the efficiency and reliability of operation and maintenance. Attached Figure Description
[0032] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.
[0033] Figure 1 This is a schematic diagram illustrating the working principle and process of Ansible in the embodiments of this disclosure.
[0034] Figure 2 This is a flowchart of an Ansible-based automated operation and maintenance method provided in an embodiment of this disclosure. Figure 3 This is an architecture diagram of a server provided in an embodiment of the present disclosure.
[0035] Figure 4 This is an architecture diagram of a server provided in an embodiment of the present disclosure.
[0036] Figure 5 This is an architecture diagram of a server provided in an embodiment of the present disclosure.
[0037] Figure 6 This is an architectural diagram of a computer device provided in an embodiment of the present disclosure. Detailed Implementation
[0038] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0039] Ansible, a powerful automation tool for system administration, continues to attract new users and maintain an active user base due to its concise configuration syntax, YAML-based agentless architecture, and widely praised ease of use. Its features include:
[0040] 1. Easy to learn: Ansible has a relatively gentle learning curve, and beginners can quickly master basic configuration management and automated deployment skills.
[0041] 2. Wide range of applications: Ansible can be used for everything from basic configuration management to complex multi-tier application deployments, cloud infrastructure automation, and even the configuration of network and security devices.
[0042] 3. Powerful integration capabilities: Ansible Tower offers more advanced features, such as access control, task scheduling, and graphical interfaces, making it suitable for enterprise-level needs.
[0043] 4. Community and Ecosystem: Ansible has an active community with a wealth of modules and roles available for direct use, which accelerates the development and deployment process.
[0044] 5. Cross-platform: Supports multiple operating systems and cloud environments, making Ansible an important choice for the automated management of heterogeneous environments.
[0045] Figure 1 This is a schematic diagram illustrating the working principle and process of Ansible in an embodiment of this disclosure. Figure 1 As shown, the process includes the following steps:
[0046] The first step is to load your own configuration file, which is / etc / ansible / ansible.cfg by default;
[0047] The first step is to locate the configuration file for the corresponding host, specifically the / etc / ansible / hosts file for the host or group to be executed.
[0048] The second step is to load the corresponding module files, such as command, yum, and ping.
[0049] The third step is to use Ansible to generate a temporary .py file (similar to a Python script) for the module commands and then transfer that file to the managed device.
[0050] Step 4: Transfer the file to the home directory of the corresponding user on the controlled device: .ansible / tmp / xxx / xxx.py;
[0051] Step 5: The controlled end adds execute permissions to the transmitted .py file;
[0052] Step 6: Execute and return the result. After execution, delete the .py file and exit with sleep 0.
[0053] It's important to note that a Playbook is a script used by Ansible to configure, deploy, and manage controlled nodes. By executing a series of tasks within a playbook's detailed description, a remote host can be brought to the desired state.
[0054] Figure 2 This is a flowchart illustrating an Ansible-based automated operation and maintenance method provided as an embodiment of this disclosure. Figure 2 As shown, this method is applied to a server and includes:
[0055] Step 201: Configure the ansible.cfg file;
[0056] In one embodiment, the configuration ansible.cfg file includes:
[0057] Configure the host_key_checking and forks variables; the host_key_checking variable is used to determine whether to perform public key checks on the controlled host, and the forks variable is used to determine the number of Ansible concurrent threads.
[0058] In this step, the ansible.cfg file is configured, mainly by configuring the two variables host_key_checking and forks. host_key_checking is used to determine whether to perform public key checks on remote hosts, and forks is used to determine the number of concurrent threads in ansible.
[0059] Step 202: Configure the hosts file, which contains information about the controlled host; the information about the controlled host includes the IP address, SSH login username and password, and root user password.
[0060] In this step, the hosts file is configured. This file records information about the controlled host (client), including its IP address, SSH login username and password, and root user password.
[0061] Step 203: Configure the userconfig.yaml file, which contains information about the controlled host running the automated disconnection tool to access the server;
[0062] In one embodiment, the information accessed by the controlled host to the server using the automated disconnection tool includes: the server's IP address, the server's operating system type, the username and password for logging into the server, and the number of times the controlled host attempts to connect to the server.
[0063] In this step, the userconfig.yaml file is configured. This file records information about the client's access to the server when running the automated disconnection tool, including the server's IP address, operating system type, username and password for logging into the server, and the number of times the client attempts to connect to the server. All of these are configurable.
[0064] Step 204: Write the linux.yaml script file, which is used to configure, deploy and manage the scripts of the controlled node.
[0065] In one embodiment, writing the linux.yaml script file includes:
[0066] The automation tools are distributed from the Ansible server to each of the controlled hosts;
[0067] Replace the configuration file in the automation tool for each controlled host according to the configuration in the userconfig.yaml file;
[0068] Control each of the controlled hosts to run the automated tool after replacing the configuration file.
[0069] In this step, the automation tool is first copied from the Ansible server to each client. Next, the configuration file in each client's automation tool is replaced according to the configuration in the user's userconfig.yaml file (each client connects to a different server). Then, the automation tool is run on each client under unified control. The results from each client's execution are visible on Ansible.
[0070] Optionally, the method further includes:
[0071] Remove the software and automation tool packages installed on each of the aforementioned clients.
[0072] In this embodiment, Ansible uniformly removes the software and automation tool packages installed on the client, restoring the environment to its original state.
[0073] The following explanation uses specific projects as examples:
[0074] The project requires multiple clients to repeatedly disconnect from the server to test the server's performance and stability. Manually deploying and running an automated disconnection tool on multiple clients would be both labor-intensive and prone to errors, requiring client-side monitor configuration for debugging to ensure the tool functions correctly. These two pain points are precisely what Ansible excels at. Therefore, this disclosure allows for unified management and configuration of each client on the Ansible server.
[0075] This disclosure provides an Ansible-based automated operation and maintenance method that enables unified management and configuration of each client on the server, thereby improving the efficiency and reliability of operation and maintenance.
[0076] Figure 3 This is an architecture diagram of a server provided as an embodiment of this disclosure. (For example...) Figure 3 As shown, the server includes: a first configuration module 301, a second configuration module 302, a third configuration module 303, and a writing module 304; wherein, the first configuration module 301 is used to configure the ansible.cfg file; the second configuration module 302 is used to configure the hosts file, which carries information about the controlled host; wherein, the information about the controlled host includes the IP address, SSH login username and password, and root user password; the third configuration module 303 is used to configure the userconfig.yaml file, which carries information about the controlled host running an automated disconnection tool to access the server; the writing module 304 is used to write the linux.yaml script file, which is used to configure, deploy, and manage the scripts of the controlled node.
[0077] Figure 4 This is an architecture diagram of a server provided as an embodiment of this disclosure. (For example...) Figure 4As shown, the server includes: a first configuration module 401, a second configuration module 402, a third configuration module 403, and a writing module 404; the writing module 404 specifically includes: a distribution submodule 4041, a replacement submodule 4042, and a control submodule 4043; wherein, the distribution submodule 4041 is used to distribute the automation tool from the Ansible server to each of the controlled hosts; the replacement submodule 4042 is used to replace the configuration file in the automation tool of each of the controlled hosts according to the configuration in the userconfig.yaml file; the control submodule 4043 is used to control each of the controlled hosts to run the automation tool after the configuration file is replaced.
[0078] Figure 5 This is an architecture diagram of a server provided as an embodiment of this disclosure. (For example...) Figure 5 As shown, the server includes: a first configuration module 501, a second configuration module 502, a third configuration module 503, a writing module 504, and a deletion module 505; wherein, the deletion module 505 is used to delete the software and automation tool packages installed on each client.
[0079] In one embodiment, a computer device is provided, the internal structure of which can be as shown in the figure. Figure 6 As shown. The computer device includes a processor, memory, network interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The database stores data. The network interface communicates with external terminals via a network connection. When the computer program is executed by the processor, it implements one of the Ansible-based automated operation and maintenance methods described above. It includes: memory and a processor; the memory stores the computer program; and the processor executes the computer program to implement any step of the Ansible-based automated operation and maintenance method described above.
[0080] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, can perform any of the steps in the Ansible-based automated operations and maintenance method described above.
[0081] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0082] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0083] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0084] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0085] Although preferred embodiments of this application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of this application.
[0086] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.
Claims
1. An Ansible-based automated operation and maintenance method, characterized in that, Applied to a server, the method includes: Configure the ansible.cfg file; Configure a hosts file, which contains information about the controlled host; the information about the controlled host includes its IP address, SSH login username and password, and root user password. Configure the userconfig.yaml file, which contains information about the controlled host running the automated disconnection tool to access the server; Write a linux.yaml script file, which is used to configure, deploy, and manage the scripts of the controlled node.
2. The method according to claim 1, characterized in that, The process of writing the linux.yaml script file includes: The automation tools are distributed from the Ansible server to each of the controlled hosts; Replace the configuration file in the automation tool for each controlled host according to the configuration in the userconfig.yaml file; Control each of the controlled hosts to run the automated tool after replacing the configuration file.
3. The method according to claim 2, characterized in that, The method further includes: Remove the software and automation tool packages installed on each of the aforementioned clients.
4. The method according to claim 1 or claim 2, characterized in that, The configuration file ansible.cfg includes: Configure the host_key_checking and forks variables; the host_key_checking variable is used to determine whether to perform public key checks on the controlled host, and the forks variable is used to determine the number of Ansible concurrent threads.
5. The method according to claim 2, characterized in that, The information accessed by the controlled host using the automated disconnection tool includes: the server's IP address, the server's operating system type, the username and password for logging into the server, and the number of times the controlled host attempted to connect to the server.
6. A server, characterized in that, The server includes: a first configuration module, a second configuration module, a third configuration module, and a writing module; wherein, The first configuration module is used to configure the ansible.cfg file; The second configuration module is used to configure the hosts file, which contains information about the controlled host; wherein, the information about the controlled host includes the IP address, the username and password for SSH login, and the password for the root user; The third configuration module is used to configure the userconfig.yaml file, which contains information about the controlled host running an automated disconnection tool to access the server. The writing module is used to write linux.yaml script files, which are used to configure, deploy, and manage the scripts of the controlled nodes.
7. The server according to claim 6, characterized in that, The writing module specifically includes: a distribution submodule, a replacement submodule, and a control submodule; wherein... The distribution submodule is used to distribute automation tools from the Ansible server to each of the controlled hosts; The replacement submodule is used to replace the configuration file in the automation tool of each controlled host according to the configuration in the userconfig.yaml file; The control submodule is used to control each controlled host to run the automation tool after the configuration file is replaced.
8. The server according to claim 7, characterized in that, The server further includes: a deletion module; wherein... The deletion module is used to delete the software and automation tool packages installed on each of the clients.
9. A computer device, comprising: A memory and a processor, the memory storing a computer program, characterized in that the processor, when executing the computer program, implements the steps of the method according to any one of claims 1 to 5.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 5.