From 92438185fc8beb5701e8ba07db70fd8b7f10f954 Mon Sep 17 00:00:00 2001 From: Greg Szabo Date: Sat, 3 Jun 2017 01:10:44 -0400 Subject: [PATCH] Clarified Ansible installation instructions and added slacknotification.py script. --- ansible/README.md | 42 +++++++++++++++++++++++++++++++++++-- devops/README.md | 16 ++++++++++++++ devops/slacknotification.py | 41 ++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 devops/README.md create mode 100644 devops/slacknotification.py diff --git a/ansible/README.md b/ansible/README.md index 53bc15e11..1dee149e5 100644 --- a/ansible/README.md +++ b/ansible/README.md @@ -34,12 +34,25 @@ The cloud inventory scripts come from the ansible team at their [GitHub](https:/ Ansible requires a "command machine" or "local machine" or "orchestrator machine" to run on. This can be your laptop or any machine that runs linux. (It does not have to be part of the cloud network that hosts your servers.) -Note: All the below commands use the Ubuntu/Debian `apt-get` command. To make it compatible with RedHat/CentOS, replace it with `yum`. +Use the official [Ansible installation guide](http://docs.ansible.com/ansible/intro_installation.html) to install Ansible. Here are a few examples on basic installation commands: +Ubuntu/Debian: ``` sudo apt-get install ansible ``` +CentOS/RedHat: +``` +sudo yum install epel-release +sudo yum install ansible +``` + +Mac OSX: +``` +sudo easy_install pip +sudo pip install ansible +``` + To make life easier, you can start an SSH Agent and load your SSH key(s). This way ansible will have an uninterrupted way of connecting to your servers. ``` @@ -55,17 +68,42 @@ Subsequently, as long as the agent is running, you can use `source ~/.ssh/ssh.en If you are using a cloud provider to host your servers, you need the below dependencies installed on your local machine. -DigitalOcean inventory dependencies: +#### DigitalOcean inventory dependencies: + +Ubuntu/Debian: ``` sudo apt-get install python-pip sudo pip install dopy ``` +CentOS/RedHat: +``` +sudo yum install python-pip +sudo pip install dopy +``` + +Mac OSX: +``` +sudo pip install dopy +``` + Amazon AWS inventory dependencies: + +Ubuntu/Debian: ``` sudo apt-get install python-boto ``` +CentOS/RedHat: +``` +sudo yum install python-boto +``` + +Mac OSX: +``` +sudo pip install boto +``` + ## Refreshing the DigitalOcean inventory If you just finished creating droplets, the local DigitalOcean inventory cache is not up-to-date. To refresh it, run: diff --git a/devops/README.md b/devops/README.md new file mode 100644 index 000000000..675271ae8 --- /dev/null +++ b/devops/README.md @@ -0,0 +1,16 @@ +# DevOps tools + +This folder contains tools that are used for automated testnet deployments. + +## slacknotification.py + +A small script that can send Slack messages. + +Requirements: slackclient python library + +Install slackclient by running as root: +``` +pip install slackclient +``` + + diff --git a/devops/slacknotification.py b/devops/slacknotification.py new file mode 100644 index 000000000..ee5987e23 --- /dev/null +++ b/devops/slacknotification.py @@ -0,0 +1,41 @@ +import os +from slackclient import SlackClient +import argparse + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description="Slack notification script") + parser.add_argument('--channel','-c', required=True, help="Slack channel.") + parser.add_argument('--message','-m', required=True, help="The message to send.") + parser.add_argument('--username', required=False, help="Username used on Slack") + parser.add_argument('--api_token', required=False, help="Slack API token. Can be set in SLACK_API_TOKEN environment variable too.") + parser.add_argument('--icon_emoji','-i', required=False, help="Icon for the message.") + args = parser.parse_args() + + username = args.username + api_token=args.api_token + if api_token is None: + api_token=os.getenv("SLACK_API_TOKEN") + message = args.message + channel = args.channel + icon_emoji = args.icon_emoji + + slack_client = SlackClient(api_token) + apitest = slack_client.api_call("api.test") + if not apitest['ok']: + raise ValueError("api.test error: {0}".format(apitest['error'])) + + authtest = slack_client.api_call("auth.test") + if not authtest['ok']: + raise ValueError("auth.test error: {0}".format(authtest['error'])) + + if username is None: + username = authtest['user'] + + if icon_emoji is None: + result = slack_client.api_call("chat.postMessage", channel=channel, text=message, username=username, icon_emoji=icon_emoji) + else: + result = slack_client.api_call("chat.postMessage", channel=channel, text=message, username=username) + + if not result['ok']: + raise ValueError("Message error: {0}".format(result['error'])) +