What is automated operation and maintenance
With the continuous development of the information age, IT operation and maintenance has become an important part of the connotation of IT services. In the face of more and more complex business and diversified user needs, expanding IT applications need more and more reasonable modes to ensure that IT services can be flexible, convenient, safe and stable and sustainable. The guarantee factor of this mode is IT operation and maintenance (other factors are more superior IT architecture, etc.). From the initial development of several servers to a huge data center, manual work alone can no longer meet the technical, business, management and other requirements, so standardization, automation, architecture optimization, process optimization and other factors to reduce the cost of IT services have been paid more and more attention. Among them, automation has been widely studied and applied as a starting point instead of manual operation. Since the birth and development of IT operation and maintenance, automation, as one of its important attributes, has not only replaced manual operation, but also deeply explored and global analysis. It focuses on how to achieve performance and service optimization under current conditions, while ensuring the maximum return on investment. The impact of automation on IT operations and maintenance is not only the relationship between people and equipment, but also the level of customer service-oriented decision-making. The composition of IT operations and maintenance team has also developed from the majority of technical personnel at all levels to the majority of business personnel and even users. Therefore, IT operation and maintenance automation is a group of strategies to transform static equipment structure into dynamic elastic response according to IT service requirements, with the aim of achieving the quality of IT operation and maintenance and reducing costs. It can be said that automation must be one of the most important attributes of IT operation and maintenance, but not all of them.
What is ansible
ansible is an emerging automated operation and maintenance tool. It is based on Python development. It combines the advantages of many operation and maintenance tools (puppet, cfengine, chef, func, fabric). It realizes the functions of batch system configuration, batch program deployment, batch operation command and so on. It can realize the configuration of multiple servers and execute the same command on multiple servers at the same time.
ansible framework
> host inventory: defines the list of hosts operated by ansible > connection plugins: responsible for monitoring the communication between the operating host and the operating host > playbook: Defining the tasks of ansible > plugins: expansion module, mainly used to complete log, mail and other functions > Core module, custom module: mainly used to execute commands
Download and install ansible
1. download ansible
[root@www ~]# wget http://releases.ansible.com/ansible/ansible-2.3.2.0-0.4.rc4.tar.gz
2. install ansible
[root@www ~]# tar -xzf ansible-2.3.2.0-0.4.rc4.tar.gz
[root@www ~]# cd ansible-2.3.2.0
[root@www ~]# python setup.py build
[root@www ~]# python setup.py install
3. Equipment Profile
[root@www ~]# mkdir /etc/ansible
[root@www ~]# cp -r examples/* /etc/ansible/
hosts configuration file
Format:
[webservers] //Host group name
alpha.example.org
beta.example.org
192.168.1.100
192.168.1.110
ansible command
1. Format:
ansible <host-pattern> [-f forks] [-m module_name] [-a args]
2. Detailed parameters:
host-pattern:Configuration file defined host group name
-f gorks: Level, default5
-m: Specify the core module to be used, default is command Modular
-a: Specify module parameters
3. Order for him:
ansible -l: Used to view ansible Supported modules
ansible-doc -s module_name: Used to view parameters supported by a module
Remote shell execution using ansible command
host file
Target aircraft
ansible host
[root@www ~]# ssh-keygen
[root@www ~]# ssh-copy-id root@192.168.80.130
[root@www ~]# ansible install_httpd -m shell -a "yum -y install httpd"
Target aircraft
Defining multitasking using yaml grammar
1. File Definition Format:
Task_set.yaml (file extension.yaml)
2. Text content format:
- hosts: hosts_name //Define the host name in the hosts file
remote_user: root //Users running this task
tasks: /// Tasks should be taken
- name: taks_name //Task Name
moudule_name: args[1]=? args[2]=? .... //Parameter, the option corresponding to - a in the command
ignore_errors:True //Ignore errors
notify: //The following events will not occur without change
- handerls_name
handlers: //Implements a one-time execution of specified operations after the changes have been completed, such as restarting the service after changing the configuration file.
- name: handerls_name
module: args
*notes*:A host set can correspond to multiple tasks, one.yaml Files can contain multiple host sets
3. Text Content Run Command:
[root@www ~]# ansible-playbook file.yaml
test