页首自改代码

Hey, Nice to meet You.  why ?

☆☆☆所谓豪杰之士,必有过人之节.人情有所不能忍者,匹夫见辱,拔剑而起,挺身而斗,此不足为勇也,天下有大勇者,猝然临之而不惊,无故加之而不怒.此其所挟持者甚大,而其志甚远也.          
返回顶部

Ansible常用模块

帮助命令

# ansible-doc -l # 列出所有可用模块;

# ansible-doc -s MODULE_NAME # 获取具体模块的使用方法;

 

模块案例

command

# 命令模块,默认模块(不写时默认有),用于远程执行命令;

# ansible all -a 'date'

shell

# 执行远程服务器上的脚本

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

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

# 将master上文件批量下发,src为master上的文件路径,dest为目标服务器上的文件路径

# 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

posted on 2019-04-11 15:22  罗穆瑞  阅读(192)  评论(0编辑  收藏  举报

导航