Skip to content

Instantly share code, notes, and snippets.

@matsimitsu
Created February 4, 2016 17:48
Show Gist options
  • Save matsimitsu/8cf52ab22287cdf2221a to your computer and use it in GitHub Desktop.
Save matsimitsu/8cf52ab22287cdf2221a to your computer and use it in GitHub Desktop.
Ansible script to notify AppSignal of new deploy
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2014 Robert Beekman <[email protected]>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION = '''
---
module: appsignal_deployment
version_added: "1.2"
author: Robert Beekman
short_description: Notify AppSignal about app deployments
description:
- Notify AppSignal about app deployments (see http://docs.appsignal.com/push-api/deploy-marker.html)
options:
api_key:
description:
- API key.
required: true
name:
description:
- Name of the application
required: true
environment:
description:
- The environment for this deployment
required: true
revision:
description:
- A revision number (e.g., git commit SHA)
required: true
user:
description:
- The name of the user/process that triggered this deployment
required: true
endpoint:
description:
- Endpoint for deploy marker (optional)
required: false
validate_certs:
description:
- If C(no), SSL certificates will not be validated. This should only be used
on personally controlled sites using self-signed certificates.
required: false
default: 'yes'
choices: ['yes', 'no']
version_added: 1.5.1
# informational: requirements for nodes
requirements: [ urllib, urllib2 ]
'''
EXAMPLES = '''
- appsignal_deployment: api_key=AAAAAA
name=myapp
environment=staging
user='Robert'
revision=1.0
'''
# ===========================================
# Module execution.
#
def main():
module = AnsibleModule(
argument_spec=dict(
api_key=dict(required=True),
name=dict(required=True),
environment=dict(required=True),
revision=dict(required=True),
user=dict(required=True),
endpoint=dict(required=False, default='https://push.appsignal.com/1/markers'),
validate_certs = dict(default='yes', type='bool'),
),
supports_check_mode=True
)
# build list of params
params = {}
for item in [ "revision", "user" ]:
if module.params[item]:
params[item] = module.params[item]
# If we're in check mode, just exit pretending like we succeeded
if module.check_mode:
module.exit_json(changed=True)
# Send the data to AppSignal
url = "%s?api_key=%s&name=%s&environment=%s" % (module.params['endpoint'], module.params['api_key'], module.params['name'], module.params['environment'])
data = json.dumps(params)
response, info = fetch_url(module, url, data=data)
if info['status'] in (200, 201):
module.exit_json(changed=True)
else:
module.fail_json(msg="unable to update AppSignal: %s" % info['msg'])
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment