ansible的环境部署及简单使用

简介: ansible的环境部署及简单使用

一.部署ansiber环境

1.准备三台机器:

配置IP,主机名,/etc/hosts

2.然后去配置免密登录

1.在服务端操作,上传公钥

[root@good .ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase 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:0ihaGqzhrrggldA2+PdMixdf80qkmODATm08Z/77wmE root@good
The key's randomart image is:
+---[RSA 3072]----+
|                 |
| o               |
|o +              |
| * =   o         |
|. X X B S +      |
|.* X % BE+ o     |
|+.+ o Ooo.. .    |
|=    . .o. .     |
|=o      o+o      |
+----[SHA256]-----+

2.将公钥传给客户端

[root@rhcsa .ssh]# ssh-copy-id root@rhce
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'rhce (192.168.40.132)' can't be established.
ECDSA key fingerprint is SHA256:70V58bQzrfUci7EE23sAS/cd7Zjc3zbRhTx15uN1PVY.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@rhce's password: 
Number of key(s) added: 1
Now try logging into the machine, with:   "ssh 'root@rhce'"
and check to make sure that only the key(s) you wanted were added.

3.验证免密登录

[root@rhcsa .ssh]# ssh root@rhce
Activate the web console with: systemctl enable --now cockpit.socket
This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --register
Last failed login: Tue Aug  2 17:13:21 CST 2022 from 192.168.40.129 on ssh:notty
There were 2 failed login attempts since the last successful login.
Last login: Tue Aug  2 16:26:36 2022 from 192.168.40.129
[root@rhce ~]# exit
logout
Connection to rhce closed.

3.配置yum源使用Centos-stream.repo

4.安装ansible

[root@rhcsa yum.repos.d]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-1.el8.noarch.rpm
Retrieving https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-1.el8.noarch.rpm
warning: /var/tmp/rpm-tmp.uSbUwD: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-release-6.0-1.el8         ################################# [100%]
[root@rhcsa yum.repos.d]# yum install -y https://mirrors.tuna.tsinghua.edu.cn/epel/epel-release-latest-8.noarch.rpm
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
Repository AppStream is listed more than once in the configuration
Zabbix Official Repository - x86_64              25 kB/s | 107 kB     00:04    
Zabbix Official Repository non-supported - x86_ 294  B/s | 1.2 kB     00:04    
epel-release-latest-8.noarch.rpm                 33 kB/s |  24 kB     00:00    
Dependencies resolved.
================================================================================
 Package             Architecture  Version            Repository           Size
================================================================================
Installing:
 epel-release        noarch        8-16.el8           @commandline         24 k
Transaction Summary
================================================================================
Install  1 Package
Total size: 24 k
Installed size: 34 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : epel-release-8-16.el8.noarch                           1/1 
  Running scriptlet: epel-release-8-16.el8.noarch                           1/1 
Many EPEL packages require the CodeReady Builder (CRB) repository.
It is recommended that you run /usr/bin/crb enable to enable the CRB repository.
  Verifying        : epel-release-8-16.el8.noarch                           1/1 
Installed products updated.
Installed:
  epel-release-8-16.el8.noarch                                                  
Complete!

5.使用ansible --version去验证

[root@good yum.repos.d]# ansible --version
ansible [core 2.12.7]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.13 (default, Jun 24 2022, 15:27:57) [GCC 8.5.0 20210514 (Red Hat 8.5.0-13)]
  jinja version = 2.11.3
  libyaml = True

二、ansible基础使用

1.配置清单:

/etc/ansible/hosts

[node]

node1.example.com

node2.example.com

[root@good yum.repos.d]# vim /etc/ansible/hosts 

2.使用ansible node -m ping去验证

 

目录
相关文章
|
运维 网络安全 Python
自动化运维:使用Ansible实现批量服务器配置
在快速迭代的IT环境中,高效、可靠的服务器管理变得至关重要。本文将介绍如何使用Ansible这一强大的自动化工具,来简化和加速批量服务器配置过程。我们将从基础开始,逐步深入到更复杂的应用场景,确保即使是新手也能跟上节奏。文章将不包含代码示例,而是通过清晰的步骤和逻辑结构,引导读者理解自动化运维的核心概念及其在实际操作中的应用。
|
运维 Ubuntu 网络协议
自动化运维:使用Ansible进行服务器配置管理
在现代IT架构中,自动化运维已成为提升效率、减少人为错误的关键。本文将介绍如何使用Ansible这一强大的自动化工具来简化和标准化服务器的配置管理过程。通过具体的代码示例和操作步骤,我们将展示如何快速部署应用、管理配置以及自动化日常任务,从而确保环境的一致性和可靠性。
|
运维 Ubuntu 应用服务中间件
自动化运维之路:使用Ansible进行服务器管理
在现代IT基础设施中,自动化运维已成为提高效率和可靠性的关键。本文将引导您通过使用Ansible这一强大的自动化工具来简化日常的服务器管理任务。我们将一起探索如何配置Ansible、编写Playbook以及执行自动化任务,旨在为读者提供一条清晰的路径,从而步入自动化运维的世界。
388 11
|
运维 Ubuntu Linux
自动化运维:使用Ansible简化日常任务
在快节奏的IT世界中,时间就是一切。本文将揭示如何通过Ansible这一强大的自动化工具来节省宝贵的时间,从而提高效率和减少人为错误。我们将深入探讨Ansible的核心概念、安装过程以及如何编写简单的playbook来自动执行常见运维任务。无论你是新手还是有经验的系统管理员,这篇文章都将为你提供实用的知识和技能,让你能够更好地控制你的服务器环境。
|
运维 安全 Ubuntu
自动化运维:使用Ansible进行服务器配置管理
在现代IT基础设施中,自动化运维是确保高效、稳定和安全服务的关键。本文将深入介绍如何使用Ansible这一开源工具来简化服务器配置管理工作,从基础安装到高级应用,我们将一步步展示如何通过Ansible Playbooks实现自动化部署和维护,旨在帮助读者构建更加灵活和可扩展的运维体系。
382 7
|
运维 监控 安全
自动化运维的利剑:Ansible在现代IT架构中的应用
在数字化浪潮中,企业对IT系统的敏捷性和可靠性要求日益提高。Ansible,一种简单但强大的自动化运维工具,正成为现代IT架构中不可或缺的一部分。它通过声明式编程语言YAM,简化了系统配置、应用部署和任务自动化的过程,显著提升了运维效率和准确性。本文将深入探讨Ansible的核心特性、应用场景以及如何有效整合进现有IT环境,为读者揭示其在自动化运维中的实用价值和未来发展潜力。
|
运维 Devops 应用服务中间件
自动化运维的利剑:Ansible在现代IT架构中的应用
【10月更文挑战第42天】本文旨在揭示自动化运维工具Ansible如何革新现代IT架构,通过简化配置管理和部署流程,提升效率和可靠性。我们将探索Ansible的核心功能、语言特性以及其在DevOps文化中的角色。文章还将展示如何借助Ansible构建模块化和可重用的配置代码,实现快速迭代与部署,并确保系统一致性。通过阅读本文,运维人员将了解如何利用Ansible优化日常任务,加速产品上线速度,同时提高系统的稳健性。
374 5
|
运维 监控 应用服务中间件
自动化运维的利器:Ansible实战应用
【10月更文挑战第41天】在现代IT运维领域,自动化已成为提高效率、减少错误的关键。Ansible作为一种简单而强大的自动化工具,正被越来越多的企业采纳。本文将通过实际案例,展示如何使用Ansible简化日常运维任务,包括配置管理和批量部署等,旨在为读者提供一种清晰、易懂的自动化解决方案。
354 1
|
运维 应用服务中间件 Linux
自动化运维的利器:Ansible在配置管理中的应用
【10月更文挑战第39天】本文旨在通过深入浅出的方式,向读者展示如何利用Ansible这一强大的自动化工具来优化日常的运维工作。我们将从基础概念讲起,逐步深入到实战操作,不仅涵盖Ansible的核心功能,还会分享一些高级技巧和最佳实践。无论你是初学者还是有经验的运维人员,这篇文章都会为你提供有价值的信息,帮助你提升工作效率。
|
运维 安全 应用服务中间件
自动化运维的利剑:Ansible在配置管理中的应用
【10月更文挑战第37天】本文将深入探讨如何利用Ansible简化和自动化复杂的IT基础设施管理任务。我们将通过实际案例,展示如何用Ansible编写可重用的配置代码,以及这些代码如何帮助运维团队提高效率和减少人为错误。文章还将讨论如何构建Ansible playbook来自动部署应用、管理系统更新和执行常规维护任务。准备好深入了解这个强大的工具,让你的运维工作更加轻松吧!
256 2