| |
| # Copyright 2017-present Open Networking Foundation |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| |
| --- |
| - hosts: {{ instance_name }} |
| gather_facts: False |
| connection: ssh |
| user: ubuntu |
| vars: |
| keystone_tenant_id: {{ keystone_tenant_id }} |
| keystone_user_id: {{ keystone_user_id }} |
| target_uri: {{ target_uri }} |
| |
| tasks: |
| - name: Verify if monitoring_agent ([] is to avoid capturing the shell process) cron job is already running |
| shell: pgrep -f [m]onitoring_agent | wc -l |
| register: cron_job_pids_count |
| |
| - name: DEBUG |
| debug: var=cron_job_pids_count.stdout |
| |
| - name: make sure /usr/local/share/monitoring_agent exists |
| file: path=/usr/local/share/monitoring_agent state=directory owner=root group=root |
| become: yes |
| when: cron_job_pids_count.stdout == "0" |
| |
| - name: Copy cron job to destination |
| copy: src=/opt/xos/synchronizers/exampleservice/monitoring_agent/ |
| dest=/usr/local/share/monitoring_agent/ |
| become: yes |
| when: cron_job_pids_count.stdout == "0" |
| |
| - name: Installing python-pip |
| apt: name=python-pip state=present update_cache=yes |
| become: yes |
| when: cron_job_pids_count.stdout == "0" |
| |
| - name: Installing Flask |
| pip: name=Flask |
| become: yes |
| when: cron_job_pids_count.stdout == "0" |
| |
| - name: install python-kombu |
| apt: name=python-kombu state=present |
| become: yes |
| when: cron_job_pids_count.stdout == "0" |
| |
| - name: Initiate monitoring agent cron job |
| command: python monitoring_agent.py & |
| async: 9999999999999999 |
| poll: 0 |
| become: yes |
| when: cron_job_pids_count.stdout == "0" |
| args: |
| chdir: /usr/local/share/monitoring_agent/ |
| |
| - name : starting monitoring agent |
| uri: |
| url: http://localhost:5004/monitoring/agent/exampleservice/start |
| method: POST |
| body: '{ "target":"{{target_uri}}", "keystone_user_id": "{{keystone_user_id}}", "keystone_tenant_id": "{{keystone_tenant_id}}" }' |
| force_basic_auth: yes |
| status_code: 200 |
| body_format: json |