ansible 自动化运维(三)

copy模块

下发配置文件到管控机上。

ansible  web  -m copy   -a  'conternt=12121212'   dest='/tmp/1 ower=root mode 660'

把内容加入1 文件汇总

ansibke web -m   copy -a  ' src=/tmp/1     dest=tmp/2 remote src=yes ower=root mode=660'

远程拷贝文件

file模块

经常使用的 创建文件 或者创建目录

 

 

 

 

 

 lineinfile  模块

修改配置文件

如修改appchi服务

 

 修改监听端口号

1.修改文件的路径

使用copy 对配置文件进行备份

ansible web -m   copy  -a      ‘src =/etc/httpd/conf/httod.conf       dest=/etc/httpd/conf/httpd.conf_org  remote src=yes’

使用lineinfile模块修改配置文件

1 ansible web -m  lineinfile -a ‘path=/etc/httpd/httpd.conf  line="0000"’

增加一行

2.ansible web -m lineinfile -a 'path=etc/httpd/httpd.conf  regexp ="Listen 80" line="Listten 8080"'

严格匹配 替换

3.ansible web -m lineinfle -a ‘path=/etc/httpd/httpd.conf regexp="0000"  state=absent’

删除指定

启动服务

ansible web -m service  -a ‘ name=httpd state =restarted’

 建立周期性任务

ansbile web -m   cron -a   ‘ minute=“*/10”    job="/bin/echo hello"  name="test cron job"’

hour  

present   创建

absent   删除

parted 对硬盘进行分区

 

 synchronize模块

 

 yum的模块

 

关闭服务 

ansible   web   -m  service -a ‘name=vsftpd   state=stoped’

卸载服务

ansible web -m   yum -a ‘name=vsftpd   state=absent’

安装服务

anbsible web  -m   yum -a ‘name=vsftpd   state  present’

 

posted @ 2020-12-04 14:43  yanglc  阅读(142)  评论(0编辑  收藏  举报