Linux安裝配置Ansible

http://docs.ansible.com/intro_installation.html#installation

對於Ansible,官方文檔是這樣描述的:

Ansible is trivially easy to run from a checkout, root permissions are not required to use it and there is no software to actually install for Ansible itself. No daemons or database setup are required. Because of this, many users in our community use the development version of Ansible all of the time, so they can take advantage of new features when they are implemented, and also easily contribute to the project. Because there is nothing to install, following the development version is significantly easier than most open source projects.

ansible是用python開發的。

其實準確的說ansible只提供了一個框架,它要基於很多其他的python模塊才能工作,所以在安裝ansible的時候你要再裝很多其他的依賴包的。

優點:

1.使用者可以開發自己的模塊,放在裏面使用;

2.無需在客戶端安裝agent,更新時,只需在主控機上進行一次更新即可;

3.批量任務執行可以寫成腳本,而且不用分發到遠程就可以執行。

建議:python版本在2.6版本以上,已經是2.6了,則無需升級


服務器:192.168.11.52


python模塊安裝

easy_install pycrypto
easy_install PyYAML 
easy_install Jinja2
easy_install paramiko
easy_install simplejson

ansible安裝

wget https://github.com/ansible/ansible/archive/v1.7.2.tar.gz
tar -zxvf v1.7.2.tar.gz
cd ansible-1.7.2
python setup.py install

SSH免密鑰登錄設置

#生成公鑰/私鑰

[root@mongo02 ~]#ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''

#分發到其他服務器

[root@mongo02 ~]#ssh-copy-id -i ~/.ssh/id_rsa.pub root@mongo01
ssh mongo01
chmod 600 /root/.ssh/authorized_keys

拷貝,生成ansible配置文件

配置文件/etc/ansible/ansible.cfg

mkdir -p /etc/ansible
cp ansible-1.7.2/examples/ansible.cfg /etc/ansible/

配置文件/etc/ansible/hosts

vim /etc/ansible/hosts
#添加
[test]
192.168.11.51
192.168.11.55

測試

ansible test -m command -a 'uptime

wKiom1VcSjiCcLWsAADK6e4NhQk527.jpg

用來測試遠程主機的運行狀態

ansible test -m ping

查看所有的參數

ansible-doc -l

更多模塊測試,請訪問:

http://chason.blog.51cto.com/9078447/1653174





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章