Ansible:
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.1.51.26
ansible xyhservers -m yum -a "name=ntp"
ansible xyhservers -m service -a 'state="started" name="ntpd" enabled="yes"'
ansible -i /tmp/hosts.bak xyhntpcore1 -m ping
ansible -i /tmp/hosts.bak xyhntp -m shell -a 'echo "ntpdate -b 10.0.54.54 >> /root/ntp.log" >> /etc/rc.d/rc.local'
ansible -i /tmp/hosts.bak xyhntp -m cron -a 'minute="*/5" job="/usr/sbin/ntpdate -b 10.0.54.54" name="cron job"'
ansible xyhservers -m shell -s 'sed -i '/^10/d' /var/spool/cron/root'
定时任务路径:/var/spool/cron/root
ansible xyhservers -i /tmp/new 1.txt -m authorized_key -a "user=root key='{{ lookup('file', '/root/.ssh/id_rsa.pub') }}'" -k
ansible xyhservers -m user -a 'name=hlwztprd shell=/bin/bash home=/home/hlwztprd/ state=present'
ansible xyhservers -m shell -a 'echo -e "nameserver 10.0.67.23\n nameserver 10.0.67.24" >> /etc/resolv.conf'
批量免密:
先编辑好txt文档如下:
1.[yidongzhanye]
10.0.40.5
10.0.40.8
10.0.40.9
10.0.40.0
2.ansible yidongzhanye -i /tmp/new 1.txt -m authorized_key -a "user=root key='{{ lookup('file', '/root/.ssh/id_rsa.pub') }}'" -k
-k 输入密码
-i:指定路径 默认不需要写