Ansible 使用基础 ( 一 )

Ansible 使用基础 ( 一 )

安装


dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y     # 安装epel扩展源

dnf install ansible         # dnf安装ansible

ansible --version   # 校验安装


使用 sshpass 批量实现基于 key 验证:

    ssh-keygen      #生成公私钥
    ssh-copy-id x.x.x.x     #每台被控主机都需要公私钥交互
ps:在 root 下操作,便于之后的实验使用


修改 Ansible 中 hosts 文件,配置管理主机【/etc/ansible/hosts】

在 hosts 文件末尾处添加管理主机组和主机 IP 地址: 使用 [xxxx] 描述组名,x.x.x.x 描述主机 IP 地址,例:

[web]
192.168.162.222
192.168.162.220 


使用 Ansbile 中 Ping 模块测试 ssh 验证是否成功:

使用命令    ansible all -m ping ;ps: ansible    xxxx【管理主机】 -m  xxxx【模块名】  -a  xxxx【参数】

192.168.162.222 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}  # 成功

Ansihosts ble 支持的模式

作用

实例

所有主机

all

所有主机

*

并集

dev:staging

交集

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值