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


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"
}

相关内容

    暂无相关文章