每日学习-ansible任务委派与本地操作
ansible通过使用delegate_to关键字委派任务到指定的机器上运行 使用示例: 1、hosts配置 - name: add host record to DC server shell: 'echo "192.168.10.12 node2" >> /etc/hosts' - name: add host record to all server shell: 'echo "192.168.10.12 node2 " >> /etc/hosts' delegate_to: 192.168.10.100 2、ntp-server配置 ntp-server执行server配置,nep-client执行定时任务同步server。 - name: install ntp shell: yum -y install ntp - name: stop all ntp_install server shell: systemctl stop ntpd && systemctl disable ntpd - name: config ntp server template: src=templates/ntp.conf dest=/etc/ntp.conf run_once: true delegate_to: "{{ntp.ntp_server}}" - name: start ntp