ansible ad-hoc常用模块汇总

ad-hoc常用模块(ansible ad-hoc调用模块的选项)

yum_repository # 配置yum仓库

yum_repository: 配置YUM仓库模块
[root@ansible ~]# ansible nfs -m yum_repository -a 'name=nginx description="Nginx YUM repo" baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ enabled=yes gpgcheck=no gpgkey=https://nginx.org/keys/nginx_signing.key'

 

yum # 安装软件

ansible backup -m yum -a 'name=rsync state=present'  : https://www.baimeidashu.com/8117.html

copy # 变更配置文件

ansible backup -m copy -a "src=1.txt dest=/root/ owner=ntp group=ntp mode=777"    : https://www.baimeidashu.com/8112.html

group user 模块 #

、  https://www.baimeidashu.com/8119.html

file # 建立目录或文件 

ansible backup -m file -a 'path=/root/a.txt state=touch owner=www group=www mode=0600'

https://www.baimeidashu.com/8121.html

 

systemd  service # 启动与停止服务

ansible backup -m systemd -a 'name=rsyncd state=started enabled=yes' : https://www.baimeidashu.com/8122.html

mount # 挂载设备

ansible web01 -m mount -a 'src=172.16.1.31:/code/blog path=/mnt fstype=nfs state=absent'

https://www.baimeidashu.com/8123.html

command # 执行shell命令(不支持管道等特殊字符) 

ansible web01 -m command -a 'ifconfig eth0'

 ansible web01 -m command -a 'nginx -t'

shell # 执行shell命令

ansible web01 -m shell -a 'ps axu|grep nginx'

scripts # 执行shell脚本

ansible web01 -m script -a '/root/1.sh' # 1.sh在ansible主机上

get_url #下载软件

get_url:
url: 链接
dest: 下载到本地的位置
[root@ansible ~]# ansible web01 -m get_url -a 'url=https://img10.360buyimg.com/n1/g12/M00/08/03/rBEQYVGZ8F0IAAAAAAIapXb0bREAABlfAPtsn0AAhq9958.jpg dest=/root/'

firewalld #防火墙

firewalld 停止防火墙
[root@ansible ~]# ansible web01 -m systemd -a 'name=firewalld state=stopped enabled=no'

selinux #selinux

[root@ansible ~]# ansible web01 -m selinux -a 'policy=targeted state=disabled'

cron # 定时任务

minute: 分钟 */5
job: 定时任务命令
state: present 添加(不写默认就是创建或者添加)
absent 删除

[root@ansible ~]# ansible web01 -m cron -a 'name=ntpdate minute=*/5 job="ntpdate ntp1.aliyun.com &>/dev/null"'
[root@web01 ~]# crontab -l

删除定时任务:
[root@ansible ~]# ansible web01 -m cron -a 'name=ntpdate1 state=absent'

 

 

欢迎来撩 : 汇总all

白眉大叔

关于白眉大叔linux云计算: 白眉大叔

热门文章