Matteo Scandolo | 35113f7 | 2017-08-08 13:05:25 -0700 | [diff] [blame^] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Srikanth Vavilapalli | 974c9ce | 2017-01-25 01:50:27 +0000 | [diff] [blame] | 17 | --- |
| 18 | - hosts: {{ instance_name }} |
| 19 | gather_facts: False |
| 20 | connection: ssh |
| 21 | user: ubuntu |
| 22 | vars: |
| 23 | keystone_tenant_id: {{ keystone_tenant_id }} |
| 24 | keystone_user_id: {{ keystone_user_id }} |
| 25 | target_uri: {{ target_uri }} |
| 26 | |
| 27 | tasks: |
| 28 | - name: Verify if monitoring_agent ([] is to avoid capturing the shell process) cron job is already running |
| 29 | shell: pgrep -f [m]onitoring_agent | wc -l |
| 30 | register: cron_job_pids_count |
| 31 | |
| 32 | - name: DEBUG |
| 33 | debug: var=cron_job_pids_count.stdout |
| 34 | |
| 35 | - name: make sure /usr/local/share/monitoring_agent exists |
| 36 | file: path=/usr/local/share/monitoring_agent state=directory owner=root group=root |
| 37 | become: yes |
| 38 | when: cron_job_pids_count.stdout == "0" |
| 39 | |
| 40 | - name: Copy cron job to destination |
| 41 | copy: src=/opt/xos/synchronizers/exampleservice/monitoring_agent/ |
| 42 | dest=/usr/local/share/monitoring_agent/ |
| 43 | become: yes |
| 44 | when: cron_job_pids_count.stdout == "0" |
| 45 | |
| 46 | - name: Installing python-pip |
| 47 | apt: name=python-pip state=present update_cache=yes |
| 48 | become: yes |
| 49 | when: cron_job_pids_count.stdout == "0" |
| 50 | |
| 51 | - name: Installing Flask |
| 52 | pip: name=Flask |
| 53 | become: yes |
| 54 | when: cron_job_pids_count.stdout == "0" |
| 55 | |
| 56 | - name: install python-kombu |
| 57 | apt: name=python-kombu state=present |
| 58 | become: yes |
| 59 | when: cron_job_pids_count.stdout == "0" |
| 60 | |
| 61 | - name: Initiate monitoring agent cron job |
| 62 | command: python monitoring_agent.py & |
| 63 | async: 9999999999999999 |
| 64 | poll: 0 |
| 65 | become: yes |
| 66 | when: cron_job_pids_count.stdout == "0" |
| 67 | args: |
| 68 | chdir: /usr/local/share/monitoring_agent/ |
| 69 | |
| 70 | - name : starting monitoring agent |
| 71 | uri: |
| 72 | url: http://localhost:5004/monitoring/agent/exampleservice/start |
| 73 | method: POST |
| 74 | body: '{ "target":"{{target_uri}}", "keystone_user_id": "{{keystone_user_id}}", "keystone_tenant_id": "{{keystone_tenant_id}}" }' |
| 75 | force_basic_auth: yes |
| 76 | status_code: 200 |
| 77 | body_format: json |