Ansible經常使用模塊

幫助命令 mysql

# ansible-doc -l # 列出全部可用模塊; web

# ansible-doc -s MODULE_NAME # 獲取具體模塊的使用方法; sql

 

模塊案例 shell

command 服務器

# 命令模塊,默認模塊(不寫時默認有),用於遠程執行命令; ui

# ansible all -a 'date' spa

shell 操作系統

# 執行遠程服務器上的腳本 server

# ansible all -m shell -a "/home/a.sh " crontab

scripts

# 在遠程服務器上執行主控服務器腳本

# ansible all -m scripts -a "/home/a.sh arg1 arg2"

cron

# ansible all -m cron -a "name='test' hour='2-5' minute='*/5' day='1' month='3,4' weekday='1' job='ls -l' user=tom"

# ansible all -a 'crontab -l -u tom'

copy

# ansible all -m copy -a 'src=/etc/fstab dest=/tmp/fstab.ansible owner=root mode=640'

# 將目標文件內容替換爲content中內容

# ansible all -m copy -a 'content="Hello Ansible\nHi\n" dest=/tmp/kazihuo.ansible'

synchronize

# ansible all -m synchronize -a "src=/tmp/test/ dest=/tmp/test/"

file

# ansible all -m file -a 'owner=mysql group=mysql mode=777 path=/tmp/kazihuo.ansible'

group

# ansible webserver -m group -a 'name=mysql gid=306 system=yes'

user

# ansible all -m user -a 'name=mysql uid=306 system=yes group=mysql'

# ansible all -m user -a "name=mysql state=absent remove=yes" #刪除用戶

link

# ansible all -m file -a 'path=/tmp/fstab.link src=/tmp/fstab.ansible state=link'

ping

# ansible all -m ping

service

# ansible all -a 'systemctl status httpd.service'

# ansible all -m service -a 'enabled=true name=httpd state=started'

yum

# ansible all -m yum -a 'name=zsh state=present'

# ansible dbserver -m yum -a 'name=httpd state=absent'

setup

# 收集遠程主機的facts(每一個被管理節點在接收並運行管理命令以前,會將本身主機相關信息,如操做系統版本、IP地址等報告給遠程的ansible主機)

# ansible all -m setup

相關文章
相關標籤/搜索