Think before you speak, read before you think.

ansible tasks判断一个主机是不是在某group

hosts文件里是这样写的

[backup_tar]
host1
host2

[backup_notar]
host3
host4

针对 backup_tar 中的 hosts 只执行某条 task

- cron: name="backup" minute=0 hour=4
        user="root" job="/bin/sh /root/mysql_backup.sh full >> /dev/null 2>&1" backup=yes
  when: inventory_hostname in groups['backup_tar']

参考:https://groups.google.com/forum/#!topic/ansible-project/lr7nXyGw0UY


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *