#################103上安装ansible
yum install -y ansible

rpm -ql ansible | egrep -v "^/usr/(lib|share)"

/etc/ansible/ansible.cfg #ansible服务配置文件
/etc/ansible/hosts #主机清单文件 定义可以管理的主机
/etc/ansible/roles #角色目录

vim /etc/ansible/hosts
...
## db-[99:101]-node.example.com
192.168.0.102
192.168.0.103(本机)

[root@linux-node2 ~]# ssh-keygen -t rsa

[root@linux-node2 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.0.103
[root@linux-node2 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.0.102


[root@linux-node2 ~]# ansible all -a "hostname"
192.168.0.103 | SUCCESS | rc=0 >>
linux-node2.localdomain

192.168.0.102 | SUCCESS | rc=0 >>
linux-node1.localdomain

Ansible架构图核心组件说明:

Ansible:Ansible的核心程序

Host Lnventory:记录了每一个由Ansible管理的主机信息,信息包括ssh端口,root帐号密码,ip地址等等。可以通过file来加载,可以通过CMDB加载

Playbooks:YAML格式文件,多个任务定义在一个文件中,使用时可以统一调用,“剧本”用来定义那些主机需要调用那些模块来完成的功能.

Core Modules:Ansible执行任何管理任务都不是由Ansible自己完成,而是由核心模块完成;Ansible管理主机之前,先调用core Modules中的模块,然后指明管理Host Lnventory中的主机,就可以完成管理主机。

Custom Modules:自定义模块,完成Ansible核心模块无法完成的功能,此模块支持任何语言编写。

Connection Plugins:连接插件,Ansible和Host通信使用

一、ansible模块

ansible模块应用语法格式:
ansible 主机名称/主机组名称/主机地址信息/all -m(指定应用的模块信息) -a(指定动作信息)

1、command模块(默认模块)
[root@linux-node2 ~]# ansible 192.168.0.102 -m command -a hostname
192.168.0.102 | SUCCESS | rc=0 >>
linux-node1.localdomain

扩展应用:
chdir 切换目录
[root@linux-node2 ~]# ansible 192.168.0.102 -m command -a "chdir=/tmp touch ansible.txt"
[WARNING]: Consider using file module with state=touch rather than running touch

192.168.0.102 | SUCCESS | rc=0 >>

creates 如果指定文件存在,就不执行命令
[root@linux-node2 ~]# ansible 192.168.0.102 -m command -a "creates=/tmp touch ansible.txt"
192.168.0.102 | SUCCESS | rc=0 >>
skipped, since /tmp exists

removes 如果文件存在,就执行
[root@linux-node2 ~]# ansible 192.168.0.102 -m command -a "removes=/tmp touch ansible.txt"
[WARNING]: Consider using file module with state=touch rather than running touch

192.168.0.102 | SUCCESS | rc=0 >>

转载于:https://www.cnblogs.com/linux985/p/11264892.html

01 安装ansible相关推荐

  1. centos7离线安装ansible

    centos7离线安装ansible: 1.通过在线的centos7将rpm包下载好了,上传到指定服务器. 下载官方repo,rpm -iUvh http://dl.Fedoraproject.org ...

  2. 常见的自动化运维工具介绍及特点、安装ansible

    常见的自动化运维工具介绍及特点.安装ansible 一.什么是自动化运维? 简单来说,自动化运维就是将日常重复性工作按照事先设定好的规则,在一定时间范围内自动化运行,而不需要人为参与. 将周期性.重复 ...

  3. 安装ansible和简单使用

    1.yum安装 [root@localhost yum.repos.d]# yum -y install ansible 如果安装报错: [root@localhost yum.repos.d]# y ...

  4. Centos 7安装Ansible+Ansible-Tower踩坑记

    一.安装前环境 Centos 7 最小化安装 | 4G内存 | 100GB硬盘 注:Ansible-Tower目前支持7.4+的版本,可以使用yum update -y命令更新 同时机器一定要联网,因 ...

  5. Ansible(1) Centos7安装Ansible

    角色 IP 系统 ansible server 120.53.13.240 Centos7.6 client 123.207.166.69 Centos7.6 确保Python的版本在2.6以上,如果 ...

  6. centos 7使用tar包安装ansible

    由于我的yum源没有ansible软件包,防止以后内网服务器也没有ansible的yum源,干脆一点,直接tar包安装!!!! 下载软件包 - # 1.python安装 # python2.7安装 [ ...

  7. linux教程:通过编译安装ansible解决apt install ansible后无法安装AWX的莫名问题

    通过编译安装ansible解决apt install ansible后无法安装AWX的莫名问题 通过apt install ansible安装的ansible无法正常部署AWX(ansible的一个w ...

  8. centos7安装ansible

    Centos7安装ansible 一.安装ansible软件 1.安装yum源 rpm -Uvh http://mirrors.ustc.edu.cn/epel/epel-release-latest ...

  9. 阿里云ECS服务器 Centos7.2 使用 yum 安装 ansible 报错

    #####################使用阿里云的ECS服务器Centos7.2系统安装ansible提示安装不上########### 原因 通过Yum安装最新发布版本 通过Yum安装RPMs适 ...

最新文章

  1. android java style_Android 在Java代码中设置style属性--使用代码创建ProgressBar对象
  2. linux中offsetof与container_of宏定义
  3. [转]OpenStack的网络模式
  4. aes密钥扩展java实现,需要使用bouncycastle将AES 256密钥“扩展”为...
  5. Oracle数据库之多表查询
  6. python中change的用法_vue中select的使用、默认选择、onchange/change事件等操作实例
  7. ubuntu服务器安装指南
  8. Java 调用 Python 方法学习笔记
  9. 博达路由器如何配置互联网ip_如何成为技术大牛第七步——路由器下接交换机单臂路由配置方法...
  10. 使用wampserver部署的织梦站点无法登录后台
  11. 8.10 NOIP模拟测试16 Blue+Weed+Drink
  12. python装饰器是什么意思_对Python装饰器的理解
  13. 使用百度地图接口绘制地图
  14. Apache Atlas 数据血缘
  15. Java- 求⼀个三位数,该三位数等与其每位数字的阶乘之和
  16. Django 项目管理
  17. 7——18 day 24 35min 类属性
  18. 微软活动目录逻辑结构分析
  19. HTML实现调用百度在线翻译API
  20. 草邦CMS公共标签调用方法

热门文章

  1. 重磅!MobileNetV3 来了!
  2. CV Code | 本周计算机视觉新出开源代码汇总(含医学图像分割、神经架构搜索、姿态迁移、超分辨率等)...
  3. AAAI 2021 京东科技集团21篇论文
  4. 收藏 | 一文看完吴恩达最新演讲精髓,人工智能部署的三大挑战及解决方案
  5. 收藏 | 一文带你深入理解深度学习最新进展
  6. TensorFlow2.0实战: 入门到进阶深度学习
  7. 深度学习(三十二)半监督阶梯网络学习笔记
  8. 自动驾驶横向运动学分析和非线性问题处理方法
  9. 叠置分析(涉及结果属性和输入图层属性的关系)
  10. verilog存小数_FPGA定点小数计算(Verilog版)第二篇——乘法运算