灰灰鼠精灵 发表于 2018-7-29 12:41:50

ansible命令(二)

  要求:linux CentOS>  两台机器:192.168.1.2 192.168.1.3

[*]  创建一个脚本放在/tmp目录下
  vim /tmp/test.sh
  #!/bin/bash
  echo `date` > /tmp/a.txt
  2. 分发到各个节点上
  ansible testhost -m copy -a "src=/tmp/test.sh dest=/tmp/test.sh mode=0755"
  3.执行节点脚本
  ansible testhost -m shell -a "/tmp/test.sh"
  4.ansible 添加crontab定时任务
  添加crontab
  ansible testhost -m cron -a "name='test cron' job='/bin/touch /tmp/12.txt' weekday=6"
  tip:分钟minute 小时hour 日期day 月份month
  删除crontab
  ansible testhost -m cron -a "name='test cron' state=absent"
  5.ansible rpm包 服务管理
  安装httpd
  ansible testhost -m yum -a "name=httpd"
  name后可以加入state=installed
  管理httpd 设置开机启动
  ansible testhost -m service -a "name=httpd state=started enabled=yes"
  文档使用
  ansible-doc -l 列出所有的模块
  ansible-doc cron 查看指定模块的文档
页: [1]
查看完整版本: ansible命令(二)