首頁 > 軟體

RHEL 6.6下安裝Ansible

2020-06-16 17:09:28

ansible是新出現的自動化運維工具,基於Python開發,集合了眾多運維工具(puppet、cfengine、chef、func、fabric)的優點,實現了批次系統設定、批次程式部署、批次執行命令等功能。(百度百科),2015年RedHat收購ansible。

主機環境:

OS:Red Hat Enterprise Linux Server release 6.6 (Santiago) x86_64
IP:172.16.10.180
Python 2.6.6
註:作業系統最小化安裝

節點:

OS:Oracle Linux Server release 5.8
IP:172.16.10.10、172.16.10.200
Python 2.4.3

1、安裝開發工具:

# yum -y groupinstall "Development tools"

2、安裝six、yaml

# rpm -ivh python-six-1.9.0-1.el6.pp.noarch.rpm 
# rpm -ivh python-yaml-3.09-3.el6.rf.x86_64.rpm

3、安裝ansible

# yum install ansible
註:受控節點需要安裝python-simplejson

4、生成秘鑰檔案

# ./sshUserSetup.sh -user root -hosts "172.16.10.10 172.16.10.200"
輸入yes和兩台主機的root密碼即可完成172.16.10.180->172.16.10.10、172.16.10.180->172.16.10.200的驗證
 
或者:
# ssh-keygen -t rsa -P ''
在/root/.ssh/下生成檔案id_rsa.pub,拷貝到所有受控機並執行以下操作:
# cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
# chmod 600 /root/.ssh/authorized_keys

5、修改hosts檔案

# cd /etc/ansible/
# cat /etc/ansible/hosts
...
[dbservers]
172.16.10.10
172.16.10.200

6、修改ansible.cfg檔案

# cat /etc/ansible/ansible.cfg
...
remote_port = 36000
...
private_key_file = /root/.ssh/id_rsa

7、測試

# ansible all  -m ping
# all指所有定的主機
172.16.10.10 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
172.16.10.200 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
 
# ansible dbservers -m ping     
172.16.10.200 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
172.16.10.10 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

8、常見錯誤:

A、"msg": "Error: ansible requires the stdlib json or simplejson module, neither was found!"
受控端需要安裝python-simplejson
 
B、FAILED => module command not found in configured module paths. Additionally, core modules are missing. If this is a checkout, run 'git submodule update --init --recursive' to correct this problem.
安裝過程有問題,重新安裝
 
C、FAILED => to use the 'ssh' connection type with passwords, you must install the sshpass program
安裝sshpass

下面關於Ansible的文章您也可能喜歡,不妨參考下:

CentOS下部署Ansible自動化工具  http://www.linuxidc.com/Linux/2017-06/144430.htm

在 CentOS 7 中安裝並使用自動化工具 Ansible  http://www.linuxidc.com/Linux/2015-10/123801.htm

CentOS 7上搭建Jenkins+Ansible服務  http://www.linuxidc.com/Linux/2016-12/138737.htm

Linux下原始碼編譯安裝Ansible及排錯記錄  http://www.linuxidc.com/Linux/2017-03/141427.htm

Ansible基礎—安裝與常用模組  http://www.linuxidc.com/Linux/2017-02/140216.htm

Ansible設定及使用  http://www.linuxidc.com/Linux/2017-03/142121.htm

自動化運維工具之 Ansible 介紹及安裝使用  http://www.linuxidc.com/Linux/2016-12/138104.htm

自動化運維之Ansible詳解  http://www.linuxidc.com/Linux/2017-03/142191.htm

Ansible入門notify和handlers  http://www.linuxidc.com/Linux/2017-02/140871.htm

CentOS 6.5安裝自動化工具Ansible和圖形化工具Tower  http://www.linuxidc.com/Linux/2017-03/141422.htm


IT145.com E-mail:sddin#qq.com