Ansible(一)——介绍

什么是Ansible

Ansible是一款开源自动化平台。它是一种简单的自动化语言,能够在Ansible Playbook中完美的描述IT应用基础架构。它是一个自动化引擎,可运行Ansible Playbook。

Ansible特性

  • 模块化:调用特定模块,完成特定任务
  • Paramiko(Python对ssh的实现),PyYAML,JinJa2(模板语言)三个关键模块
  • 支持自定义模块,可使用任何编程语言
  • 基于Python语言实现
  • 部署简单,基于Python和SSH,无需代理
  • 安全,基于OpenSSH
  • 幂等性:一个任务执行1遍和执行n遍效果一样,不因重复执行带来意外
  • 支持Playbook编排任务,YAML格式,支持丰富的数据结构
  • 强大的多层解决方案roles

Ansible架构

 Ansible核心组成

inventory:Ansible管理主机的清单

modules:Ansible执行命令的功能模块,多数为内置核心模块,也可自定义

plugins:模块功能的补充。如连接类型插件、循环插件、过滤插件、变量插件等

API:供第三方程序调用的接口

Ansible命令执行来源

users普通用户:即系统管理员

playbook:任务剧本

cmdb:配置管理数据库。API调用

public/private cloud:公有云/私有云平台API调用

注意事项

  • 运行Ansible的主机一般被称为主控端、中控、master、堡垒机。
  • 主控端Python版本需要2.6及以上
  • 被控端Python版本小于2.4需要安装python-simplejson
  • 被控端如开启selinux需要安装libselinux-python
  • Windows不能作为主控端

安装Ansible

CentOS8

[root@centos8-01 ~]# yum -y install epel-release
[root@centos8-01 ~]# yum -y install ansible

#查看ansible版本信息
[root@centos8-01 ~]#ansible --version
ansible 2.9.27
  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.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Apr 16 2020, 01:36:27) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]

CentOS8安装Ansible可能会报错:

Error: 
 Problem: cannot install the best candidate for the job
  - nothing provides python3.9dist(ansible-core) needed by ansible-6.3.0-1.el8.noarch
  - nothing provides (python3.9dist(ansible-core) >= 2.13.3 with python3.9dist(ansible-core) < 2.14) needed by ansible-6.3.0-1.el8.noarch
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

解决方法:

[root@centos8-01 ~]# yum -y install centos-release-ansible-29.noarch;yum install -y ansible

Ubuntu2004

[root@wenzi ~]$apt list ansible
Listing... Done
ansible/focal 2.9.6+dfsg-1 all
[root@wenzi ~]$apt -y install ansible
[root@wenzi ~]$ansible --version
ansible 2.9.6
  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/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.8.10 (default, Nov 22 2023, 10:22:35) [GCC 9.4.0]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值