天天看點

ansible 梁

一、連接配接兩台機器或多台

ssy-keygen -t rsa 生成公鑰和私鑰

ssh-copy -id -i 公鑰 [email protected] 生成的公鑰,傳給伺服器

ssh [email protected] 确認連接配接上另一個伺服器

二、ansible常用子產品

1.遠端指令子產品( command / script / shell )

command 作為 Ansible 的預設子產品,可以運作遠端權限範圍所有的 shell 指令,不支援管道符。

shell > ansible Client -m command -a "free -m" # 檢視 Client 分組主機記憶體使用情況

script 的功能是在遠端主機執行主要端存儲的 shell 腳本檔案,相當于 scp + shell 組合。

shell > ansible Client -m script -a "/home/test.sh 12 34" # 遠端執行本地腳本

shell 的功能是執行遠端主機上的 shell 腳本檔案,支援管道符。
shell > ansible Client -m shell -a "/home/test.sh"           # 執行遠端腳本           
  1. copy 子產品(實作主要端向目标主機拷貝檔案,類似于 scp 功能)
    shell > ansible Client -m copy -a "src=/home/test.sh desc=/tmp/ owner=root group=root mode=0755"   # 向 Client 組中主機拷貝 test.sh 到 /tmp 下,屬主、組為 root ,權限為 0755           
  2. stat 子產品(擷取遠端檔案狀态資訊,atime/ctime/mtime/md5/uid/gid 等資訊)

    shell > ansible Client -m stat -a "path=/etc/syctl.conf"

  3. get_url 子產品(實作在遠端主機下載下傳指定 URL 到本地,支援 sha256sum 檔案校驗)

例:

上一篇: Ansible小記
下一篇: ansible學習

繼續閱讀