Skip to content

Commit

Permalink
Merge pull request ansible#41 from inventure/check_servers_state_1364…
Browse files Browse the repository at this point in the history
…61073

Add ansible playbook for checking servers status
  • Loading branch information
liyocee authored Jan 8, 2017
2 parents b89ff3d + 5293d68 commit a415a28
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 1 deletion.
11 changes: 10 additions & 1 deletion SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ To set up a specific application, please run the deploy scripts for local enviro
- http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
- http://docs.aws.amazon.com/cli/latest/userguide/installing.html
- To setup monitoring on a single instance you will need to filter it by its private ip using below command
- ` play -i hosts aws-monitor.yml -l {{ country_code }}-devops --vault-password ~/.vault -e "private_ip={{ PRIVATE_IP_GOES_HERE" `
- ` play -i hosts aws-monitor.yml -l {{ country_code }}-devops --vault-password ~/.vault -e "private_ip={{ PRIVATE_IP_GOES_HERE" `
- To setup monitoring on all the instances in a region use `*` as the private ip using below command:
- `play -i hosts aws-monitor.yml -l {{ country_code }}-devops --vault-password ~/.vault -e "private_ip=*"`

Expand All @@ -153,4 +153,13 @@ To set up a specific application, please run the deploy scripts for local enviro
#run the server setup role with only specific tags; upgrade, env-setup,utils-setup,python-setup,ssh-setup
ansible-playbook -i provisioning/hosts provisioning/servers-basic-setup.yml --vault-password-file=vault

# USING THE check-servers-state playbook
- Run the ansible playbook command as shown below:
- `ansible-playbook -i hosts check-servers-state.yml -l {host} --extra-vars "env={ env } country_code={ country code }"`

**NOTE**:
- env : can be 'prod', 'staging', 'dev', 'demo', 'prod', 'qa', 'qa2', 'staging'
- country code: this can be 'ke', 'tz', or 'ph'
- host - the host you want to run the playbook from

Happy Coding!
7 changes: 7 additions & 0 deletions provisioning/check-servers-state.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- hosts: all
become: yes
become_user: root
remote_user: vagrant
roles:
- { role: check-servers-state}
8 changes: 8 additions & 0 deletions provisioning/group_vars/ke/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ s3_payments_logs_bucket: "payments-logs-backup"
country_code: ke
aws_region: us-west-2
payment_logs_dir: "/var/log/applications/payments/"

# Server API urls
dev_server_api_base_url: "devserverapi.inventureaccess.com"
demo_server_api_base_url: "demo-serverapi.inventureaccess.com"
prod_server_api_base_url: "api.inventureaccess.com"
qa_server_api_base_url: "qaserverapi.inventureaccess.com"
qa2_server_api_base_url: "qa2-serverapi.inventureaccess.com"
staging_server_api_base_url: "staging-serverapi.inventureaccess.com"
8 changes: 8 additions & 0 deletions provisioning/group_vars/ph/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ s3_payments_logs_bucket: "payments-logs-backup"
country_code: ph
aws_region: ap-southeast-1
payment_logs_dir: "/var/log/applications/payments/"

# Server API urls
dev_server_api_base_url: "ph-devserverapi.inventureaccess.com"
demo_server_api_base_url: "ph-demoserverapi.inventureaccess.com"
prod_server_api_base_url: "ph-api.inventureaccess.com"
qa_server_api_base_url: "ph-qaserverapi.inventureaccess.com"
qa2_server_api_base_url: "ph-qa2serverapi.inventureaccess.com"
staging_server_api_base_url: "ph-stagingserverapi.inventureaccess.com"
8 changes: 8 additions & 0 deletions provisioning/group_vars/tz/vars.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
---
country_code: tz

# Server API urls
dev_server_api_base_url: "tz-devserverapi.inventureaccess.com"
demo_server_api_base_url: "tz-demoserverapi.inventureaccess.com"
prod_server_api_base_url: "tz-api.inventureaccess.com"
qa_server_api_base_url: "tz-qaserverapi.inventureaccess.com"
qa2_server_api_base_url: "tz-qa2serverapi.inventureaccess.com"
staging_server_api_base_url: "tz-stagingserverapi.inventureaccess.com"
27 changes: 27 additions & 0 deletions provisioning/roles/check-servers-state/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
# Role to ping servers to check their state

- name: Set server api base url
include: set-server-api-baseurl.yml
tags:
- check-servers-state

- name: Check servers state
uri:
url: "{{ server_api_base_url }}/admin/serverstatus/check"
return_content: yes
status_code: 200
register: servers_state
tags:
- check-servers-state

- name: Fail when one of the servers is down
fail:
msg: >
"Server Name: {{ item.key }}"
"Status Code: {{ item.value.status }}"
"Error Details: {{ item.value.statusDetails }}"
failed_when: item.value.status != 200
with_dict: "{{ servers_state.content|from_json }}"
tags:
- check-servers-state
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
# Set server_api_base_url based on the environment

- include_vars: group_vars/{{ country_code }}/vars.yml

- name: Set server api base url - local
set_fact: server_api_base_url="http://serverapi.lh"
tags:
- check-servers-state

- name: Set server api base url - dev
set_fact: server_api_base_url="http://{{ dev_server_api_base_url }}"
when: env == "dev"
tags:
- check-servers-state

- name: Set server api base url - demo
set_fact: server_api_base_url="http://{{ demo_server_api_base_url }}"
when: env == "demo"
tags:
- check-servers-state

- name: Set server api base url - prod
set_fact: server_api_base_url="http://{{ prod_server_api_base_url }}"
when: env == "prod"
tags:
- check-servers-state

- name: Set server api base url - qa
set_fact: server_api_base_url="http://{{ qa_server_api_base_url }}"
when: env == "qa"
tags:
- check-servers-state

- name: Set server api base url - qa2
set_fact: server_api_base_url="http://{{ qa2_server_api_base_url }}"
when: env == "qa2"
tags:
- check-servers-state

- name: Set server api base url - staging
set_fact: server_api_base_url="http://{{ staging_server_api_base_url }}"
when: env == "staging"
tags:
- check-servers-state

0 comments on commit a415a28

Please sign in to comment.