Detecting deploy failure from Ansistrano Deploy

Viewed 118

We are using Ansistrano Deploy

roles:
  - role: ansistrano.deploy

We want to be able to detect when the deploy fails for any reason (or succeeds), so we can send a Slack notification.

How can we get a return code or similar on this to know the result of the deploy?

1 Answers

Not being familiar under the hood with Ansistrano and more specifically with the error handling already in place inside the role, I'm not entirely sure this will work out of the box.

But my first natural attempt would be to use a block with error handling. This will require to change the way you call the role to use import_role instead of the play-level role: keyword.

Here is a pseudo playbook example to give you the global idea:

- hosts: my_deploy_hosts
  
  tasks:
    - name: deploy my_app with some error control
      block:
        - name: run the ansistrano deploy role
          import_role:
            name: ansistrano.deploy

        - name: If we got there, above ran successfully
          debug:
            msg: "You should send a ++ message to slack"

      rescue:
        - name: If we get into this something went wrong
          debug:
            msg: "Houston. Houston. We have a problem."
Related