linux之Ansible快速入门

Ansible是一款简单的运维自动化工具,只需要使用ssh协议连接就可以来进行系统管理,自动化执行命令,部署等任务。

Ansible的优点

Ansible的组成结构

Ansible常用的功能模块

命令模块
  command
  shell
文件模块
  copy
  fetch
  file
安装模块
  yum
服务模块
  service
挂载模块
  mount
定时任务
  cron
用户模块
  group
  user
压缩解压
  unarchive

Ansible安装

> yum install ansible -y

配置主机

> vim /etc/ansible/hosts
[web]
192.168.2.10 ansible_ssh_port=22 ansible_ssh_user=rumenz ansible_ssh_pass="123456"
192.168.2.11 ansible_ssh_port=22 ansible_ssh_user=rumenz ansible_ssh_pass="123456"

我们定义了一个web组(可以加很多主机),Ansible默认使用的是ssh协议,指定好端口,账号,密码就可以了。
除了使用账号,密码的形式配置,我们也可以用秘钥,后面访问。

测试

> ansible web -m ping

web就是上面我们定义的分组,-m我后面指定模块,这里我们使用ping模块,用于查看主机是否网络可达。

使用Ansible执行pwd命令

> ansible  web -m shell -a "pwd"

这里我们使用的是shell 模块,-a后面跟上需要执行的shell命令

使用Ansible查看web分组下nginx服务是否在运行

> ansible web -m shell -a "ps -ef | grep nginx"

使用Ansible简单批量安装redis

> ansible web -m shell -a "yum install redis -y"

注意复杂的软件安装,需要编写Ansible playbook配置文件,更加灵活。

原文链接:https://rumenz.com/rumenbiji/linux-ansible-quick.html

展开阅读全文

页面更新:2024-06-16

标签:变量   端口   账号   功能模块   插件   模块   入门   命令   定义   协议   主机   密码   快速   结构   简单   功能   工具   科技

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号

Top