Ansible常用命令

2021-08-07 19:53:13 字數 1080 閱讀 1998

-------------old

# 檢查主機連線

# ansible caoguo -m ping

# 執行遠端命令

# ansible caoguo -m command -a 'uptime'

# 執行主控端指令碼

# ansible caoguo -m script -a '/etc/ansible/script/test.sh'

# 執行遠端主機的指令碼

# ansible caoguo -m shell -a 'ps aux|grep zabbix'

# 類似shell

# ansible caoguo -m raw -a "ps aux|grep zabbix|awk ''"

# 建立軟鏈結

# ansible caoguo -m file -a "src=/etc/resolv.conf dest=/tmp/resolv.conf state=link"

# 刪除軟鏈結

# ansible caoguo -m file -a "path=/tmp/resolv.conf state=absent"

# 複製檔案到遠端伺服器

# ansible caoguo -m copy -a "src=/etc/ansible/ansible.cfg dest=/tmp/ansible.cfg owner=root group=root mode=0644"

------------new

批量後台啟動指令碼並輸出到日誌

ansible ipaddress -m command -a 'nohup python -u /home/ceshi/sichuan/xl.py 0 > out.log 2>&1 &'

批量複製檔案到test3組伺服器

ansible test3 -m copy -a 'src=/root/qd/shandong dest=/home/ceshi/'

批量刪除test5組伺服器的某個檔案

ansible  test5 -m shell -a "rm -rf /home/ceshi/

anhui

" -i '/etc/ansible/hosts'

ansible常用命令

ad hoc常用命令是用來解決一些常用的簡單的配置命令,而且這些命令的執行速度很快。adhoc可以不用寫playbooks,使用方便簡單。man ansible ansible f forks m module a args arguments pattern 組名,或者主機名,匹配hosts檔案。...

ansible常用命令

ansible 預設提供了很多模組來供我們使用。在 linux 中,可以通過 ansible doc l 命令檢視到當前 ansible 都支援哪些模組,通過 ansible doc s 模組名 又可以檢視該模組有哪些引數可以使用 常用模組 所有示例以webserver為匹配目標主機。1.ping ...

Ansible入門 常用命令

ansible是用來批量配置伺服器的,達到配置自動化的目的。ansible使用ssh協議,無需配置agent,開箱即用。saltstack需要安裝agent,但部署速度快。核心模組 core,實現批量處理的命令 主機清單 etc ansible hosts 指令碼 playbook 大批量主機 yu...