Installation and configuration of ansible on centos7

Source: Internet
Author: User
Tags ssh port
1. Introduction to ansible: ansible is developed based on Python and integrates the advantages of many excellent O & M tools to implement features such as running commands, deploying programs, and configuring the system in batches. By default, SSH protocol is used for remote command execution or configuration delivery, without the need to deploy any client proxy software, making the deployment of the automated environment easier. Allows you to manage multiple hosts at the same time, making it easier to manage hosts. The main version is released every two months.
2. core components:
Ansible: ansible core program
Host lnventory: records information about each host managed by ansible, including the ssh port, root account password, and IP address. You can use file to load data, and you can use CMDB to load data.
Playbooks: a file in yaml format. multiple tasks are defined in one file and can be called in a unified manner. The script defines the functions that the host needs to call by those modules.
Core modules: ansible does not execute any management tasks by ansible itself, but by the core module. Before ansible manages the host, it first calls the module in core modules, then specify the host in host lnventory to manage the host.
Custom modules: a custom module that completes functions that cannot be completed by the ansible core module. This module supports writing in any language.
Connection plugins: Connection plug-in for communication between ansible and host

3. installation and configuration
Lab environment: ansibleserver (IP: 192.168.252.130 centos7)
Mysqlserver (IP: 192.168.252.173 centos7)
Webserver (IP: 192.168.252.174 centos7)
Ansibleserver
1) install ansible and configure the host list
Yum install-y epel-release // install the environment package
Yum install-y ansible // install ansible
Vim/etc/ansible/hosts // configure the host list and add the managed Host IP Address

# This is the default ansible 'hosts' file.

# It shoshould live in/etc/ansible/hosts

#-Comments begin with the '# 'character
#-Blank lines are ignored
#-Groups of hosts are delimited by [header] elements
#-You can enter hostnames or IP addresses
#-A Hostname/IP can be a member of multiple groups

# Ex 1: ungrouped hosts, specify before any group headers.

# Green.example.com
# Blue.example.com
#192.168.100.1
#192.168.100.10

# EX 2: a collection of hosts belonging to the 'webservers' Group

# [Webservers]
# Alpha.example.org
# Beta.example.org
#192.168.1.100
#192.168.1.110
[Webserver] // Add
192.168.252.173 // Add
[MySQL] // Add
192.168.252.174 // Add


2) generate a key pair and push the public key to the managed Terminal
Ssh-keygen-t rsa // generate a key pair of the RSA type
Enerating public/private RSA key pair.
Enter file in which to save the key (/root/. Ssh/id_rsa): // press ENTER
Created directory '/root/. Ssh '.
Enter passphrase (empty for no passphrase): // enter the password
Enter same passphrase again: // enter again
Your identification has been saved in/root/. Ssh/id_rsa.
Your public key has been saved in/root/. Ssh/id_rsa.pub.
The key fingerprint is:
Sha256: udpix9u0dkslcnd1rfwgy3pk/zdczw1fep2ao3ggq [email protected]
The key's randomart image is:
+ --- [RSA 2048] ---- +
|... O +. o |
|... +. + O |
|. =. = |
|. +. Ooo. o |
| ESO =. +. B |
| O. O... OOB |
|. O +. O + = |
|. = +. O |
| O... |
+ ---- [Sha256] ----- +
Cd ~
CD. SSH
Ssh-copy-ID [email protected]
Ssh-copy-ID [email protected] // push the public key to the managed Terminal
Ssh-Agent bash // no interaction
Ssh-add

Now ansible installation and host configuration are complete. (Note: If the connection fails, check whether the ansibleserver and the managed side can be pinged. If the connection fails, delete the key under. SSH and generate and issue it again)

Installation and configuration of ansible on centos7

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.