Ansible 使用筆記

2021-07-26 03:59:46 字數 2836 閱讀 2442

平台運維需要,開始使用ansible使自動化管理的一些記錄。

ansible 172.16

.0.14 -m file -u root -a "dest=/mnt/test.x mode=600 owner=eseals group=wheel"

ansible 172.16

.0.14 -m file -u root -a "dest=~/ansib/test01/test02 mode=755 owner=root state=directory"

# 效果同 mkdir -p

ansible 172.16

.0.14

-m shell -u root -a

"mkdir -p ~/ansib/test01/test02"

ansible是一種輕量級管理工具,同類軟體有(puppet、cfengine、chef、func、fabric) ,同這些軟體相比,它完全不用安裝,甚至於管理端也不用安裝,在linux下配置好python即可。 —— [github原始碼]

使用ansible 管理主機,採用證書認證方式會方便許多。

ssh-keygen -t rsa -b 4096

-f ./id_rsa # 製作金鑰對

ssh-keygen -e

-f ./id_rsa # 顯示公鑰

ssh-copy-id -i ./id_rsa [email protected]

ad-hoc commands使用方法:

ansible all -a

"/bin/echo 'hello,world'"

# 所有客戶端顯示..

ansible all -m shell -u root -a

"echo 'hello,world'"

ansible all -m ping -u root # ping 模組

ansible kvm -u root -a

"/bin/ping -c3 www.g.cn"

#ansible 直接執行命令

ansible 172.16

.0.14 -m copy -u root -a

"src=/mnt/test.x dest=/mnt/"

ansible 172.16

.0.14 -u root -a

"/bin/rm /mnt/test.x"

ansible jboss_172 -m shell -u root -a

"reboot" -f 10

主機定義方法

主要引數:

ansible_ssh_host

將要連線的遠端主機名.與你想要設定的主機的別名不同的話,可通過此變數設定.

ansible_ssh_port

ssh埠號.如果不是預設的埠號,通過此變數設定.

ansible_ssh_user

預設的 ssh 使用者名稱

ansible_ssh_pass

ssh 密碼(這種方式並不安全,我們強烈建議使用 --ask-pass 或 ssh 金鑰)

ansible_sudo_pass

sudo 密碼(這種方式並不安全,我們強烈建議使用 --ask-sudo-pass)

ansible_sudo_exe (new

inversion

1.8)

sudo 命令路徑(適用於1.8及以上版本)

ansible_connection

與主機的連線型別.比如:local, ssh 或者 paramiko. ansible 1.2 以前預設使用 paramiko.1

.2 以後預設使用 'smart','smart' 方式會根據是否支援 controlpersist, 來判斷'ssh' 方式是否可行.

ansible_ssh_private_key_file

ssh 使用的私鑰檔案.適用於有多個金鑰,而你不想使用 ssh **的情況.

ansible_shell_type

目標系統的shell型別.預設情況下,命令的執行使用 'sh' 語法,可設定為 'csh' 或 'fish'.

ansible_python_interpreter

目標主機的 python 路徑.適用於的情況: 系統中有多個 python, 或者命令路徑不是"/usr/bin/python",比如 \*bsd, 或者 /usr/bin/python

不是 2.x 版本的 python.我們不使用 "/usr/bin/env" 機制,因為這要求遠端使用者的路徑設定正確,且要求 "python" 可執行程式名不可為 python以外的名字(實際有可能名為python26).

與 ansible_python_interpreter 的工作方式相同,可設定如 ruby 或 perl 的路徑....

ansible 模組眾多,常用幫助資訊ansible-doc –list

例如想查詢authorized相關模組,執行命令ansible-doc -l | grep auth

檢視某個模組詳細資訊,可以使用以下

ansible-doc -s authorized_key

生成乙個腳注1.

[toc]來生成目錄:

這裡是腳注的 內容. ↩

Vim 使用筆記

set hlsearch set nohlsearch 搜尋後清除上次的加亮 nohl nohlsearch 拷貝 很有用的一句話,規定了格式選項,讓它換行不自動空格 set formatoptions tcrqn set fo r set noautoindent 再 shift insert 正...

xemacs使用筆記

xemacs使用筆記 xemacs emacs的下一代,由lucid原創 from debian參考手冊.由於不知道什麼時候刪掉了emacs的乙個重要檔案.每次都沒法安裝好.突然發現了xemacs,於是決定使用看看.本人還是菜鳥,僅供交流 我使用的ubuntu系統,所以就直接apt get inst...

TreeView使用筆記

treeview由節點構成,建樹通過對treeview.items屬性進行操作。items是乙個ttreenodes物件,這是乙個ttreenode集。一 針對ttreenodes,也就是 treeview.items,有這些屬性 1 count,節點個數。2 item index 通過index得...