Ansible automated operation and maintenance installation

Source: Internet
Author: User
Tags ssh port

Currently, the deployment of automated operations has become a safe and efficient completion of the necessary skills, mainly puppet, Saltstack, ansible, this blog post will focus on the Automation Operations Tools Ansible installation and configuration file resolution.

I. Ansible INTRODUCTION 1, What is ansible?

Ansible based on the development of Python, the advantages of many excellent operation and maintenance tools are assembled, and the functions of batch system configuration, batch program deployment and batch running command are realized. The default is remote control via the SSH protocol without the need for Client Agent software.

2. Ansible Core Components

Ansible is a module-based operation and does not have the capacity to deploy in bulk. The real batch deployment is the module that Ansible runs, and Ansible just provides a framework. Mainly include:

    • ansible core engine;
    • Host inventory (host manifest): Defines Ansible managed hosts and supports custom Dynamic host inventory and other profile locations.
    • Connection plugins (connection plug-in): Responsible for communicating with managed hosts.
    • playbooks (script): Centrally define configuration files for ansible tasks.
    • Core modules: Ansible comes with modules, distributing resources to managed hosts.
    • Custom Modules: Complete the function Module supplement. 3, Ansible features

      (1) deployment is simple, only need to deploy the Ansible environment on the main control side, the host does not need to do anything.
      (2) The device is managed by default using the SSH protocol.
      (3) centralized management of master and slave. The
      (4) configuration is simple, powerful and extensible. The
      (5) supports APIs and custom modules that can be easily extended with Python. The
      (6) uses playbooks to customize powerful configuration and state management. The
      (7) has good support for the cloud computing platform and big data.
      (8) provides a powerful, operational Web management interface and REST API interface----AWX platform.

      Ii. Deployment Ansible Service Case Description:
        ansible Automation operation consists of the control host and the managed host, because SSH-based communication, so the control host only need to install ansible, the managed host does not need to install and run any agent.  
      Case Environment:
role Operating System IP Address Group name
Control host Centos7 192.168.37.128
Managed hosts Centos7 192.168.37.130 Webserver
Managed hosts Centos7 192.168.37.131 Mysql
Deployment Installation

1, install ansible on the control host

Yum install-y epel-release #安装epel扩展源
Yum install-y ansible-y #安装ansible

2. View ansible configuration file after installation

ansible --version          #查看版本cat /etc/ansible    ansible.cfg                #主配置文件    hosts                         #主仓库、用于存储需要管理的远程主机    roles                          #角色

3. Configure Host Inventory

vim  /etc/ansible/hosts    【webserver】192.168.37.130【mysql】192.168.37.131


4, configure the key pair to authenticate, push the public key to the managed host

SSH-KEYGEN-T RSA
Ssh-copy-id [email protected]
Ssh-copy-id [email protected]



5. Set up SSH password-free login

Ssh-agent Bash
Ssh-add


Three, ansible configuration file detailed master configuration file ansible.cfg
[Defaults] #some basic Default values...inventory =/etc/ansible/hosts # host manifest INVe Location of the ntory file Library =/usr/share/my_modules/#指向存放ansible模块的目录module_utils =/usr/shar E/my_module_utils/remote_tmp = ~/.ansible/tmp #Ansible by remote transmission          module to the remote host, and then remotely execute local_tmp = ~/.ansible/tmpplugin_filters_cfg =/etc/ansible/plugin_filters.yml #过滤器插件forks                                                           = 5 #默认ansible最多有5个进程同时工作poll_interval = 15                                                        #多少时间回查一下任务状态sudo_user = root # set default execution command for user Ask_sudo_pass = True # to control ansible Playboo K whether to ask for sudo password before executing sudo ask_pass = True #控制Ansible whether playbook will automatically Default Popup Password transport = sMart #通信机制. The default value is ' smart ' Remote_port = 22                                                         # Specify the management port to connect to the managed node, default is 22module_lang = C                                                #模块和系统之间通信的计算机语言, the default is c language Module_set_locale = False
Host List hosts
#[webservers]#alpha.example.org#beta.example.org#192.168.1.100#192.168.1.110#[dbservers]#db01.intranet.mydomain.net#db02.intranet.mydomain.net#10.25.1.56#10.25.1.57
    • The square brackets [] are group names, which are used to classify the system to facilitate individual management of different systems.
    • A system can belong to a different group, such as a server that can belong to both the Webserver group and the DBServer group. Variables that belong to two groups can be used by this host.
    • If the SSH port of the host is not a standard 22 port, you can append the port number to the host name, separated by a colon. The port numbers listed in the SSH configuration file are not used in the Paramiko connection and are used in the OpenSSH connection.

Ansible automated operation and maintenance installation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.