Install and use the automation tool Ansible CentOS7

Source: Internet
Author: User
Ansible is a free, open-source configuration and automation tool developed for Unix-like systems. It is written in Python and is similar to Chef and Puppet. but there is a difference and advantage that we do not need to install any client in the node. It uses SSH to communicate with nodes. In this article, we will install and configure Ansible on CentOS7 and try to manage the two nodes. Ansible server & ndash; ansible. linuxtech

Ansible is a free, open-source configuration and automation tool developed for Unix-like systems. It is written in Python and is similar to Chef and Puppet. but there is a difference and advantage that we do not need to install any client in the node. It uses SSH to communicate with nodes.

In this article, we will install and configure Ansible on CentOS7 and try to manage the two nodes.

Ansible server-ansible.linuxtechi.com (192.168.1.15)

Node-192.168.1.9, 192.168.1.10

 

Step 1: Set the EPEL repository

The Ansible repository is not in the yum repository by default, so we need to use the following command to enable the epel repository.

[Root @ ansible ~] # Rpm-iUvhhttp: // dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

 

Step 2: Use yum to install Ansible

[Root @ ansible ~] # Yum installansible

After the installation is complete, check the ansible version:

[Root @ ansible ~] # Ansible -- version

 

Step 3: Set the SSH key for Node Authentication

Generate a key on the Ansible server and copy the public key to the node.

Root @ ansible ~] # Ssh-keygen

Use the ssh-copy-id command to copy the Ansible public key to the node.

 

Step 4: define a node list for Ansible

File/etc/ansible/hosts maintains the list of servers in Ansible.

[Root @ ansible ~] # Vi/etc/ansible/hosts

[Test-servers]

192.168.1.9

192.168.1.10

Save and exit the file.

 

Step 5: try to run the command on the Ansible server

Use ping to check the connectivity of the 'test-servers' or ansible node.

[Root @ ansible ~] # Ansible-mping 'test-servers'

 

Execute shell commands

1: Check the running time (uptime) of the Ansible node)

[Root @ ansible ~] # Ansible-mcommand-a "uptime" 'test-servers'

 

2: Check the kernel version of the node.

[Root @ ansible ~] # Ansible-mcommand-a "uname-r" 'test-servers'

 

3: Add users to nodes

[Root @ ansible ~] # Ansible-mcommand-a "useradd mark" 'test-servers'

[Root @ ansible ~] # Ansible-mcommand-a "grep mark/etc/passwd" 'test-servers'

 

4: Redirect output to file

[Root @ ansible ~] # Ansible-mcommand-a "df-Th" 'test-servers'>/tmp/command-output.txt

Receive free Brothers IT education original linux O & M engineers video/detailed linux tutorial, details consulting official website Customer Service: http://www.lampbrother.net/linux/

Or hook up Q2430675018.

Welcome to the linux chat group 478068715.

Related Article

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.