This repository has been archived by the owner on Apr 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
main.yml
92 lines (77 loc) · 3.06 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
# Copyright 2014, Rackspace US, Inc.
#
# 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.
- name: Clone plugins repo
git:
repo: "{{ git_repo }}"
dest: /usr/lib/rackspace-monitoring-agent/plugins/
version: "{{ git_install_branch }}"
- name: Chmod plugins
file: path={{ item }} mode=0755
with_fileglob:
- /usr/lib/rackspace-monitoring-agent/plugins/*.py
- name: Create openrc file
template: >
src=openrc
dest=/root/openrc-maas
owner=root
group=root
mode=0600
- name: Install python dependencies
pip:
requirements: "{{ pip_requirements_file }}"
- name: Entity {{ entity_name }} count
shell: "raxmon-entities-list | grep ' label={{ entity_name }} provider=Rackspace Monitoring ...>$' | wc -l"
register: entity_count
- name: At most one {{ entity_name }} entity exists
fail:
msg: "Entity count of {{ entity_count.stdout }} != 1 for entity with the label {{ entity_name }}"
when: entity_count.stdout|int != 1
- name: Get entity {{ entity_name }}
shell: "raxmon-entities-list | grep ' label={{ entity_name }} provider=Rackspace Monitoring ...>$' | awk '{print $2}' | cut -d= -f2"
register: entity
- name: Assign agent ID to entity
shell: "raxmon-entities-update --id {{ entity.stdout }} --agent-id {{ entity_name }}"
- name: Agent token {{ entity_name }} count
shell: "raxmon-agent-tokens-list | grep ' label={{ entity_name }}, ' | wc -l"
register: agent_token_count
when: maas_agent_token is not defined
- name: At most one {{ entity_name }} agent token should exist
fail:
msg: "Agent token count of {{ agent_token_count.stdout }} > 1 for entity with the label {{ entity_name }}"
when: maas_agent_token is not defined and agent_token_count.stdout|int > 1
- name: Create agent token
shell: "raxmon-agent-tokens-create --label={{ entity_name }}"
register: agent_token
when: maas_agent_token is not defined and agent_token_count.stdout|int == 0
- name: Get agent token
shell: "raxmon-agent-tokens-list | grep '<AgentToken: id=.* label={{ entity_name }}, .*>' | awk '{print $2}' | sed -e 's/id=\\(.*\\),/\\1/g'"
register: maas_agent_token_id
when: maas_agent_token is not defined
- name: Set agent token fact
set_fact: maas_agent_token={{ maas_agent_token_id.stdout }}
when: maas_agent_token is not defined
- name: Generate raxmon agent config
template:
src: rackspace-monitoring-agent.cfg
dest: /etc/rackspace-monitoring-agent.cfg
mode: 0600
owner: root
group: root
notify: Restart raxmon agent
- name: Start raxmon agent
service:
name: rackspace-monitoring-agent
state: started
enabled: yes