ansible的安装配置和配合sshpass的使用

ansible安装

官网安装文档:https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-the-control-machine

  • centos使用yum安装
sudo yum install ansible
  • Ubuntu使用apt-get安装
sudo apt-get install ansible
  • MAC使用pip安装
sudo pip install ansible

其他安装方式,参考官网安装文档吧。

ansible配置

官网配置文件介绍:https://docs.ansible.com/ansible/latest/installation_guide/intro_configuration.html

我自己的配合文件:

vim ~/.ansible.cfg

[defaults]
hostfile=$HOME/.ansible/hosts
deprecation_warnings=False
#host_key_checking=Falses
  • hostfile:host配置文件的目录,默认是在/etc/ansible/hosts
  • deprecation_warnings:不要警告信息

hosts配置

在上面配置信息hostfile的路径找到hosts文件编辑:

vim ~/.ansible/hosts

[test]
192.168.1.1
192.168.1.2
192.168.1.3

上面这种配置方式,是需要添加sshkey才可以使用的,这种使用方式更爽一些。

使用sshpass

如果想使用用户名密码来配置ansible,也是可以的,一样是需要在hostfile的路径找到hosts文件编辑:

vim ~/.ansible/hosts

[test]
192.168.1.1 ansible_ssh_user=用户名 ansible_ssh_pass=密码
192.168.1.2 ansible_ssh_user=用户名 ansible_ssh_pass=密码
192.168.1.3 ansible_ssh_user=用户名 ansible_ssh_pass=密码

测试一下

无论是使用sshkey还是使用sshpass,都可以使用下面的测试:

ansible test -m ping

192.168.1.1 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
192.168.1.2 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
192.168.1.3| SUCCESS => {
    "changed": false,
    "ping": "pong"
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值