Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and configure ansible

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "how to install and configure ansible", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to install and configure ansible" article.

Introduction to ansible

Ansible project

1. Brief introduction to Ansible:

Ansible is a new and popular automatic operation and maintenance tool. Based on python2-paramiko module development, it integrates the advantages of many operation and maintenance tools (puppet, cfengine, chef, func, fabric), and realizes the functions of batch system configuration, batch program deployment and batch running commands.

Ansible works based on modules and does not have the ability to deploy in batches. What really has batch deployment is the module that ansible runs, and ansible provides only one framework. The framework of ansible mainly includes the following functions:

(1) connection plug-in connection plugins: responsible for communicating with the monitored end in advance

(2) host inventory: list of operating hosts

(3) Core module, command module, custom module

(4) with the help of plug-ins, log mail and other functions are completed.

(5) Playbook: when the script performs multiple tasks, it is not necessary to let the node run multiple tasks at one time.

Second, Ansible features:

(1) No agents: no client software needs to be installed on the managed host.

(2) No server: without the concept of server side, you can run the command directly when you use it.

(3) Modules in any languages: based on the module work, the module can be developed in any language.

(4) Yaml, not code: customize the script playbook using the Yaml language.

(5) Ssh by default: work based on SSH.

(6) Strong multi-tier solution: multi-level command can be realized.

3. Advantages of Ansible:

(1) lightweight, there is no need to install agent on the client side. When updating, you only need to update once on the manipulator.

(2) batch tasks can be written as scripts and can be executed without having to distribute them remotely.

(3) written in python, the maintenance is simpler, and the ruby syntax is too complex.

(4) support sudo

4. Install Ansible:

(1) install Ansible on the management node

(on Redhat/CentOS Linux, Ansible is currently placed in the epel source. The default source of Fedora includes Ansible, which can be installed by yourself.)

# yum install epel-release

# yum install ansible-y

# ssh-keygen

# ssh-copy-id remoteuser@remotehost

(2) managed remote host

(there is no need to install a special package, just configure and start the SSH service and the Python version is above 2.4. Redhat is generally installed by default. )

5. Introduction of Ansible configuration file:

(1) main configuration file: / etc/ansible/ansible.cfg

(2) default host manifest file: / etc/ansible/hosts

The configuration file for Ansible states:

Profile category

Description

Location

Default profile

Default profile for ansible software, effective for all users using ansible

/ etc/ansible/ansible.cfg

User Profil

Using a specific operation and maintenance playbook of an ordinary user, as long as the user is used to log in to the ansible operation and maintenance host, the configuration file will overwrite the contents of the default configuration file in any folder.

~ / amsible.cfg

~ / .ansible.cfg

Operation and maintenance project configuration file

Put a type of operation and maintenance playbook in a folder and only the configuration files that are valid in the current operation and maintenance project.

/ dir/ansible.cfg

● uses ansible-- version to view the path of the currently valid ansible.cfg.

● when three files conflict, priority: operation and maintenance project profile > user profile > default profile

/ dir/ansible.cfg > ~ / .ansible.cfg > ~ / amsible.cfg > / etc/ansible/ansible.cfg

You can specify where the hosts file is located in ansible.cfg

6. Ansible default host manifest file Inventory is / etc/ansible/hosts:

What is inventory:

● Static lines of servers

● Ranges

● Other custom things

● Dynamic lists of servers: AWS,Azure,GCP,etc.

Grammatical structure:

● "#" starts to indicate comments, and space lines are ignored

● uses [] to set remote host grouping, with the group name in [groupname].

The ● host list can use a hostname or IP address.

● A hostname or IP address can be in multiple packets.

● uses [start:end] to represent consecutive hosts.

● grouping supports nesting, and one group can contain other groups, with the suffix ": children" in the new group name.

[group1]

Host1.example.com

Host2.example.com

[group2]

Host3.example.com

Host4.example.com

[newgroup:children]

Group1

Group2

(1) examples of standard host and packet lists:

Mail.example.com

[webservers]

Foo.example.com

Bar.example.com

[dbservers]

One.example.com

Two.example.com

Three.example.com

(2) list of hosts under non-standard ports

Badwolf.example.com:5309

(3) continuous mass host list "[start:end]"

[webservers]

Www [01:50] .example.com

[databases]

Db- [a:f]. Example.com

192.168. [4:7]. All hosts under the network segment 22 of 192.168.4.0 / all hosts under 192.168.4.0-192.168.7.255

(4) list of aliases set by the host

Jumper ansible_port=5555 ansible_host=192.0.2.50

(5) groups contain other groups (group nesting)

[olympia]

Washington1.example.com

Washington2.example.com

[salem]

Oregon01.example.com

Oregon02.example.com

[nwcapitols:children]

Olympia

Salem

(6) set connection parameters

[targets]

Localhost ansible_connection=local

Other1.example.com ansible_connection=ssh ansible_user=mpdehaan

Other2.example.com ansible_connection=ssh ansible_user=mdehaan

Common connection parameters for host manifest files

Connection parameters

Express meaning

Ansible_connection

The connection method of the SSH. Can be specified as smart, ssh, local, paramiko

Ansible_host

The host address of the Ansible connection, if you have a different alias in the host list, you need to use this parameter to specify the host IP or host name.

Ansible_port

SSH port number, default is 22.

Ansible_user

The default user name used when connecting to SSH.

Ansible_ssh_pass

The password used for the SSH connection. However, it is not recommended to use this parameter to store the password of plaintext.

Ansible_ssh_private_key_file

Specifies the location where the private key file generated using ssh-keygen is stored.

Ansible_ssh_common_args

Configure this parameter to specify the default additional parameters for SFTP, SCP, and SSH.

The above is about the content of this article on "how to install and configure ansible". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report