Ansible--Ad-Hoc

什麼是Ad-Hocweb

  • (這實際上是一個概念性的名字,是相對於寫Ansible playbook來講的。相似於在命令行敲入shell命令和寫shell scripts二者之間的關係)...
  • 若是咱們敲入一些敲入一些命令去比較快的完成一些事情,而不須要將這些執行的命令特別保存下來,這樣的命令叫作ad-hoc命令

 

ansible atlanta -a "/sbin/reboot" -f 10

這個命令,atlanta是一個組,這個組裏面有不少服務器,"/sbin/reboot" 命令會fork出10個子進程(bash)shell

以並行的方式執行reboot命令。bash

 

指定用戶執行shell命令服務器

ansible atlanta -a "/usr/bin/foo" -u username

使用sudospa

ansible atlanta -a "/usr/bin/foo" -u username --sudo [--ask-sudo-pass]

 

文件管理命令行

建立文件夾code

ansible webservers -m file -a "dest=/path/to/cmode=755 owner=mdehaan group=mdehaan state=directory"

拷貝文件server

ansible atlanta -m copy -a "src=/etc/hosts dest=/tmp/hosts"
本站公眾號
   歡迎關注本站公眾號,獲取更多信息