Ansible学习 安装

  对于运维人员来说,自动化工具是日常工作中比不可少的。Ansible是一个很好的自动化工具。

  Ansible默认使用SSH协议管理机器,在管理主机上安装Ansible,管理主机和被管理主机只要安装了python,即可使用

1、安装,管理主机环境如下

操作系统:

[root@client01 ansible]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)

python版本:

[root@client01 ansible]# python -V
Python 2.7.5

 

查看yum是否配置完成

[root@client01 ansible]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.zju.edu.cn
* updates: mirrors.aliyun.com
repo id                                                              repo name                                            status
!base/7/x86_64                                                       CentOS-7 - Base                                      9,591
!extras/7/x86_64                                                     CentOS-7 - Extras                                    327
!updates/7/x86_64                                                    CentOS-7 - Updates                                   1,573
repolist: 11,491   

2、安装ansible

yum install ansible

安装完查看ansible版本

[root@client01 ansible]# ansible --version
ansible 2.4.1.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]

3、初次尝试

[root@client01 ansible]# ansible all -i 192.168.144.130, -m ping -k
SSH password:
192.168.144.130 | SUCCESS => {
"changed": false,
"failed": false,
"ping": "pong"
}

-i 选项后可以接主机,也可以接inventory文件(hosts文件),-m选择执行模块,-k输入被管理主机密码

如果在被管理主机上配置了管理主机的公钥,则不需要再通过-k输入密码,提高自动化执行效率

[root@client01 ansible]# ansible all -i 192.168.144.130, -m ping
192.168.144.130 | SUCCESS => {
"changed": false,
"failed": false,
"ping": "pong"
}

 

posted @ 2018-01-02 18:02  pigwan7  阅读(154)  评论(0编辑  收藏  举报