Is there a Pattern for having one machine in a cluster perform an action?

Hi! I have a few django servers . . . I would like to run a syncdb in my playbook, but only need/want one of the django servers in the group to run that play . . . do I need to designate a machine to run that or is there an easier way?

Thanks!!

Ansible 1.7 added the new "run_once" keyword so that a given action
will only run once for that host list.

Super-sweet! For anyone who is wondering, the “full” documentation is in here: http://docs.ansible.com/playbooks_delegation.html

Thanks!!!

run_once does that for a task, yes.

Long-form, may be useful, as well;

all of em

  • hosts: webservers
    tasks:
  • blarg
  • blarg

just on the head node

  • hosts: webservers[0]
    tasks:
  • blarg
  • blarg

now some others

  • hosts: dbservers
    tasks:
  • blarg