可實現:
1)需要ssh和python即可
2)無客戶端
3)功能強大,模組豐富
4)上手太容易,門檻低
5)基於python的開發
6)使用公司比較多,社群活躍
ansible基於ssh協議來管理機器,被管理主機需要開啟ssh服務
ansible執行時配置檔案的查詢順序 :
1、首先檢測ansible_configd變數定義的配置檔案
2、其次檢測當前目錄下的./ansible.cfg檔案
3、再次檢測當前使用者的家目錄下~/ansible.cfg檔案
4、最後檢測/etc/ansible/ansible.cfg檔案
/etc/ansible/ansible.cfg是ansible預設的配置檔案路徑
ansible命令基礎
ansible 主機集合 -m 模組名 -a 模組引數
主機集合:多個用逗號分隔
-m: 模組名 預設是command
-a or --args 模組引數:
其他的引數
-i: inventory檔案路徑,或者可執行的指令碼
-k: 使用互動式的登陸密碼
-e:定義變數
-v: 顯示詳細資訊
ansible模組的使用
ansible all -m command -a 『uptime』 #檢視所有主機的負載
ansible all -m shell -a 'uptime'
#檢視所有機器的負載
切換目錄一般用chdir來 代替cd命令
~]
# ansible all -m copy -a 'src=/etc/hostname dest=/etc/hostname'
~]
# ansible db -m lineinfile -a '
path=
"/etc/my.cnf"
regexp=
"^binlog-format"
line=
"binlog-format = row "
'
~]
# ansible db -m replace -a '
path=
"/etc/my.cnf"
regexp=
"row"
replace=
"mixed"
'
~]
# ansible cache -m setup -a 'filter=ansible_distribution'
~]
# ansible host1 -m file -a "path=/test owner=test group=test mode=0644"
~]# ansible host1 -m file -a "src=/test dest=/testlink owner=root group=root state=link"
Ansible常用模組使用
ansible官方提供了非常多的模組,還有若干第三方模組,我們也可以自己編寫模組。ansible對遠端伺服器的操作實際是通過模組完成的,先將模組拷貝到遠端伺服器,完成操作後,然後在遠端伺服器上刪除該模組。檢視模組幫助資訊 檢視模組列表 ansible doc l 檢視具體模組幫助資訊,以file為例...
ansible 日常使用模組
執行系統命令,不支援命令中帶特殊字元 等 ansible localhost m command a ls root ansible localhost m command a chdir tmp creates 1.txt ls chdir 執行目錄 creates 判定條件,檔案存在則不執行,檔...
Ansible常用模組使用
ansible官方提供了非常多的模組,還有若干第三方模組,我們也可以自己編寫模組。ansible對遠端伺服器的操作實際是通過模組完成的,先將模組拷貝到遠端伺服器,完成操作後,然後在遠端伺服器上刪除該模組。檢視模組幫助資訊 檢視模組列表 ansible doc l 檢視具體模組幫助資訊,以file為例...