1. 程式人生 > >Ansible學習 安裝

Ansible學習 安裝

效率 exe x86_64 環境 name ces 版本 選擇 body

  對於運維人員來說,自動化工具是日常工作中比不可少的。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"
}

Ansible學習 安裝