文章出處

一、簡介

Ansible is a radically simple configuration-management, application deployment, task-execution, and multinode orchestration engine.

Design Principles

Have a dead simple setup process and a minimal learning curve
Be super fast & parallel by default
Require no server or client daemons; use existing SSHd
Use a language that is both machine and human friendly
Focus on security and easy auditability/review/rewriting of content
Manage remote machines instantly, without bootstrapping
Allow module development in any dynamic language, not just Python
Be usable as non-root
Be the easiest IT automation system to use, ever.

 


二、安裝

ansible依賴于Python 2.6或更高的版本、paramiko、PyYAML及Jinja2。

2.1 編譯安裝

解決依賴關系

# yum -y install python-jinja2 PyYAML python-paramiko python-babel python-crypto
# tar xf ansible-1.5.4.tar.gz
# cd ansible-1.5.4
# python setup.py build
# python setup.py install
# mkdir /etc/ansible
# cp -r examples/* /etc/ansible

2.2 rpm包安裝
# yum install ansible

注意:不同版本的ansible的功能差異可能較大。


三、簡單應用

ansible通過ssh實現配置管理、應用部署、任務執行等功能,因此,需要事先配置ansible端能基于密鑰認證的方式聯系各被管理節點。

 

ansible <host-pattern> [-f forks] [-m module_name] [-a args]
-m module:默認為command


ansible-doc: Show Ansible module documentation
-l, --list List available modules
-s, --snippet Show playbook snippet for specified module(s)

實例應用:

ssh-keygen -t rsa -P ''    

ssh-copy-id -i .ssh/id_rsa.pub root@103.242.135.25   

一、定義host

注:一個主機可以定義于多個不同組          解決通信問題:1.直接可以編輯文件加入密碼  2.可以基于ssh秘鑰認證方式進行

ping模塊使用,也可以使用單個主機或者已定義好的組名,這里使用all,代表所有主機

command模塊使用,創建目錄!可以使用linux系統命令

shell模塊使用,命令中執行管道,重定向之類的需使用shell模塊

shell模塊和command模塊的區別

cpoy模塊使用,cp本地的1.html到遠端主機的/root目錄下,必須使用絕對路徑

cron模塊,批量執行定時任務

state=absent 刪除指定name對應的任務計劃

fetch拉取模塊,將遠端的文件拉到本地,和copy模塊相反

file模塊使用,創建目錄,并賦予權限

用file模塊,做軟連接

使用yum模塊,批量安轉tree工具包

ansible all -m yum -a "name=tree state=installed"

name:指定安裝包名

state:指定方式,安裝或卸載

安裝: install (`present' or `installed', `latest'),

卸載:remove (`absent' or `removed') a package

ansible all -m yum -a "name=httpd* state=latest"       #安裝httpd服務

service模塊使用,關閉服務:stopped 開啟服務:started

 


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()