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

1255

ansible安装

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

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

    1
    sudo apt-get install ansible
  • MAC使用pip安装

    1
    sudo pip install ansible

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

ansible配置

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

我自己的配合文件:

1
2
3
4
5
6
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文件编辑:

1
2
3
4
5
6
vim ~/.ansible/hosts

[test]
192.168.1.1
192.168.1.2
192.168.1.3

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

使用sshpass

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

1
2
3
4
5
6
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,都可以使用下面的测试:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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"
}

本文由 千寻啊千寻创作。可自由转载、引用,但需署名作者且注明文章出处。


收藏文章
表情删除后不可恢复,是否删除
取消
确定
图片正在上传,请稍后...
评论内容为空!
还没有评论,快来抢沙发吧!
按钮 内容不能为空!
立刻说两句吧! 查看0条评论