Search code examples
symfonyansibledevopsdoctrine-migrations

How to run ansible command on a single server during deployment to many servers?


I'm using Ansistrano to deploy my Symfony2 application. Application uses Doctrine, oso I'm also using DoctrineMigrationsBundle. Now, my problem is that I would like to run database migration at the end of deployment process, but I want this operation to be called only once, and I know that ansible by default run all commands from playbook on all given servers. Is there any way to tell ansible to run a specific command on a single server from a set of all servers to which I deploy my code?


Solution

  • There's run_once for this.

    Example from the docs:

    ---
    # ...
    
      tasks:
    
        # ...
    
        - command: /opt/application/upgrade_db.py
          run_once: true
    
        # ...